about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-11-27 16:50:23 -0800
committerKartik Agaram <vc@akkartik.com>2019-11-27 17:02:13 -0800
commit703f6ab1ae6ac8d1ac96d8765dfa76c6061279a9 (patch)
tree6f992d6024a6c12c531f389cc7fe2af2be5cec12 /apps
parent374397f0cbd841bb76f0798eae7d3a18f5eef3b6 (diff)
downloadmu-703f6ab1ae6ac8d1ac96d8765dfa76c6061279a9.tar.gz
5767
Some groundwork for parsing.
Diffstat (limited to 'apps')
-rwxr-xr-xapps/mubin53751 -> 54274 bytes
-rw-r--r--apps/mu.subx191
2 files changed, 175 insertions, 16 deletions
diff --git a/apps/mu b/apps/mu
index 25d5ed3d..1f1c5b5a 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index c3a1020a..0a1814a7 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -280,7 +280,7 @@ Block-statements:  # (address list statement)
 
 Stmt1-operation:  # string
   4/imm32
-Stmt1-inouts:  # (address list operand)
+Stmt1-inouts:  # (address list var)
   8/imm32
 Stmt1-outputs:  # (address list var)
   0xc/imm32
@@ -302,14 +302,6 @@ Named-block-name:
 Named-block-statements:  # (address list statement)
   8/imm32
 
-Stmt-operation:
-  0/imm32
-Stmt-inouts:
-  4/imm32
-Stmt-outputs:
-  8/imm32
-Stmt-next:
-  0xc/imm32
 Stmt-size:
   0x10/imm32
 
@@ -562,6 +554,10 @@ test-convert-function-with-arg:
     5d/pop-to-ebp
     c3/return
 
+#######################################################
+# Parsing
+#######################################################
+
 parse-mu:  # in : (address buffered-file)
     # pseudocode
     #   var curr-function = Program
@@ -886,17 +882,186 @@ $parse-mu-block:abort:
     cd/syscall  0x80/imm8
     # never gets here
 
+new-function:  # ad: allocation-descriptor, name: string, subx-name: string, inouts: (address list var), outputs: (address list var), body: (address block), next: (address function) -> result/eax: (address function)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Function-size)  # => eax
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *eax 1/r32/ecx  # Function-name
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Function-subx-name
+    8b/-> *(ebp+0x14) 1/r32/ecx
+    89/<- *(eax+8) 1/r32/ecx  # Function-inouts
+    8b/-> *(ebp+0x18) 1/r32/ecx
+    89/<- *(eax+0xc) 1/r32/ecx  # Function-outputs
+    8b/-> *(ebp+0x1c) 1/r32/ecx
+    89/<- *(eax+0x10) 1/r32/ecx  # Function-body
+    8b/-> *(ebp+0x20) 1/r32/ecx
+    89/<- *(eax+0x14) 1/r32/ecx  # Function-next
+$new-function:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+new-var:  # ad: allocation-descriptor, name: string, type: int, block: int, stack-offset: int, register: string -> result/eax: (address var)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Var-size)  # => eax
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *eax 1/r32/ecx  # Var-name
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Var-type
+    8b/-> *(ebp+0x14) 1/r32/ecx
+    89/<- *(eax+8) 1/r32/ecx  # Var-block
+    8b/-> *(ebp+0x18) 1/r32/ecx
+    89/<- *(eax+0xc) 1/r32/ecx  # Var-stack-offset
+    8b/-> *(ebp+0x1c) 1/r32/ecx
+    89/<- *(eax+0x10) 1/r32/ecx  # Var-register
+$new-var:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+new-block:  # ad: allocation-descriptor, data: (address list statement)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Stmt-size)  # => eax
+    c7 0/subop/copy *eax 0/imm32/tag/block  # Stmt-tag
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Block-statements
+$new-block:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+new-stmt:  # ad: allocation-descriptor, operation: string, inouts: (address list var), outputs: (address list var) -> result/eax: (address statement)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Stmt-size)  # => eax
+    c7 0/subop/copy *eax 1/imm32/tag/regular-stmt  # Stmt-tag
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Stmt1-operation
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    89/<- *(eax+8) 1/r32/ecx  # Stmt1-inouts
+    8b/-> *(ebp+0x14) 1/r32/ecx
+    89/<- *(eax+0xc) 1/r32/ecx  # Stmt1-outputs
+$new-stmt:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+new-vardef:  # ad: allocation-descriptor, name: string, type: int -> result/eax: (address statement)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Stmt-size)  # => eax
+    c7 0/subop/copy *eax 2/imm32/tag/var-on-stack  # Stmt-tag
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Vardef-name
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    89/<- *(eax+8) 1/r32/ecx  # Vardef-type
+$new-vardef:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+new-regvardef:  # ad: allocation-descriptor, name: string, type: int, register: string -> result/eax: (address statement)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Stmt-size)  # => eax
+    c7 0/subop/copy *eax 3/imm32/tag/var-in-register
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Regvardef-name
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    89/<- *(eax+8) 1/r32/ecx  # Regvardef-type
+    8b/-> *(ebp+0x14) 1/r32/ecx
+    89/<- *(eax+0xc) 1/r32/ecx  # Regvardef-register
+$new-regvardef:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+new-named-block:  # ad: allocation-descriptor, name: string, data: (address list statement)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    #
+    (allocate *(ebp+8) *Stmt-size)  # => eax
+    c7 0/subop/copy *eax 4/imm32/tag/named-block
+    8b/-> *(ebp+0xc) 1/r32/ecx
+    89/<- *(eax+4) 1/r32/ecx  # Named-block-name
+    8b/-> *(ebp+0x10) 1/r32/ecx
+    89/<- *(eax+8) 1/r32/ecx  # Named-block-statements
+$new-named-block:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+#######################################################
+# Type-checking
+#######################################################
+
 check-mu-types:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-$check-types:end:
+$check-mu-types:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
     c3/return
 
+#######################################################
+# Code-generation
+#######################################################
+
 emit-subx:  # out : (address buffered-file)
     # . prologue
     55/push-ebp
@@ -928,12 +1093,6 @@ $emit-subx:end:
     5d/pop-to-ebp
     c3/return
 
-# == Emitting a function
-# Emit function header
-# Emit function prologue
-# Translate function body
-# Emit function epilogue
-
 emit-subx-function:  # out : (address buffered-file), f : (address function)
     # . prologue
     55/push-ebp
'Blame the previous revision' href='/akkartik/mu/blame/076continuation.cc?h=hlt&id=b74744cd5851e034a88d4a335b22a372ebb39237'>^
f8f22245 ^
53930831 ^
f8f22245 ^
53930831 ^






c1bb5eca ^


53930831 ^



4856c701 ^

53930831 ^




53ba69a7 ^
f8f22245 ^
d82d9035 ^
53ba69a7 ^





53930831 ^



53ba69a7 ^

dd660682 ^
53ba69a7 ^





d82d9035 ^


dd660682 ^
d82d9035 ^





53930831 ^


87374384 ^





53930831 ^
87374384 ^
a3195d44 ^
53930831 ^

a3195d44 ^
53930831 ^






d37c983a ^


53930831 ^



7fb1017b ^


53930831 ^


5059f32d ^
f8f22245 ^
53930831 ^
d82d9035 ^
4856c701 ^


53930831 ^

a3195d44 ^
87374384 ^
53930831 ^









4c513685 ^
f8f22245 ^
53930831 ^




f8f22245 ^
53930831 ^
f8f22245 ^
53930831 ^




c6ab07f7 ^
03d673bb ^

a3195d44 ^
fe63e0d6 ^
03d673bb ^
87374384 ^
acce384b ^
03d673bb ^

fe63e0d6 ^
03d673bb ^

53930831 ^
fa76b0b5 ^

3b776ac3 ^
03d673bb ^
a3195d44 ^
0e1ebc3e ^


5059f32d ^
0e1ebc3e ^






5059f32d ^
0e1ebc3e ^

0e1ebc3e ^
0e1ebc3e ^
5059f32d ^


















07de3e95 ^



5059f32d ^
07de3e95 ^








5059f32d ^

1cd83361 ^
07de3e95 ^
5059f32d ^
07de3e95 ^
1cd83361 ^


5059f32d ^

1cd83361 ^



5059f32d ^

1cd83361 ^
07de3e95 ^
20252c5e ^

5059f32d ^
20252c5e ^



5059f32d ^
20252c5e ^


1cd83361 ^


5059f32d ^
1cd83361 ^




5059f32d ^
1cd83361 ^




a3195d44 ^




87374384 ^
2a81a547 ^








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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370