2
2
3
3
# ! @Section Tests
4
4
5
+ # ! @Example
6
+
5
7
LoadPackage( " CompilerForCAP" );
8
+ # ! true
6
9
7
- # ! @Example
10
+ MY_ID_FUNC := x -> x;;
8
11
9
12
func1 := function ( x )
10
13
if x = 1 then return 1 ; else return 2 ; fi ; end ;;
11
14
12
15
tree1 := ENHANCED_SYNTAX_TREE( func1 );;
16
+ tree1 := CapJitDetectedTernaryConditionalExpressions( tree1 );;
13
17
tree1.stats.statements[ 1 ] .obj.type = " EXPR_CONDITIONAL" ;
14
18
# ! true
15
19
16
20
coded_func1 := ENHANCED_SYNTAX_TREE_CODE( tree1 );;
17
21
String( func1 ) = ReplacedString( String( coded_func1 ), " _1" , " " );
18
22
# ! true
19
23
20
- func2 := function ( x )
21
- local y; if x = 1 then y := 1 ; else y := 2 ; fi ; return y; end ;;
22
24
23
- tree2 := ENHANCED_SYNTAX_TREE( func2 );;
24
- tree2.stats.statements[ 1 ] .rhs.type = " EXPR_CONDITIONAL" ;
25
- # ! true
26
25
27
- coded_func2 := ENHANCED_SYNTAX_TREE_CODE( tree2 );;
28
- String( func2 ) = ReplacedString( String( coded_func2 ), " _1" , " " );
29
- # ! true
30
-
31
- tree3 := rec (
26
+ tree2 := rec (
32
27
type := " EXPR_FUNC" ,
33
28
id := 1 ,
34
29
nams := [ ] ,
@@ -44,7 +39,7 @@ tree3 := rec(
44
39
type := " EXPR_FUNCCALL" ,
45
40
funcref := rec (
46
41
type := " EXPR_REF_GVAR" ,
47
- gvar := " IdFunc " ,
42
+ gvar := " MY_ID_FUNC " ,
48
43
),
49
44
args := [
50
45
rec (
@@ -68,10 +63,10 @@ tree3 := rec(
68
63
),
69
64
);;
70
65
71
- coded_func3 := ENHANCED_SYNTAX_TREE_CODE( tree3 );;
72
- Display( coded_func3 );
66
+ coded_func2 := ENHANCED_SYNTAX_TREE_CODE( tree2 );;
67
+ Display( coded_func2 );
73
68
# ! function ( )
74
- # ! return IdFunc ( function ( )
69
+ # ! return MY_ID_FUNC ( function ( )
75
70
# ! if false then
76
71
# ! return 1;
77
72
# ! else
@@ -81,28 +76,48 @@ Display( coded_func3 );
81
76
# ! end( ) );
82
77
# ! end
83
78
84
- coded_func3 ();
79
+ coded_func2 ();
85
80
# ! 2
86
81
87
- func4 := function ( x )
88
- local y; if x then y := 1 ; else y := 2 ; fi ; return IdFunc( y ); end ;;
89
82
90
- compiled_func4 := CapJitCompiledFunction( func4, [ true ] );;
91
- Display( compiled_func4 );
83
+
84
+ # we have to work hard to not write semicolons so AutoDoc
85
+ # does not begin a new statement
86
+ func3 := EvalString( ReplacedString( " " " function( x )
87
+ local inner_func@
88
+
89
+ inner_func := function( )
90
+ local y@
91
+ if x then
92
+ return 1@
93
+ else
94
+ y := 2@
95
+ return y@
96
+ fi@
97
+ end@
98
+
99
+ return MY_ID_FUNC( inner_func( ) )@
100
+
101
+ end" " " , " @" , " ;" ) );;
102
+
103
+ compiled_func3 := CapJitCompiledFunction( func3, [ true ] );;
104
+ Display( compiled_func3 );
92
105
# ! function ( x_1 )
93
106
# ! if x_1 then
94
- # ! return ID_FUNC ( 1 );
107
+ # ! return MY_ID_FUNC ( 1 );
95
108
# ! else
96
- # ! return ID_FUNC ( 2 );
109
+ # ! return MY_ID_FUNC ( 2 );
97
110
# ! fi;
98
111
# ! return;
99
112
# ! end
100
113
101
- func5 := function ( x )
114
+
115
+
116
+ func4 := function ( x )
102
117
local y; if x then return 1 ; else return 1 ; fi ; end ;;
103
118
104
- compiled_func5 := CapJitCompiledFunction( func5 , [ true ] );;
105
- Display( compiled_func5 );
119
+ compiled_func4 := CapJitCompiledFunction( func4 , [ true ] );;
120
+ Display( compiled_func4 );
106
121
# ! function ( x_1 )
107
122
# ! return 1;
108
123
# ! end
0 commit comments