aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backendC/CleanCompilerSources/codegen1.c25
-rw-r--r--backendC/CleanCompilerSources/codegen3.c26
-rw-r--r--backendC/CleanCompilerSources/pattern_match.c8
3 files changed, 57 insertions, 2 deletions
diff --git a/backendC/CleanCompilerSources/codegen1.c b/backendC/CleanCompilerSources/codegen1.c
index 869c679..6a60cfa 100644
--- a/backendC/CleanCompilerSources/codegen1.c
+++ b/backendC/CleanCompilerSources/codegen1.c
@@ -3668,6 +3668,25 @@ static int generate_code_for_push_node (NodeP node,int asp,int bsp,struct esc *e
#endif
}
+#ifdef CLEAN2
+int contains_fail (NodeP node_p)
+{
+ while (node_p->node_kind==IfNode){
+ NodeP else_node_p;
+
+ else_node_p=node_p->node_arguments->arg_next->arg_next->arg_node;
+ while (else_node_p->node_kind==IfNode)
+ else_node_p=else_node_p->node_arguments->arg_next->arg_next->arg_node;
+
+ if (else_node_p->node_kind==NormalNode && else_node_p->node_symbol->symb_kind==fail_symb)
+ return 1;
+
+ node_p=node_p->node_arguments->arg_next->arg_node;
+ }
+ return 0;
+}
+#endif
+
int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,NodeDefP defs,StateP result_state_p,
SavedNidStateS **save_states_p,AbNodeIdsP ab_node_ids_p)
{
@@ -3719,11 +3738,13 @@ int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,No
return generate_code_for_root_node (node,asp,bsp,esc_p,defs,result_state_p,save_states_p,ab_node_ids_p);
default:
{
+#ifndef CLEAN2
NodeP else_node;
else_node=node;
while (else_node->node_kind==IfNode)
else_node=else_node->node_arguments->arg_next->arg_next->arg_node;
+#endif
return CodeRhsNodeDefs (node,defs,asp,bsp,save_states_p,*result_state_p,esc_p,ab_node_ids_p->a_node_ids,
ab_node_ids_p->b_node_ids,
@@ -3732,7 +3753,11 @@ int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,No
#else
NULL,
#endif
+#ifdef CLEAN2
+ !contains_fail (node));
+#else
!(else_node->node_kind==NormalNode && else_node->node_symbol->symb_kind==fail_symb));
+#endif
}
}
}
diff --git a/backendC/CleanCompilerSources/codegen3.c b/backendC/CleanCompilerSources/codegen3.c
index b055dd7..d1682c6 100644
--- a/backendC/CleanCompilerSources/codegen3.c
+++ b/backendC/CleanCompilerSources/codegen3.c
@@ -1130,6 +1130,10 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
}
}
+#ifdef CLEAN2
+extern int contains_fail (NodeP node_p);
+#endif
+
static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP code_gen_node_ids_p,StateS resultstate,struct esc *esc_p)
{
switch (root->node_kind){
@@ -1166,11 +1170,20 @@ static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP
if (thenlab.lab_mod==NULL)
GenLabelDefinition (&thenlab);
-
+#ifdef CLEAN2
+ {
+ int needs_next_alt;
+
+ needs_next_alt=
+#endif
CodeRhsNodeDefsAndRestoreNodeIdStates (then_arg->arg_node,root->node_then_node_defs,asp,bsp,resultstate,esc_p,
code_gen_node_ids_p->a_node_ids,code_gen_node_ids_p->b_node_ids,
root->node_else_node_id_ref_counts,
+#ifdef CLEAN2
+ !contains_fail (then_arg->arg_node)
+#else
True
+#endif
/*
code_gen_node_ids_p->doesnt_fail
*/
@@ -1186,9 +1199,18 @@ static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP
return 1;
} else
- return CodeRhsNodeDefsAndRestoreNodeIdStates (else_node,root->node_else_node_defs,asp,bsp,resultstate,esc_p,
+#ifdef CLEAN2
+ needs_next_alt = needs_next_alt |
+#else
+ return
+#endif
+ CodeRhsNodeDefsAndRestoreNodeIdStates (else_node,root->node_else_node_defs,asp,bsp,resultstate,esc_p,
code_gen_node_ids_p->a_node_ids,code_gen_node_ids_p->b_node_ids,
NULL,code_gen_node_ids_p->doesnt_fail);
+#ifdef CLEAN2
+ return needs_next_alt;
+ }
+#endif
}
case NodeIdNode:
if (rootid==NULL){
diff --git a/backendC/CleanCompilerSources/pattern_match.c b/backendC/CleanCompilerSources/pattern_match.c
index 7952e37..ff2e15e 100644
--- a/backendC/CleanCompilerSources/pattern_match.c
+++ b/backendC/CleanCompilerSources/pattern_match.c
@@ -1719,6 +1719,10 @@ static NodeIdRefCountListP duplicate_node_id_ref_count_list (NodeIdRefCountListP
return new_node_id_ref_count_list;
}
+#ifdef CLEAN2
+extern int contains_fail (NodeP node_p);
+#endif
+
static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCountListP *node_id_ref_count_list_p)
{
switch (node->node_kind){
@@ -1864,6 +1868,9 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo
case GuardNode:
return determine_failing_cases_and_adjust_ref_counts (node->node_arguments->arg_next->arg_node,node_id_ref_count_list_p);
case IfNode:
+#ifdef CLEAN2
+ return contains_fail (node);
+#else
{
NodeP else_node;
@@ -1873,6 +1880,7 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo
return else_node->node_kind==NormalNode && else_node->node_symbol->symb_kind==fail_symb;
}
+#endif
default:
return False;
}