Skip to content

Commit 438390a

Browse files
committed
Remove STAT_SEQ_STAT from if branches with only a single statement
1 parent e54b6fa commit 438390a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CompilerForCAP/examples/LinearAlgebraForCAP.g

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#! @Section Examples
44

5+
LoadPackage( "LinearAlgebra" );
6+
57
#! @Example
68

79
Q := HomalgFieldOfRationals();;
@@ -22,7 +24,7 @@ tree1 := SYNTAX_TREE(
2224
vec!.compiled_functions.MorphismBetweenDirectSums[3]
2325
);;
2426
# fixup nams
25-
tree1.stats.statements[1].branches[2].body.statements[1].
27+
tree1.stats.statements[1].branches[2].body.
2628
obj.args[12].args[1].args[2].nams := [ "row" ];;
2729
Display( SYNTAX_TREE_CODE( tree1 ) );
2830
#! function ( cat, S, morphism_matrix, T )
@@ -47,7 +49,7 @@ tree2 := SYNTAX_TREE( CapJitCompiledFunction(
4749
[ vec, W, morphism_matrix, W ]
4850
) );;
4951
# fixup nams
50-
tree2.stats.statements[1].branches[2].body.statements[1].
52+
tree2.stats.statements[1].branches[2].body.
5153
obj.args[12].args[1].args[2].nams := [ "row" ];;
5254
Display( SYNTAX_TREE_CODE( tree2 ) );
5355
#! function ( cat, S, morphism_matrix, T )

CompilerForCAP/gap/EnhancedSyntaxTree.gi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ InstallGlobalFunction( ENHANCED_SYNTAX_TREE_CODE, function ( tree )
488488

489489
fi;
490490

491+
# remove STAT_SEQ_STAT from if branches with only a single statement
492+
if tree.type = "BRANCH_IF" and tree.body.type = "STAT_SEQ_STAT" and Length( tree.body.statements ) = 1 then
493+
494+
tree.body := tree.body.statements[1];
495+
496+
fi;
497+
491498
# convert EXPR_CONDITIONAL back into if/else
492499

493500
# EXPR_CONDITIONAL as obj of STAT_RETURN_OBJ

0 commit comments

Comments
 (0)