Skip to content

Commit

Permalink
Added test function to compare syntax trees
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasguts committed May 4, 2019
1 parent e75ede8 commit 812dc61
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions tst/testinstall/syntaxtree.tst
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@ gap> SyntaxTree(x -> x);
<syntax tree>
gap> SyntaxTree(\+);
Error, SYNTAX_TREE: <func> must be a plain GAP function (not a function)
gap> test_tree := function( f )
> local curr_tree, new_func, new_tree;
> curr_tree := SYNTAX_TREE( f );
> new_func := SYNTAX_TREE_CODE( curr_tree );
> new_tree := SYNTAX_TREE( new_func );
> return new_tree = curr_tree;
> end;;

# Just try compiling all functions we can find in the workspace
# to see nothing crashes.
gap> for n in NamesGVars() do
> if IsBoundGlobal(n) and not IsAutoGlobal(n) then
> v := ValueGlobal(n);
> if IsFunction(v) and not IsKernelFunction(v) then
> SYNTAX_TREE(v);
> if not test_tree(v) then
> Print("failed round trip: ",n,"\n");
> fi;
> elif IsOperation(v) then
> for i in [1..6] do
> for x in METHODS_OPERATION(v, i) do
> if IsFunction(x) and not IsKernelFunction(v) then
> SYNTAX_TREE(x);
> if not test_tree(v) then
> Print("failed round trip: ",n,"\n");
> fi;
> fi;
> od;
> od;
Expand All @@ -37,8 +48,7 @@ gap> testit := function(f)
> local tree;
> tree := SYNTAX_TREE(f);
> Display(tree);
> # TODO: recode the tree, then decode again and compare
> return true;
> return test_tree( f );
> end;;

# T_PROCCALL_0ARGS
Expand Down Expand Up @@ -1616,6 +1626,9 @@ rec(
comobj := rec(
lvar := 1,
type := "T_REFLVAR" ),
rhs := rec(
type := "T_INTEXPR",
value := 1 ),
rnam := "abc",
type := "T_ASS_COMOBJ_NAME" ), rec(
type := "T_RETURN_VOID" ) ],
Expand Down Expand Up @@ -2687,6 +2700,23 @@ rec(
type := "T_FUNC_EXPR",
variadic := false )
true
gap> testit( x -> [, [] ] );
rec(
nams := [ "x" ],
narg := 1,
nloc := 0,
stats := rec(
statements := [ rec(
obj := rec(
list := [ , rec(
list := [ ],
type := "T_LIST_EXPR" ) ],
type := "T_LIST_EXPR" ),
type := "T_RETURN_OBJ" ) ],
type := "T_SEQ_STAT" ),
type := "T_FUNC_EXPR",
variadic := false )
true

# T_LIST_TILDE_EXPR
gap> testit(x -> [~]);
Expand Down

0 comments on commit 812dc61

Please sign in to comment.