1 ! Testing templates machinery without compiling anything
3 USING: compiler compiler.generator compiler.generator.registers
4 compiler.generator.registers.private tools.test namespaces
5 sequences words kernel math effects definitions compiler.units
6 accessors cpu.architecture ;
8 : <int-vreg> ( n -- vreg ) int-regs <vreg> ;
11 [ ] [ init-templates ] unit-test
13 [ V{ 3 } ] [ 3 fresh-object fresh-objects get ] unit-test
15 [ ] [ 0 <int-vreg> phantom-push ] unit-test
17 [ ] [ compute-free-vregs ] unit-test
19 [ f ] [ 0 <int-vreg> int-regs free-vregs member? ] unit-test
24 1 <int-vreg> phantom-push
26 1 <int-vreg> int-regs free-vregs member?
30 [ t ] [ 1 <int-vreg> int-regs free-vregs member? ] unit-test
34 [ ] [ init-templates ] unit-test
36 [ ] [ T{ effect f 3 { 1 2 0 } f } phantom-shuffle ] unit-test
38 [ 3 ] [ live-locs length ] unit-test
40 [ ] [ T{ effect f 2 { 1 0 } f } phantom-shuffle ] unit-test
42 [ 2 ] [ live-locs length ] unit-test
46 [ ] [ init-templates ] unit-test
48 H{ } clone compiled set
50 [ ] [ gensym gensym begin-compiling ] unit-test
52 [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
56 [ f ] [ [ end-basic-block ] { } make empty? ] unit-test
60 [ ] [ init-templates ] unit-test
63 { +input+ { { f "x" } } }
65 [ 1 0 ] [ +input+ get { } { } guess-vregs ] unit-test
66 [ ] [ finalize-contents ] unit-test
67 [ ] [ [ template-inputs ] { } make drop ] unit-test
71 ! Test template picking strategy
72 SYMBOL: template-chosen
74 : template-test ( a b -- c d ) ;
79 1 template-chosen get push
81 { +input+ { { f "obj" } { [ ] "n" } } }
82 { +output+ { "obj" "obj" } }
87 2 template-chosen get push
89 { +input+ { { f "obj" } { f "n" } } }
90 { +output+ { "obj" "n" } }
96 V{ } clone template-chosen set
97 0 0 [ template-test ] compile-call 2drop
102 V{ } clone template-chosen set
103 1 [ dup 0 template-test ] compile-call 3drop
108 V{ } clone template-chosen set
109 1 [ 0 template-test ] compile-call 2drop
115 [ ] [ init-templates ] unit-test
119 T{ effect f { "x" } { "x" "x" } } phantom-shuffle
120 T{ effect f { "x" } { "x" "x" } } phantom-shuffle
123 ! This is not empty since a load instruction is emitted
125 [ { { f "x" } } +input+ set load-inputs ] { } make
129 ! This is empty since we already loaded the value
131 [ { { f "x" } } +input+ set load-inputs ] { } make
135 ! This is empty since we didn't change the stack
136 [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
141 [ ] [ init-templates ] unit-test
149 ! This is empty since we didn't change the stack
150 [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
158 [ ] [ { object } set-operand-classes ] unit-test
160 ! This is empty since we didn't change the stack
161 [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
166 [ ] [ init-templates ] unit-test
168 [ ] [ { object object } set-operand-classes ] unit-test
172 T{ effect f { "x" "y" } { "x" "y" "x" "y" } }
177 2 phantom-datastack get phantom-input
178 [ { { f "a" } { f "b" } } lazy-load ] { } make drop
182 phantom-datastack get stack>> [ cached? ] all?
190 ! This should not fail
191 [ ] [ [ end-basic-block ] { } make drop ] unit-test
195 SYMBOL: templates-chosen
197 V{ } clone templates-chosen set
199 : template-choice-1 ;
202 [ "template-choice-1" templates-chosen get push ]
204 { +input+ { { f "obj" } { [ ] "n" } } }
205 { +output+ { "obj" } }
208 : template-choice-2 ;
211 [ "template-choice-2" templates-chosen get push drop ]
212 { { f "x" } { f "y" } } define-if-intrinsic
215 [ 2 template-choice-1 template-choice-2 ]
216 [ define-temp ] with-compilation-unit drop
219 [ V{ "template-choice-1" "template-choice-2" } ]
220 [ templates-chosen get ] unit-test