Commit f701bbe3 authored by John van Groningen's avatar John van Groningen
Browse files

add integers and rationals

parent 856490d6
......@@ -27,6 +27,7 @@ void PushBasicOnB (ObjectKind state, int offset);
void UpdateBasic (int size, int srcoffset, int dstoffset);
void CallFunction (Label label, SymbDef def, Bool isjsr, Node root);
void CallFunction1 (Label label, SymbDef def, StateS root_state, Args fun_args, int arity);
void CallArrayFunction (SymbDef def,Bool isjsr,StateP node_state_p);
......@@ -66,6 +67,9 @@ void GenBuildU (Label symblab,int a_size,int b_size,Label contlab);
void GenBuildArray (int argoffset);
void GenBuildString (SymbValue val);
void GenPushZ (SymbValue val);
void GenPushZR (SymbValue val);
void GenBuildFieldSelector (Label symblab,Label contlab,char *record_name,int arity);
void GenFillFieldSelector (Label symblab,Label contlab,char *record_name,int arity,int offset,FillKind fkind);
......@@ -91,6 +95,7 @@ void GenJsrAp (int n_args);
void GenJmpEval (void);
void GenJmpAp (int n_args);
void GenJmpApUpd (int n_args);
void GenJmpNotEqZ (SymbValue val,Label tolab);
void GenJmpUpd (Label tolab);
void GenPopA (int nr);
void GenPopB (int nr);
......@@ -168,6 +173,7 @@ void GenApplyEntryDirective (int arity,Label label);
void GenLazyRecordNodeEntryDirective (int arity,Label label,Label label2);
void GenFieldNodeEntryDirective (int arity, Label label, Label label2,char *record_name);
void GenConstructorDescriptorAndExport (SymbDef sdef);
void GenConstructor0DescriptorAndExport (SymbDef sdef,int constructor_n);
void GenFunctionDescriptorAndExportNodeAndDescriptor (SymbDef sdef);
void GenConstructorFunctionDescriptorAndExportNodeAndDescriptor (SymbDef sdef);
#if OPTIMIZE_LAZY_TUPLE_RECURSION
......
......@@ -497,9 +497,9 @@ static Node copy_root_node (Node old)
case_node_arg_p=case_node_p->node_arguments;
new_case_node_p->node_su.su_u.u_case=CompAllocType (CaseNodeContentsS);
if (case_node_p->node_kind==CaseNode){
new_case_node_p->node_su.su_u.u_case=CompAllocType (CaseNodeContentsS);
new_case_node_p->node_node_defs = copy_rhs_node_ids_of_node_defs (case_node_p->node_node_defs,NULL);
if (case_node_arg_p->arg_node->node_kind==PushNode){
......@@ -570,9 +570,49 @@ static Node copy_root_node (Node old)
new_case_node_arg_p->arg_node = copy_root_node (case_node_arg_p->arg_node);
}
} else if (case_node_p->node_kind==DefaultNode){
new_case_node_p->node_su.su_u.u_case=CompAllocType (CaseNodeContentsS);
new_case_node_p->node_node_defs = copy_rhs_node_ids_of_node_defs (case_node_p->node_node_defs,NULL);
copy_nodes_of_node_defs (new_case_node_p->node_node_defs,False);
new_case_node_arg_p->arg_node = copy_root_node (case_node_arg_p->arg_node);
} else if (case_node_p->node_kind==OverloadedCaseNode){
NodeP new_overloaded_case_node_p;
ArgP new_overloaded_case_node_arg2_p;
new_overloaded_case_node_arg2_p=CompAllocType (ArgS);
new_overloaded_case_node_arg2_p->arg_state=LazyState;
new_overloaded_case_node_arg2_p->arg_next=NULL;
new_case_node_arg_p->arg_next=new_overloaded_case_node_arg2_p;
new_case_node_arg_p->arg_node=copy_node (case_node_arg_p->arg_node,False);
new_overloaded_case_node_arg2_p->arg_node=copy_node (case_node_arg_p->arg_next->arg_node,False);
case_node_p=case_node_p->node_node;
new_overloaded_case_node_p=new_case_node_p;
new_case_node_p = CompAllocType (NodeS);
*new_case_node_p = *case_node_p;
new_overloaded_case_node_p->node_node = new_case_node_p;
new_case_node_arg_p=CompAllocType (ArgS);
new_case_node_arg_p->arg_state=LazyState;
new_case_node_p->node_arguments=new_case_node_arg_p;
new_case_node_arg_p->arg_next=NULL;
case_node_arg_p=case_node_p->node_arguments;
new_case_node_p->node_su.su_u.u_case=CompAllocType (CaseNodeContentsS);
new_case_node_p->node_node_defs = copy_rhs_node_ids_of_node_defs (case_node_p->node_node_defs,NULL);
copy_nodes_of_node_defs (new_case_node_p->node_node_defs,False);
new_case_node_arg_p->arg_node = copy_root_node (case_node_arg_p->arg_node);
} else
error_in_function ("copy_root_node");
......@@ -3086,6 +3126,23 @@ static void optimise_root_node (NodeP node,NodeDefP node_defs,FreeUniqueNodeIdsP
optimise_root_node (case_alt_node_p,case_node->node_node_defs,case_f_node_ids);
set_global_reference_counts (case_node);
} else if (case_node->node_kind==OverloadedCaseNode){
NodeP case_alt_node_p;
FreeUniqueNodeIdsP case_f_node_ids;
case_node=case_node->node_node;
case_f_node_ids=f_node_ids;
case_alt_node_p=case_node->node_arguments->arg_node;
set_local_reference_counts (case_node);
optimise_root_node (case_alt_node_p,case_node->node_node_defs,case_f_node_ids);
set_global_reference_counts (case_node);
} else
error_in_function ("optimise_root_node");
}
......@@ -3609,10 +3666,21 @@ static void ReorderNodeDefinitionsAndDetermineUsedEntries (NodeDefs *def_p,Node
error_in_function ("ReorderNodeDefinitionsAndDetermineUsedEntries");
for_l (arg,root->node_arguments,arg_next){
if (arg->arg_node->node_kind!=CaseNode && arg->arg_node->node_kind!=DefaultNode)
error_in_function ("ReorderNodeDefinitionsAndDetermineUsedEntries");
if (arg->arg_node->node_kind==OverloadedCaseNode){
NodeP overloaded_case_node_p,case_node_p;
overloaded_case_node_p=arg->arg_node;
MarkDependentNodeDefs (overloaded_case_node_p->node_arguments->arg_node);
MarkDependentNodeDefs (overloaded_case_node_p->node_arguments->arg_next->arg_node);
case_node_p=overloaded_case_node_p->node_node;
ReorderNodeDefinitionsAndDetermineUsedEntries (&case_node_p->node_node_defs,case_node_p->node_arguments->arg_node);
} else {
if (arg->arg_node->node_kind!=CaseNode && arg->arg_node->node_kind!=DefaultNode && arg->arg_node->node_kind!=OverloadedCaseNode)
error_in_function ("ReorderNodeDefinitionsAndDetermineUsedEntries");
ReorderNodeDefinitionsAndDetermineUsedEntries (&arg->arg_node->node_node_defs,arg->arg_node->node_arguments->arg_node);
ReorderNodeDefinitionsAndDetermineUsedEntries (&arg->arg_node->node_node_defs,arg->arg_node->node_arguments->arg_node);
}
}
return;
......@@ -3621,7 +3689,7 @@ static void ReorderNodeDefinitionsAndDetermineUsedEntries (NodeDefs *def_p,Node
ReorderNodeDefinitionsAndDetermineUsedEntries (&root->node_node_defs,root->node_arguments->arg_next->arg_node);
return;
}
reordered_defs_p=&reordered_defs;
MarkNodeDefsWithProperty (*def_p,&IsObservedDef);
......@@ -3847,6 +3915,18 @@ static void determine_then_else_ref_counts (NodeP node)
set_global_reference_counts (case_node);
--node->node_node_id->nid_refcount;
} else if (case_node->node_kind==OverloadedCaseNode){
case_node=case_node->node_node;
++node->node_node_id->nid_refcount;
set_local_reference_counts (case_node);
determine_then_else_ref_counts (case_node->node_arguments->arg_node);
set_global_reference_counts (case_node);
--node->node_node_id->nid_refcount;
} else
error_in_function ("determine_then_else_ref_counts");
}
......
......@@ -776,7 +776,7 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo
node_id_ref_count_list_sorted=0;
for (arg=node->node_arguments; arg!=NULL; arg=arg->arg_next)
if (arg->arg_node->node_kind!=CaseNode)
if (arg->arg_node->node_kind!=CaseNode && arg->arg_node->node_kind!=OverloadedCaseNode)
break;
default_may_fail=1;
......@@ -853,6 +853,9 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo
arg_node=arg->arg_node;
switch (arg_node->node_kind){
case OverloadedCaseNode:
arg_node = arg_node->node_node;
/* no break */
case CaseNode:
{
int case_may_fail;
......
......@@ -2136,6 +2136,11 @@ static void InitNode (Node node)
InitNode (case_alt_node_p);
InitNodeDefs (node_p->node_node_defs);
} else if (node_p->node_kind==OverloadedCaseNode){
node_p=node_p->node_node;
InitNode (node_p->node_arguments->arg_node);
InitNodeDefs (node_p->node_node_defs);
} else if (node_p->node_kind==DefaultNode){
InitNode (node_p->node_arguments->arg_node);
InitNodeDefs (node_p->node_node_defs);
......@@ -2683,7 +2688,12 @@ static void convert_switch_node (NodeP switch_node_p,Alts fun_alt_p)
}
} else if (node_p->node_kind==DefaultNode){
case_alt_node_p=node_p->node_arguments->arg_node;
case_alt_p->fun_lhs=NULL;
case_alt_p->fun_lhs=NULL;
} else if (node_p->node_kind==OverloadedCaseNode){
node_p=node_p->node_node;
case_alt_node_p=node_p->node_arguments->arg_node;
case_alt_p->fun_lhs=⊤
} else
error_in_function ("convert_switch_node");
......
......@@ -31,64 +31,69 @@ static void set_node_id_scope_numbers (NodeDefP node_defs,int local_scope)
static void set_root_scope_numbers (NodeP node_p,int local_scope)
{
/* RWS added switch nodes */
switch (node_p->node_kind)
{
switch (node_p->node_kind){
case IfNode:
{
int new_local_scope;
ArgP arg_p;
node_p->node_if_scope=scope;
{
int new_local_scope;
ArgP arg_p;
node_p->node_if_scope=scope;
new_local_scope=scope+2;
scope+=3;
arg_p=node_p->node_arguments;
set_root_scope_numbers (arg_p->arg_node,local_scope);
++scope;
arg_p=arg_p->arg_next;
set_root_scope_numbers (arg_p->arg_node,new_local_scope);
set_node_id_scope_numbers (node_p->node_then_node_defs,new_local_scope);
++scope;
arg_p=arg_p->arg_next;
set_root_scope_numbers (arg_p->arg_node,new_local_scope);
set_node_id_scope_numbers (node_p->node_else_node_defs,new_local_scope);
new_local_scope=scope+2;
scope+=3;
arg_p=node_p->node_arguments;
set_root_scope_numbers (arg_p->arg_node,local_scope);
++scope;
arg_p=arg_p->arg_next;
set_root_scope_numbers (arg_p->arg_node,new_local_scope);
set_node_id_scope_numbers (node_p->node_then_node_defs,new_local_scope);
++scope;
arg_p=arg_p->arg_next;
set_root_scope_numbers (arg_p->arg_node,new_local_scope);
set_node_id_scope_numbers (node_p->node_else_node_defs,new_local_scope);
}
break;
}
case SwitchNode:
{
ArgP arg_p;
int old_scope;
old_scope=scope;
for_l (arg_p,node_p->node_arguments,arg_next){
NodeP node_p;
scope=old_scope;
node_p=arg_p->arg_node;
if (node_p->node_kind==CaseNode){
NodeP case_alt_node_p;
case_alt_node_p=node_p->node_arguments->arg_node;
/* Cedewarrior bug if (case_alt_node_p->node_kind==PushNode) */
if (node_p->node_arguments->arg_node->node_kind==PushNode)
set_root_scope_numbers (case_alt_node_p->node_arguments->arg_next->arg_node, local_scope);
else
set_root_scope_numbers (node_p->node_arguments->arg_node, local_scope);
} else if (node_p->node_kind==DefaultNode){
{
ArgP arg_p;
int old_scope;
old_scope=scope;
for_l (arg_p,node_p->node_arguments,arg_next){
NodeP node_p;
scope=old_scope;
node_p=arg_p->arg_node;
if (node_p->node_kind==CaseNode){
NodeP case_alt_node_p;
case_alt_node_p=node_p->node_arguments->arg_node;
/* Cedewarrior bug if (case_alt_node_p->node_kind==PushNode) */
if (node_p->node_arguments->arg_node->node_kind==PushNode)
set_root_scope_numbers (case_alt_node_p->node_arguments->arg_next->arg_node, local_scope);
else
set_root_scope_numbers (node_p->node_arguments->arg_node, local_scope);
} else
ErrorInCompiler ("set_scope_numbers.c", "set_root_scope_numbers", "");
} else if (node_p->node_kind==DefaultNode){
set_root_scope_numbers (node_p->node_arguments->arg_node, local_scope);
} else if (node_p->node_kind==OverloadedCaseNode){
node_p=node_p->node_node;
set_root_scope_numbers (node_p->node_arguments->arg_node, local_scope);
set_node_id_scope_numbers (node_p->node_node_defs,local_scope);
}
} else
ErrorInCompiler ("set_scope_numbers.c", "set_root_scope_numbers", "");
set_node_id_scope_numbers (node_p->node_node_defs,local_scope);
}
break;
}
case GuardNode:
{
int old_scope;
......
......@@ -420,7 +420,7 @@ static void GenResultStatesOfLazyFields (SymbDef sdef)
for (i=0, fields = rectype->type_fields; fields; i++, fields = fields->fl_next){
TypeNode field_type_node = fields->fl_type;
if (field_type_node->type_node_annotation!=StrictAnnot){
if (field_type_node->type_node_is_var || field_type_node->type_node_symbol->symb_kind==apply_symb)
SetUnaryState (&fields->fl_state, LazyRedirection, UnknownObj);
......@@ -570,6 +570,10 @@ static void ChangeElementStateForStrictAbsTypeFields (SymbDef icl_sdef,SymbDef d
}
}
#ifdef CLEAN2
SymbDefP special_types[2];
#endif
void GenerateStatesForRecords (Symbol symbols)
{
Symbol symb;
......@@ -609,6 +613,11 @@ void GenerateStatesForRecords (Symbol symbols)
}
}
}
#ifdef CLEAN2
if (special_types[0]!=NULL)
BasicSymbolStates[integer_denot] = special_types[0]->sdef_record_state;
#endif
}
/*
......@@ -2034,7 +2043,7 @@ static Bool NodeInAStrictContext (Node node,StateS demanded_state,int local_scop
}
definition_state_p = GetStateOfArguments (sdef,node->node_arity);
if (definition_state_p!=NULL){
#ifdef FASTER_STRICT_AND_OR
if (sdef->sdef_module==StdBoolId->ident_name && node->node_arity==2){
......@@ -2117,7 +2126,7 @@ static Bool NodeInAStrictContext (Node node,StateS demanded_state,int local_scop
}
default:
if (rootsymb->symb_kind < Nr_Of_Predef_Types){
node->node_state = BasicSymbolStates [rootsymb->symb_kind];
node->node_state = BasicSymbolStates [rootsymb->symb_kind];
node->node_state.state_kind = demanded_state.state_kind;
}
break;
......@@ -2385,6 +2394,15 @@ static void DetermineStatesSwitchRootNode (Node root_node, StateS demstate, int
DetermineStatesOfRootNodeAndDefs (node->node_arguments->arg_node,&node->node_node_defs,demstate,local_scope);
} else if (node->node_kind==DefaultNode){
DetermineStatesOfRootNodeAndDefs (node->node_arguments->arg_node,&node->node_node_defs,demstate,local_scope);
} else if (node->node_kind==OverloadedCaseNode){
NodeP case_node_p;
DetermineStrictArgContext (node->node_arguments,StrictState,local_scope);
if (ShouldDecrRefCount)
DecrRefCountCopiesOfArg (node->node_arguments->arg_next IF_OPTIMIZE_LAZY_TUPLE_RECURSION(local_scope));
case_node_p=node->node_node;
DetermineStatesOfRootNodeAndDefs (case_node_p->node_arguments->arg_node,&case_node_p->node_node_defs,demstate,local_scope);
} else
error_in_function ("DetermineStatesSwitchRootNode");
}
......@@ -2785,6 +2803,8 @@ static void DetermineStatesOfNodeAndDefs (Node root_node,NodeDefs node_defs,Stat
DetermineStatesOfNodeAndDefs (case_alt_node_p,arg_node_p->node_node_defs,demstate,local_scope);
} else if (arg_node_p->node_kind==DefaultNode){
DetermineStatesOfNodeAndDefs (arg_node_p->node_arguments->arg_node,arg_node_p->node_node_defs,demstate,local_scope);
} else if (arg_node_p->node_kind==OverloadedCaseNode){
DetermineStatesOfNodeAndDefs (arg_node_p->node_node->node_arguments->arg_node,arg_node_p->node_node->node_node_defs,demstate,local_scope);
} else
error_in_function ("DetermineStatesOfNodeAndDefs");
}
......@@ -3160,6 +3180,8 @@ static NodeP add_argument_to_switch_node (NodeP rhs_root_p,NodeIdP new_node_id_p
node_h=&(*node_h)->node_arguments->arg_next->arg_node;
} else if (node_p->node_kind==DefaultNode){
node_h=&node_p->node_arguments->arg_node;
} else if (node_p->node_kind==OverloadedCaseNode){
node_h=&node_p->node_node->node_arguments->arg_node;
} else
error_in_function ("add_argument_to_switch_node");
......@@ -3680,8 +3702,7 @@ static NodeDefs *CollectSharedNodeIdsInRootNode (Node* node_p,NodeId parent_node
root_node=*node_p;
switch (root_node->node_kind)
{
switch (root_node->node_kind){
case SwitchNode:
{
ArgP arg_p;
......@@ -3697,9 +3718,8 @@ static NodeDefs *CollectSharedNodeIdsInRootNode (Node* node_p,NodeId parent_node
case_alt_node_p=node->node_arguments->arg_node;
case_last=&node->node_node_defs;
/* Codewarrior bug if (case_alt_node_p->node_kind==PushNode){ */
if (node->node_arguments->arg_node->node_kind==PushNode){
if (node->node_arguments->arg_node->node_kind==PushNode)
case_last=CollectSharedNodeIdsInRootNode (&case_alt_node_p->node_arguments->arg_next->arg_node, parent_node_id, case_last);
}
else
case_last=CollectSharedNodeIdsInRootNode (&node->node_arguments->arg_node, parent_node_id, case_last);
*case_last=NULL;
......@@ -3709,6 +3729,22 @@ static NodeDefs *CollectSharedNodeIdsInRootNode (Node* node_p,NodeId parent_node
default_last=&node->node_node_defs;
default_last=CollectSharedNodeIdsInRootNode (&node->node_arguments->arg_node, parent_node_id, default_last);
*default_last=NULL;
} else if (node->node_kind==OverloadedCaseNode){
NodeP case_node_p;
NodeDefs *case_last;
ArgP arg;
arg=node->node_arguments;
arg->arg_state=LazyState;
last = CollectSharedNodeIdsInNode (&arg->arg_node,parent_node_id,last);
arg=arg->arg_next;
arg->arg_state=LazyState;
last = CollectSharedNodeIdsInNode (&arg->arg_node,parent_node_id,last);
case_node_p=node->node_node;
case_last=&case_node_p->node_node_defs;
case_last=CollectSharedNodeIdsInRootNode (&case_node_p->node_arguments->arg_node, parent_node_id, case_last);
*case_last=NULL;
} else
error_in_function ("CollectSharedNodeIdsInRootNode");
}
......@@ -3765,11 +3801,11 @@ static void CollectSharedAndAnnotatedNodesInRhs (NodeS **root_p,NodeDefS **defs_
if ((imp_rule_p->rule_mark & RULE_LAMBDA_FUNCTION_MASK) &&
root_node->node_symbol->symb_def->sdef_arity==root_node->node_arity &&
imp_rule_p->rule_alts->alt_next==NULL
# ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
# ifdef TRANSFORM_PATTERNS_BEFORE_STRICTNESS_ANALYSIS
&& ! (imp_rule_p->rule_alts->alt_rhs_root->node_kind==SwitchNode ||
imp_rule_p->rule_alts->alt_rhs_root->node_kind==GuardNode ||
imp_rule_p->rule_alts->alt_rhs_root->node_kind==IfNode)
# endif
# endif
)
{
ArgP call_arg_p,lhs_arg_p;
......@@ -3905,8 +3941,7 @@ static void AnnotateStrictNodeIds (Node node,StrictNodeIdP strict_node_ids,NodeD
node_id->nid_node->node_annotation=StrictAnnot;
}
switch (node->node_kind)
{
switch (node->node_kind){
case IfNode:
{
ArgS *arg;
......@@ -3938,6 +3973,11 @@ static void AnnotateStrictNodeIds (Node node,StrictNodeIdP strict_node_ids,NodeD
AnnotateStrictNodeIds (node->node_arguments->arg_node,node->node_strict_node_ids,&node->node_node_defs);
} else if (node->node_kind==DefaultNode){
AnnotateStrictNodeIds (node->node_arguments->arg_node,node->node_strict_node_ids,&node->node_node_defs);
} else if (node->node_kind==OverloadedCaseNode){
NodeP case_node_p;
case_node_p=node->node_node;
AnnotateStrictNodeIds (case_node_p->node_arguments->arg_node,case_node_p->node_strict_node_ids,&case_node_p->node_node_defs);
} else
error_in_function ("AnnotateStrictNodeIds");
}
......@@ -4091,6 +4131,16 @@ static void reset_states_and_ref_count_copies_of_root_node (NodeP node_p)
} else if (node_p->node_kind==DefaultNode){
reset_states_and_ref_count_copies_of_root_node (node_p->node_arguments->arg_node);
reset_states_and_ref_count_copies_of_node_defs (node_p->node_node_defs);
} else if (node_p->node_kind==OverloadedCaseNode){
NodeP case_node_p;
case_node_p=node_p->node_node;
reset_states_and_ref_count_copies_of_root_node (case_node_p->node_arguments->arg_node);
reset_states_and_ref_count_copies_of_node_defs (case_node_p->node_node_defs);
reset_states_and_ref_count_copies_of_node (node_p->node_arguments->arg_node);
reset_states_and_ref_count_copies_of_node (node_p->node_arguments->arg_next->arg_node);
} else
error_in_function ("reset_states_and_ref_count_copies_of_root_node");
}
......@@ -4200,5 +4250,6 @@ void InitStatesGen (void)
SetUnaryState (& BasicSymbolStates[tuple_type], StrictOnA, TupleObj);
#ifdef CLEAN2
SetUnaryState (& BasicSymbolStates[dynamic_type], StrictOnA, DynamicObj);
SetUnaryState (& BasicSymbolStates[rational_denot], StrictOnA, UnknownObj);
#endif
}
......@@ -32,3 +32,5 @@ extern void ConvertTypeToState (TypeNode type,States state,StateKind kind);
extern int optimise_strict_tuple_result_functions;
extern PolyList UserDefinedArrayFunctions;
extern SymbDefP special_types[];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment