about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-15 22:53:15 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-18 00:44:49 -0700
commit8ec4d9264936a7b178fe66fc50f87aaebc56f9e5 (patch)
tree468e79493826a592351e45a4f7667f8bfa2106bd
parent23cab12bb6bc56c709c06f91c7d7c4ce782b32b0 (diff)
downloadmu-8ec4d9264936a7b178fe66fc50f87aaebc56f9e5.tar.gz
mu.subx: fourth code-gen test
-rw-r--r--apps/mu.subx131
1 files changed, 102 insertions, 29 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index 08ffef9e..b040c20c 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -11450,7 +11450,7 @@ $test-emit-subx-stmt-select-primitive:initialize-primitive-subx-name:
 
 test-emit-subx-stmt-select-primitive-2:
     # Select the right primitive between overloads.
-    #   foo <- increment
+    #   increment foo
     # =>
     #   ff 0/subop/increment %eax  # sub-optimal, but should suffice
     #
@@ -11473,65 +11473,138 @@ test-emit-subx-stmt-select-primitive-2:
     # setup
     (clear-stream _test-output-stream)
     (clear-stream $_test-output-buffered-file->buffer)
+$test-emit-subx-stmt-select-primitive-2:initialize-type:
     # var type/ecx: (handle tree type-id) = int
-    68/push 0/imm32/right/null
-    68/push 1/imm32/left/int
+    68/push 0/imm32/right:null
+    68/push 0/imm32/right:null
+    68/push 0/imm32/left:unused
+    68/push 1/imm32/value:int
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0x11/imm32/alloc-id:fake:payload
     89/<- %ecx 4/r32/esp
-    # var var-foo/ecx: var in eax
-    68/push "eax"/imm32/register
+$test-emit-subx-stmt-select-primitive-2:initialize-var:
+    # var var-foo/ecx: (handle var)
+    68/push 0/imm32/register
+    68/push 0/imm32/register
     68/push 0/imm32/no-stack-offset
     68/push 1/imm32/block-depth
     51/push-ecx
-    68/push "foo"/imm32
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0/imm32/name
+    68/push 0/imm32/name
+    68/push 0x11/imm32/alloc-id:fake:payload
     89/<- %ecx 4/r32/esp
-    # var inouts/edi: (handle stmt-var)
+$test-emit-subx-stmt-select-primitive-2:initialize-var-name:
+    # var-foo->name = "foo"
+    8d/copy-address *(ecx+4) 0/r32/eax  # Var-name + 4
+    (copy-array Heap "foo" %eax)
+$test-emit-subx-stmt-select-primitive-2:initialize-var-register:
+    # var-foo->register = "eax"
+    8d/copy-address *(ecx+0x1c) 0/r32/eax  # Var-register + 4
+    (copy-array Heap "eax" %eax)
+$test-emit-subx-stmt-select-primitive-2:initialize-stmt-var:
+    # var operand/ebx: (handle stmt-var)
     68/push 0/imm32/is-deref:false
     68/push 0/imm32/next
-    51/push-ecx/var-foo
-    89/<- %edi 4/r32/esp
-    # var stmt/esi: statement
     68/push 0/imm32/next
+    51/push-ecx/var-foo
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0x11/imm32/alloc-id:fake:payload
+    89/<- %ebx 4/r32/esp
+$test-emit-subx-stmt-select-primitive-2:initialize-stmt:
+    # var stmt/esi: (addr statement)
     68/push 0/imm32/outputs
-    57/push-edi/inouts
-    68/push "increment"/imm32/operation
+    68/push 0/imm32/outputs
+    53/push-ebx/inouts
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0/imm32/operation
+    68/push 0/imm32/operation
     68/push 1/imm32
     89/<- %esi 4/r32/esp
-    # var formal-var/ebx: var in any register
-    68/push Any-register/imm32
+$test-emit-subx-stmt-select-primitive-2:initialize-stmt-operation:
+    # stmt->operation = "increment"
+    8d/copy-address *(esi+4) 0/r32/eax  # Stmt1-operation
+    (copy-array Heap "increment" %eax)
+$test-emit-subx-stmt-select-primitive-2:initialize-formal-var:
+    # var formal-var/ebx: (handle var)
+    68/push 0/imm32/register
+    68/push 0/imm32/register
     68/push 0/imm32/no-stack-offset
     68/push 1/imm32/block-depth
-    ff 6/subop/push *(ecx+4)  # Var-type
-    68/push "dummy"/imm32
+    ff 6/subop/push *(ecx+0x10)  # Var-type + payload alloc id + handle alloc id
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0/imm32/name
+    68/push 0/imm32/name
+    68/push 0x11/imm32/alloc-id:fake:payload
     89/<- %ebx 4/r32/esp
-    # var operand/ebx: (handle stmt-var)
-    68/push 0/imm32/is-deref:false
+$test-emit-subx-stmt-select-primitive-2:initialize-formal-var-name:
+    # formal-var->name = "dummy"
+    8d/copy-address *(ebx+4) 0/r32/eax  # Var-name + 4
+    (copy-array Heap "dummy" %eax)
+$test-emit-subx-stmt-select-primitive-2:initialize-formal-register:
+    # formal-var->register = "*"
+    8d/copy-address *(ebx+0x1c) 0/r32/eax  # Var-register + 4
+    (copy-array Heap "*" %eax)  # Any-register
+$test-emit-subx-stmt-select-primitive-2:initialize-var-list:
+    # var formal-outputs/ebx: (handle list stmt-var)
+    68/push 0/imm32/next
     68/push 0/imm32/next
     53/push-ebx/formal-var
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0x11/imm32/alloc-id:fake:payload
     89/<- %ebx 4/r32/esp
-    # var primitive1/ebx: primitive
+$test-emit-subx-stmt-select-primitive-2:initialize-primitive2:
+    # var primitive2/edi: (handle primitive)
+    68/push 0/imm32/next
     68/push 0/imm32/next
     68/push 0/imm32/output-is-write-only
     68/push 0/imm32/no-disp32
     68/push 0/imm32/no-imm32
     68/push 0/imm32/no-r32
-    68/push 3/imm32/rm32-in-first-output
-    68/push "ff 0/subop/increment"/imm32/subx-name
-    53/push-ebx/outputs/formal-outputs
+    68/push 3/imm32/rm32-is-first-output
+    68/push 0/imm32/subx-name
+    68/push 0/imm32/subx-name
+    53/push-ebx/outputs
+    68/push 0x11/imm32/alloc-id:fake
     68/push 0/imm32/inouts
-    68/push "increment"/imm32/name
-    89/<- %ebx 4/r32/esp
-    # var primitives/ebx: primitive
-    53/push-ebx/next
+    68/push 0/imm32/inouts
+    68/push 0/imm32/name
+    68/push 0/imm32/name
+    68/push 0x11/imm32/alloc-id:fake:payload
+    89/<- %edi 4/r32/esp
+$test-emit-subx-stmt-select-primitive-2:initialize-primitive2-name:
+    # primitives->name = "increment"
+    8d/copy-address *(edi+4) 0/r32/eax  # Primitive-name + 4
+    (copy-array Heap "increment" %eax)
+$test-emit-subx-stmt-select-primitive-2:initialize-primitive2-subx-name:
+    # primitives->subx-name = "ff 0/subop/increment"
+    8d/copy-address *(edi+0x1c) 0/r32/eax  # Primitive-subx-name + 4
+    (copy-array Heap "ff 0/subop/increment" %eax)
+$test-emit-subx-stmt-select-primitive-2:initialize-primitive:
+    # var primitives/ebx: (addr primitive)
+    57/push-edi
+    68/push 0x11/imm32/alloc-id:fake
     68/push 0/imm32/output-is-write-only
     68/push 0/imm32/no-disp32
     68/push 0/imm32/no-imm32
     68/push 0/imm32/no-r32
     68/push 1/imm32/rm32-is-first-inout
-    68/push "ff 0/subop/increment"/imm32/subx-name
+    68/push 0/imm32/subx-name
+    68/push 0/imm32/subx-name
+    68/push 0/imm32/outputs
     68/push 0/imm32/outputs
-    57/push-edi/inouts/real-outputs  # hack; in practice we won't have the same var in function definition and call
-    68/push "increment"/imm32/name
+    53/push-ebx/inouts  # hack: reuse stmt-var from call stmt as (list var) in function declaration
+    68/push 0x11/imm32/alloc-id:fake
+    68/push 0/imm32/name
+    68/push 0/imm32/name
     89/<- %ebx 4/r32/esp
+$test-emit-subx-stmt-select-primitive-2:initialize-primitive-name:
+    # primitives->name = "increment"
+    (copy-array Heap "increment" %ebx)  # Primitive-name
+$test-emit-subx-stmt-select-primitive-2:initialize-primitive-subx-name:
+    # primitives->subx-name = "ff 0/subop/increment"
+    8d/copy-address *(ebx+0x18) 0/r32/eax  # Primitive-subx-name
+    (copy-array Heap "ff 0/subop/increment" %eax)
     # convert
     c7 0/subop/copy *Curr-block-depth 0/imm32
     (emit-subx-stmt _test-output-buffered-file %esi %ebx)
pre>93397e45 ^
a2726b6a ^
93397e45 ^
3bb1f124 ^
a871ad80 ^
055a5f71 ^
93397e45 ^
a2726b6a ^
a871ad80 ^

93397e45 ^
81190251 ^
93397e45 ^

0499c4e0 ^
055a5f71 ^
93397e45 ^
a578419d ^
a2726b6a ^

a578419d ^
a2726b6a ^
a578419d ^
3bb1f124 ^
a871ad80 ^
81190251 ^
a578419d ^
81190251 ^
a578419d ^
a578419d ^

a2726b6a ^

a578419d ^
a2726b6a ^


a578419d ^
3bb1f124 ^
a871ad80 ^


a578419d ^
81190251 ^
a578419d ^
a578419d ^
bcafba2d ^
a2726b6a ^

bcafba2d ^
a2726b6a ^
bcafba2d ^
3bb1f124 ^
a871ad80 ^
81190251 ^
bcafba2d ^
81190251 ^
bcafba2d ^
bcafba2d ^

a2726b6a ^

bcafba2d ^
a2726b6a ^

bcafba2d ^
3bb1f124 ^
a871ad80 ^

bcafba2d ^
81190251 ^
bcafba2d ^
bcafba2d ^
11c04d9f ^
a2726b6a ^

11c04d9f ^
a2726b6a ^
11c04d9f ^
3bb1f124 ^
a871ad80 ^
81190251 ^
11c04d9f ^
81190251 ^
11c04d9f ^
11c04d9f ^

a2726b6a ^

11c04d9f ^
a2726b6a ^
11c04d9f ^
3bb1f124 ^
a871ad80 ^
81190251 ^
11c04d9f ^
81190251 ^
11c04d9f ^
11c04d9f ^

a2726b6a ^

11c04d9f ^
a2726b6a ^
11c04d9f ^
055a5f71 ^
a871ad80 ^
3bb1f124 ^
a871ad80 ^
11c04d9f ^

81190251 ^
11c04d9f ^

055a5f71 ^
11c04d9f ^

a2726b6a ^

11c04d9f ^
a2726b6a ^


11c04d9f ^
055a5f71 ^
a2726b6a ^
055a5f71 ^
11c04d9f ^

3bb1f124 ^
a871ad80 ^




11c04d9f ^

81190251 ^
11c04d9f ^



5b19ed28 ^
055a5f71 ^
11c04d9f ^

a2726b6a ^

11c04d9f ^
a2726b6a ^
11c04d9f ^
3bb1f124 ^
a871ad80 ^
81190251 ^
11c04d9f ^
81190251 ^
11c04d9f ^
11c04d9f ^

a2726b6a ^

11c04d9f ^
a2726b6a ^
11c04d9f ^
055a5f71 ^
a871ad80 ^
3bb1f124 ^
a871ad80 ^
11c04d9f ^

81190251 ^
11c04d9f ^

055a5f71 ^
11c04d9f ^

a2726b6a ^

11c04d9f ^
a2726b6a ^

11c04d9f ^
055a5f71 ^
a2726b6a ^
055a5f71 ^
11c04d9f ^

3bb1f124 ^
a871ad80 ^




11c04d9f ^

81190251 ^
11c04d9f ^




055a5f71 ^
11c04d9f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253