about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xapps/mubin345626 -> 347319 bytes
-rw-r--r--apps/mu.subx136
2 files changed, 135 insertions, 1 deletions
diff --git a/apps/mu b/apps/mu
index 5507e0c5..1edbf9a3 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index 40628ece..d8790c87 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -1179,6 +1179,50 @@ test-convert-function-with-local-var-in-reg:
     5d/pop-to-ebp
     c3/return
 
+test-initializer-in-hex:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # setup
+    (clear-stream _test-input-stream)
+    (clear-stream $_test-input-buffered-file->buffer)
+    (clear-stream _test-output-stream)
+    (clear-stream $_test-output-buffered-file->buffer)
+    (clear-stream _test-error-stream)
+    (clear-stream $_test-error-buffered-file->buffer)
+    # var ed/edx: exit-descriptor = tailor-exit-descriptor(16)
+    68/push 0/imm32
+    68/push 0/imm32
+    89/<- %edx 4/r32/esp
+    (tailor-exit-descriptor %edx 0x10)
+    #
+    (write _test-input-stream "fn foo {\n")
+    (write _test-input-stream "  var x/ecx: int <- copy 10\n")
+    (write _test-input-stream "}\n")
+    # convert
+    (convert-mu _test-input-buffered-file _test-output-buffered-file _test-error-buffered-file %edx)
+    # registers except esp clobbered at this point
+    # restore ed
+    89/<- %edx 4/r32/esp
+    (flush _test-output-buffered-file)
+    (flush _test-error-buffered-file)
+#?     # dump _test-error-stream {{{
+#?     (write 2 "^")
+#?     (write-stream 2 _test-error-stream)
+#?     (write 2 "$\n")
+#?     (rewind-stream _test-error-stream)
+#?     # }}}
+    # check output
+    (check-stream-equal _test-output-stream  ""  "F - test-initializer-in-hex: output should be empty")
+    (check-next-stream-line-equal _test-error-stream  "literal integers are always hex in Mu; either start '10' with a '0x' to be unambiguous, or convert it to decimal."  "F - test-initializer-in-hex: error message")
+    # check that stop(1) was called
+    (check-ints-equal *(edx+4) 2 "F - test-initializer-in-hex: exit status")
+    # don't restore from ebp
+    81 0/subop/add %esp 8/imm32
+    # . epilogue
+    5d/pop-to-ebp
+    c3/return
+
 test-convert-function-with-second-local-var-in-same-reg:
     # . prologue
     55/push-ebp
@@ -3566,6 +3610,50 @@ test-convert-function-with-local-array-var-in-mem:
     5d/pop-to-ebp
     c3/return
 
+test-array-size-in-hex:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # setup
+    (clear-stream _test-input-stream)
+    (clear-stream $_test-input-buffered-file->buffer)
+    (clear-stream _test-output-stream)
+    (clear-stream $_test-output-buffered-file->buffer)
+    (clear-stream _test-error-stream)
+    (clear-stream $_test-error-buffered-file->buffer)
+    # var ed/edx: exit-descriptor = tailor-exit-descriptor(16)
+    68/push 0/imm32
+    68/push 0/imm32
+    89/<- %edx 4/r32/esp
+    (tailor-exit-descriptor %edx 0x10)
+    #
+    (write _test-input-stream "fn foo {\n")
+    (write _test-input-stream "  var x: (array int 10)\n")
+    (write _test-input-stream "}\n")
+    # convert
+    (convert-mu _test-input-buffered-file _test-output-buffered-file _test-error-buffered-file %edx)
+    # registers except esp clobbered at this point
+    # restore ed
+    89/<- %edx 4/r32/esp
+    (flush _test-output-buffered-file)
+    (flush _test-error-buffered-file)
+#?     # dump _test-error-stream {{{
+#?     (write 2 "^")
+#?     (write-stream 2 _test-error-stream)
+#?     (write 2 "$\n")
+#?     (rewind-stream _test-error-stream)
+#?     # }}}
+    # check output
+    (check-stream-equal _test-output-stream  ""  "F - test-array-size-in-hex: output should be empty")
+    (check-next-stream-line-equal _test-error-stream  "literal integers are always hex in Mu; either start '10' with a '0x' to be unambiguous, or convert it to decimal."  "F - test-array-size-in-hex: error message")
+    # check that stop(1) was called
+    (check-ints-equal *(edx+4) 2 "F - test-array-size-in-hex: exit status")
+    # don't restore from ebp
+    81 0/subop/add %esp 8/imm32
+    # . epilogue
+    5d/pop-to-ebp
+    c3/return
+
 # special-case for size(byte) when allocating array
 test-convert-function-with-local-array-of-bytes-in-mem:
     # . prologue
@@ -7027,7 +7115,7 @@ parse-type:  # ad: (addr allocation-descriptor), in: (addr stream byte), out: (a
       # if (s != "(") break
       (slice-equal? %ecx "(")  # => eax
       3d/compare-eax-and 0/imm32/false
-      75/jump-if-!= break/disp8
+      0f 85/jump-if-!= break/disp32
       # if s is a number, store it in the type's size field
       {
 $parse-type:check-for-int:
@@ -7044,6 +7132,7 @@ $parse-type:check-for-int:
         3d/compare-eax-and 0/imm32/false
         74/jump-if-= break/disp8
 $parse-type:int:
+        (check-mu-hex-int %ecx *(ebp+0x14) *(ebp+0x18))
         (parse-hex-int-from-slice %ecx)  # => eax
         c7 0/subop/copy *(edx+4) 9/imm32/type-id-array-capacity  # Type-tree-value
         89/<- *(edx+8) 0/r32/eax  # Type-tree-value-size
@@ -9496,6 +9585,8 @@ new-literal-integer:  # ad: (addr allocation-descriptor), name: (addr slice), ou
     (is-hex-int? *(ebp+0xc))  # => eax
     3d/compare-eax-and 0/imm32/false
     0f 84/jump-if-= $new-literal-integer:abort/disp32
+    # a little more error-checking
+    (check-mu-hex-int *(ebp+0xc) *(ebp+0x18) *(ebp+0x1c))
     # out = new var(s)
     (new-var-from-slice *(ebp+8) *(ebp+0xc) *(ebp+0x10))
     # var out-addr/ecx: (addr var) = lookup(*out)
@@ -9534,6 +9625,49 @@ $new-literal-integer:abort:
     (stop *(ebp+0x1c) 1)
     # never gets here
 
+# precondition: name is a valid hex integer; require a '0x' prefix
+check-mu-hex-int:  # name: (addr slice), err: (addr buffered-file), ed: (addr exit-descriptor)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    52/push-edx
+    #
+    8b/-> *(ebp+8) 1/r32/ecx
+    # var start/ecx: (addr byte) = name->start
+    8b/-> *(ecx+4) 2/r32/edx
+    # var end/ecx: (addr byte) = name->end
+    8b/-> *ecx 1/r32/ecx
+    # var len/eax: int = name->end - name->start
+    89/<- %eax 2/r32/edx
+    29/subtract-from %eax 1/r32/ecx
+    # if (len <= 1) return
+    3d/compare-eax-with 1/imm32
+    0f 8e/jump-if-<= $check-mu-hex-int:end/disp32
+$check-mu-hex-int:length->-1:
+    # if slice-starts-with?("0x") return
+    (slice-starts-with? *(ebp+8) "0x")  # => eax
+    3d/compare-eax-with 0/imm32/false
+    75/jump-if-!= $check-mu-hex-int:end/disp8
+$check-mu-hex-int:abort:
+    # otherwise abort
+    (write-buffered *(ebp+0xc) "literal integers are always hex in Mu; either start '")
+    (write-slice-buffered *(ebp+0xc) *(ebp+8))
+    (write-buffered *(ebp+0xc) "' with a '0x' to be unambiguous, or convert it to decimal.\n")
+    (flush *(ebp+0xc))
+    (stop *(ebp+0x10) 1)
+$check-mu-hex-int:end:
+    # . restore registers
+    5a/pop-to-edx
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 new-literal:  # ad: (addr allocation-descriptor), name: (addr slice), out: (addr handle var)
     # . prologue
     55/push-ebp
ni-tty/commit/src/ui/confwin.c?id=1f8b1eb740391941e79e1004ad041f8178a2b674'>1f8b1eb7 ^
a761ea71 ^
a952776b ^
a761ea71 ^
a2726b6a ^

a761ea71 ^
a2726b6a ^
a761ea71 ^


a2726b6a ^
1f8b1eb7 ^
a761ea71 ^

a2726b6a ^
a952776b ^
a761ea71 ^






a2726b6a ^
a761ea71 ^
38255e9b ^

a2726b6a ^

a952776b ^
1f8b1eb7 ^
a761ea71 ^


a2726b6a ^
a761ea71 ^
38255e9b ^
a761ea71 ^
a2726b6a ^
a761ea71 ^
38255e9b ^
a952776b ^
a761ea71 ^
1f8b1eb7 ^
371b64a8 ^
1f8b1eb7 ^
371b64a8 ^
1f8b1eb7 ^


a761ea71 ^


a2726b6a ^
a761ea71 ^
91060292 ^

a2726b6a ^

a761ea71 ^
1f8b1eb7 ^
a761ea71 ^
711c5b8e ^
a761ea71 ^
711c5b8e ^
a761ea71 ^

1f8b1eb7 ^
a761ea71 ^
1f8b1eb7 ^
a761ea71 ^

a2726b6a ^

a761ea71 ^



1f8b1eb7 ^

a761ea71 ^


1f8b1eb7 ^

a761ea71 ^
1f8b1eb7 ^

a761ea71 ^


1f8b1eb7 ^

a761ea71 ^

1f8b1eb7 ^

a761ea71 ^


1f8b1eb7 ^
a761ea71 ^



1f8b1eb7 ^


a761ea71 ^


1f8b1eb7 ^
a761ea71 ^



1f8b1eb7 ^

a761ea71 ^

1f8b1eb7 ^


a761ea71 ^







1f8b1eb7 ^
a761ea71 ^



a2726b6a ^
a761ea71 ^
2a65aa00 ^

a761ea71 ^
a2726b6a ^
1f8b1eb7 ^


a761ea71 ^



a2726b6a ^
a761ea71 ^
1f8b1eb7 ^
ce5f07a0 ^
a761ea71 ^
ce5f07a0 ^
a761ea71 ^
ce5f07a0 ^
a761ea71 ^

a2726b6a ^

a761ea71 ^





a2726b6a ^
a761ea71 ^

ce5f07a0 ^
a761ea71 ^
ce5f07a0 ^
a761ea71 ^






a2726b6a ^
a761ea71 ^
ce5f07a0 ^
a761ea71 ^







a2726b6a ^

a761ea71 ^
1f8b1eb7 ^
a761ea71 ^





711c5b8e ^
a761ea71 ^
a2726b6a ^
a761ea71 ^
711c5b8e ^
a761ea71 ^
71c9cbf8 ^
711c5b8e ^
a761ea71 ^
711c5b8e ^
a761ea71 ^






a2726b6a ^


a761ea71 ^
a2726b6a ^
a761ea71 ^
1f8b1eb7 ^
a761ea71 ^
1f8b1eb7 ^
a761ea71 ^







a2726b6a ^

a761ea71 ^
a2726b6a ^
a761ea71 ^
1f8b1eb7 ^
a761ea71 ^
1f8b1eb7 ^
a761ea71 ^






a2726b6a ^
a761ea71 ^
ce5f07a0 ^
a761ea71 ^






a2726b6a ^
1f8b1eb7 ^
a761ea71 ^




a2726b6a ^
a761ea71 ^
ce5f07a0 ^
a761ea71 ^







d9435d3b ^

a2726b6a ^
d9435d3b ^


a2726b6a ^
d9435d3b ^
a2726b6a ^
d9435d3b ^


a2726b6a ^
d9435d3b ^



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