Skip to content

Commit f979641

Browse files
mohamed-barakatFabian Zickgraf
andcommitted
converted logic templates into logic functions
Co-authored-by: Fabian Zickgraf <fabian.zickgraf@uni-siegen.de>
1 parent c0b1e8d commit f979641

File tree

1 file changed

+66
-24
lines changed

1 file changed

+66
-24
lines changed

gap/CompilerLogic.gi

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,72 @@ CapJitAddLogicFunction( function ( tree )
8585

8686
end );
8787

88+
## list{[ ]} => [ ]
89+
CapJitAddLogicFunction( function ( tree )
90+
local pre_func;
91+
92+
Info( InfoCapJit, 1, "####" );
93+
Info( InfoCapJit, 1, "Apply logic for extracting the empty sublist of a given list" );
94+
95+
pre_func :=
96+
function ( tree, additional_arguments )
97+
local args, is_big_int, values;
98+
99+
if CapJitIsCallToGlobalFunction( tree, "{}" ) then
100+
101+
args := tree.args;
102+
103+
if args.2.type = "EXPR_LIST" and args.2.list.length = 0 and IsBound( args.1.data_type ) then
104+
105+
return rec( type := "EXPR_LIST", list := AsSyntaxTreeList( [ ] ), data_type := args.1.data_type );
106+
107+
fi;
108+
109+
fi;
110+
111+
return tree;
112+
113+
end;
114+
115+
return CapJitIterateOverTree( tree, pre_func, CapJitResultFuncCombineChildren, ReturnTrue, true );
116+
117+
end );
118+
119+
## Product( [ ] ) => BigInt( 1 ) and Product( [ ], func ) => BigInt( 1 )
120+
CapJitAddLogicFunction( function ( tree )
121+
local pre_func;
122+
123+
Info( InfoCapJit, 1, "####" );
124+
Info( InfoCapJit, 1, "Apply logic for computing the empty product of an empty list of integers" );
125+
126+
pre_func :=
127+
function ( tree, additional_arguments )
128+
local args, is_big_int, values;
129+
130+
if CapJitIsCallToGlobalFunction( tree, "Product" ) then
131+
132+
args := tree.args;
133+
134+
if args.1.type = "EXPR_LIST" and args.1.list.length = 0 and IsBound( args.1.data_type ) then
135+
136+
return rec( type := "EXPR_FUNCCALL",
137+
funcref := rec(
138+
gvar := "BigInt",
139+
type := "EXPR_REF_GVAR" ),
140+
args := rec( 1 := rec( type := "EXPR_INT", value := 1 ), length := 1, type := "SYNTAX_TREE_LIST" ) );
141+
142+
fi;
143+
144+
fi;
145+
146+
return tree;
147+
148+
end;
149+
150+
return CapJitIterateOverTree( tree, pre_func, CapJitResultFuncCombineChildren, ReturnTrue, true );
151+
152+
end );
153+
88154
## Teach CompilerForCAP about the input type of the function so it can correctly type the function,
89155
## that can be done with the following code (adapted from the existing List type signature):
90156
##
@@ -260,14 +326,6 @@ CapJitAddLogicTemplate(
260326
)
261327
);
262328

263-
CapJitAddLogicTemplate(
264-
rec(
265-
variable_names := [ "list" ],
266-
src_template := "list{[ ]}",
267-
dst_template := "[ ]",
268-
)
269-
);
270-
271329
CapJitAddLogicTemplate(
272330
rec(
273331
variable_names := [ "list" ],
@@ -284,22 +342,6 @@ CapJitAddLogicTemplate(
284342
)
285343
);
286344

287-
CapJitAddLogicTemplate(
288-
rec(
289-
variable_names := [ ],
290-
src_template := "Product( [ ] )",
291-
dst_template := "BigInt( 1 )",
292-
)
293-
);
294-
295-
CapJitAddLogicTemplate(
296-
rec(
297-
variable_names := [ "func" ],
298-
src_template := "Product( [ ], func )",
299-
dst_template := "BigInt( 1 )",
300-
)
301-
);
302-
303345
CapJitAddLogicTemplate(
304346
rec(
305347
variable_names := [ "entry" ],

0 commit comments

Comments
 (0)