]> gitweb.factorcode.org Git - factor.git/blob - core/compiler/test/templates-early.factor
Initial import
[factor.git] / core / compiler / test / templates-early.factor
1 ! Testing templates machinery without compiling anything
2 IN: temporary
3 USING: compiler generator generator.registers tools.test
4 namespaces sequences words kernel math effects ;
5
6 [
7     [ ] [ init-templates ] unit-test
8     
9     [ V{ 3 } ] [ 3 fresh-object fresh-objects get ] unit-test
10     
11     [ ] [ 0 <int-vreg> phantom-d get phantom-push ] unit-test
12     
13     [ ] [ compute-free-vregs ] unit-test
14     
15     [ f ] [ 0 <int-vreg> T{ int-regs } free-vregs member? ] unit-test
16     
17     [ f ] [
18         [
19             copy-templates
20             1 <int-vreg> phantom-d get phantom-push
21             compute-free-vregs
22             1 <int-vreg> T{ int-regs } free-vregs member?
23         ] with-scope
24     ] unit-test
25     
26     [ t ] [ 1 <int-vreg> T{ int-regs } free-vregs member? ] unit-test
27 ] with-scope
28
29 [
30     [ ] [ init-templates ] unit-test
31     
32     [ ] [ T{ effect f 3 { 1 2 0 } f } phantom-shuffle ] unit-test
33     
34     [ 3 ] [ live-locs length ] unit-test
35     
36     [ ] [ T{ effect f 2 { 1 0 } f } phantom-shuffle ] unit-test
37     
38     [ 2 ] [ live-locs length ] unit-test
39 ] with-scope
40
41 [
42     [ ] [ init-templates ] unit-test
43
44     [ ] [ init-generator ] unit-test
45
46     [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
47
48     3 fresh-object
49
50     [ f ] [ [ end-basic-block ] { } make empty? ] unit-test
51 ] with-scope
52
53 [
54     [ ] [ init-templates ] unit-test
55     
56     H{
57         { +input+ { { f "x" } } }
58     } clone [
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
64     ] bind
65 ] with-scope
66
67 ! Test template picking strategy
68 SYMBOL: template-chosen
69
70 : template-test ( a b -- c ) + ;
71
72 \ template-test {
73     {
74         [
75             1 template-chosen get push
76         ] H{
77             { +input+ { { f "obj" } { [ ] "n" } } }
78             { +output+ { "obj" } }
79         }
80     }
81     {
82         [
83             2 template-chosen get push
84         ] H{
85             { +input+ { { f "obj" } { f "n" } } }
86             { +output+ { "obj" } }
87         }
88     }
89 } define-intrinsics
90
91 [ V{ 2 } ] [
92     V{ } clone template-chosen set
93     [ template-test ] compile-quot drop
94     template-chosen get
95 ] unit-test
96
97 [ V{ 1 } ] [
98     V{ } clone template-chosen set
99     [ dup 0 template-test ] compile-quot drop
100     template-chosen get
101 ] unit-test
102
103 [ V{ 1 } ] [
104     V{ } clone template-chosen set
105     [ 0 template-test ] compile-quot drop
106     template-chosen get
107 ] unit-test
108
109 ! Regression
110 [
111     [ ] [ init-templates ] unit-test
112
113     ! dup dup
114     [ ] [
115         T{ effect f { "x" } { "x" "x" } } phantom-shuffle
116         T{ effect f { "x" } { "x" "x" } } phantom-shuffle
117     ] unit-test
118
119     ! This is not empty since a load instruction is emitted
120     [ f ] [
121         [ { { f "x"  } } fast-input ] { } make empty?
122     ] unit-test
123
124     ! This is empty since we already loaded the value
125     [ t ] [
126         [ { { f "x"  } } fast-input ] { } make empty?
127     ] unit-test
128
129     ! This is empty since we didn't change the stack
130     [ t ] [ [ end-basic-block ] { } make empty? ] unit-test
131 ] with-scope