1 ! Testing templates machinery without compiling anything
3 USING: compiler generator generator.registers tools.test
4 namespaces sequences words kernel math effects ;
7 [ ] [ init-templates ] unit-test
9 [ V{ 3 } ] [ 3 fresh-object fresh-objects get ] unit-test
11 [ ] [ 0 <int-vreg> phantom-d get phantom-push ] unit-test
13 [ ] [ compute-free-vregs ] unit-test
15 [ f ] [ 0 <int-vreg> T{ int-regs } free-vregs member? ] unit-test
20 1 <int-vreg> phantom-d get phantom-push
22 1 <int-vreg> T{ int-regs } free-vregs member?
26 [ t ] [ 1 <int-vreg> T{ int-regs } free-vregs member? ] unit-test
30 [ ] [ init-templates ] unit-test
32 [ ] [ T{ effect f 3 { 1 2 0 } f } phantom-shuffle ] unit-test
34 [ 3 ] [ live-locs length ] unit-test
36 [ ] [ T{ effect f 2 { 1 0 } f } phantom-shuffle ] unit-test
38 [ 2 ] [ live-locs length ] unit-test
42 [ ] [ init-templates ] unit-test
44 [ ] [ init-generator ] unit-test
46 [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
50 [ f ] [ [ end-basic-block ] { } make empty? ] unit-test
54 [ ] [ init-templates ] unit-test
57 { +input+ { { f "x" } } }
59 [ 1 0 ] [ +input+ get { } { } guess-vregs ] unit-test
60 [ ] [ 1 0 ensure-vregs ] unit-test
61 ! [ t ] [ +input+ get phantom-d get compatible? ] unit-test
62 [ ] [ finalize-contents ] unit-test
63 [ ] [ [ template-inputs ] { } make drop ] unit-test
67 ! Test template picking strategy
68 SYMBOL: template-chosen
70 : template-test ( a b -- c ) + ;
75 1 template-chosen get push
77 { +input+ { { f "obj" } { [ ] "n" } } }
78 { +output+ { "obj" } }
83 2 template-chosen get push
85 { +input+ { { f "obj" } { f "n" } } }
86 { +output+ { "obj" } }
92 V{ } clone template-chosen set
93 [ template-test ] compile-quot drop
98 V{ } clone template-chosen set
99 [ dup 0 template-test ] compile-quot drop
104 V{ } clone template-chosen set
105 [ 0 template-test ] compile-quot drop
111 [ ] [ init-templates ] unit-test
115 T{ effect f { "x" } { "x" "x" } } phantom-shuffle
116 T{ effect f { "x" } { "x" "x" } } phantom-shuffle
119 ! This is not empty since a load instruction is emitted
121 [ { { f "x" } } fast-input ] { } make empty?
124 ! This is empty since we already loaded the value
126 [ { { f "x" } } fast-input ] { } make empty?
129 ! This is empty since we didn't change the stack
130 [ t ] [ [ end-basic-block ] { } make empty? ] unit-test