https://github.com/akkartik/mu/blob/main/shell/sandbox.mu
1 type sandbox {
2 data: (handle gap-buffer)
3 value: (handle stream byte)
4 trace: (handle trace)
5 screen-var: (handle cell)
6 keyboard-var: (handle cell)
7 cursor-in-data?: boolean
8 cursor-in-trace?: boolean
9 cursor-in-keyboard?: boolean
10 }
11
12 fn initialize-sandbox _self: (addr sandbox), fake-screen-width: int, fake-screen-height: int {
13 var self/esi: (addr sandbox) <- copy _self
14 var data-ah/eax: (addr handle gap-buffer) <- get self, data
15 allocate data-ah
16 var data/eax: (addr gap-buffer) <- lookup *data-ah
17 initialize-gap-buffer data, 0x2000/default-gap-buffer-size=8KB
18
19 var value-ah/eax: (addr handle stream byte) <- get self, value
20 populate-stream value-ah, 0x1000/4KB
21
22 {
23 compare fake-screen-width, 0
24 break-if-=
25 var screen-ah/eax: (addr handle cell) <- get self, screen-var
26 new-fake-screen screen-ah, fake-screen-width, fake-screen-height, 1/enable-pixel-graphics
27 var keyboard-ah/eax: (addr handle cell) <- get self, keyboard-var
28 new-fake-keyboard keyboard-ah, 0x10/keyboard-capacity
29 }
30
31 var trace-ah/eax: (addr handle trace) <- get self, trace
32 allocate trace-ah
33 var trace/eax: (addr trace) <- lookup *trace-ah
34 initialize-trace trace, 4/max-depth, 0x8000/lines, 0x80/visible
35 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
36 copy-to *cursor-in-data?, 1/true
37 }
38
39
40
41 fn initialize-sandbox-with _self: (addr sandbox), s: (addr array byte) {
42 var self/esi: (addr sandbox) <- copy _self
43 var data-ah/eax: (addr handle gap-buffer) <- get self, data
44 allocate data-ah
45 var data/eax: (addr gap-buffer) <- lookup *data-ah
46 initialize-gap-buffer-with data, s
47 var value-ah/eax: (addr handle stream byte) <- get self, value
48 populate-stream value-ah, 0x1000/4KB
49 var trace-ah/eax: (addr handle trace) <- get self, trace
50 allocate trace-ah
51 var trace/eax: (addr trace) <- lookup *trace-ah
52 initialize-trace trace, 3/max-depth, 0x8000/lines, 0x80/visible
53 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
54 copy-to *cursor-in-data?, 1/true
55 }
56
57 fn allocate-sandbox-with _out: (addr handle sandbox), s: (addr array byte) {
58 var out/eax: (addr handle sandbox) <- copy _out
59 allocate out
60 var out-addr/eax: (addr sandbox) <- lookup *out
61 initialize-sandbox-with out-addr, s
62 }
63
64 fn write-sandbox out: (addr stream byte), _self: (addr sandbox) {
65 var self/eax: (addr sandbox) <- copy _self
66 var data-ah/eax: (addr handle gap-buffer) <- get self, data
67 var data/eax: (addr gap-buffer) <- lookup *data-ah
68 {
69 var len/eax: int <- gap-buffer-length data
70 compare len, 0
71 break-if-!=
72 return
73 }
74 write out, " (sandbox . ["
75 append-gap-buffer data, out
76 write out, "])\n"
77 }
78
79
80
81 fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: int, xmax: int, ymax: int, show-cursor?: boolean {
82 clear-rect screen, xmin, ymin, xmax, ymax, 0xc5/bg=blue-bg
83 add-to xmin, 1/padding-left
84 add-to ymin, 1/padding-top
85 subtract-from xmax, 1/padding-right
86 var self/esi: (addr sandbox) <- copy _self
87
88 var data-ah/eax: (addr handle gap-buffer) <- get self, data
89 var _data/eax: (addr gap-buffer) <- lookup *data-ah
90 var data/edx: (addr gap-buffer) <- copy _data
91 var x/eax: int <- copy xmin
92 var y/ecx: int <- copy ymin
93 y <- maybe-render-empty-screen screen, self, xmin, y
94 y <- maybe-render-keyboard screen, self, xmin, y
95 var cursor-in-editor?/ebx: boolean <- copy show-cursor?
96 {
97 compare cursor-in-editor?, 0/false
98 break-if-=
99 var cursor-in-data-a/eax: (addr boolean) <- get self, cursor-in-data?
100 cursor-in-editor? <- copy *cursor-in-data-a
101 }
102 x, y <- render-gap-buffer-wrapping-right-then-down screen, data, x, y, xmax, ymax, cursor-in-editor?, 7/fg, 0xc5/bg=blue-bg
103 y <- increment
104
105 var trace-ah/eax: (addr handle trace) <- get self, trace
106 var _trace/eax: (addr trace) <- lookup *trace-ah
107 var trace/edx: (addr trace) <- copy _trace
108 var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
109 y <- render-trace screen, trace, xmin, y, xmax, ymax, *cursor-in-trace?
110
111 $render-sandbox:value: {
112 compare y, ymax
113 break-if->=
114 var value-ah/eax: (addr handle stream byte) <- get self, value
115 var _value/eax: (addr stream byte) <- lookup *value-ah
116 var value/esi: (addr stream byte) <- copy _value
117 rewind-stream value
118 var done?/eax: boolean <- stream-empty? value
119 compare done?, 0/false
120 break-if-!=
121 var x/eax: int <- copy 0
122 x, y <- draw-text-wrapping-right-then-down screen, "=> ", xmin, y, xmax, ymax, xmin, y, 7/fg, 0xc5/bg=blue-bg
123 var x2/edx: int <- copy x
124 var dummy/eax: int <- draw-stream-rightward screen, value, x2, xmax, y, 7/fg=grey, 0xc5/bg=blue-bg
125 }
126 y <- add 2
127 maybe-render-screen screen, self, xmin, y
128 }
129
130 fn render-sandbox-menu screen: (addr screen), _self: (addr sandbox) {
131 var self/esi: (addr sandbox) <- copy _self
132 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
133 compare *cursor-in-data?, 0/false
134 {
135 break-if-=
136 render-sandbox-edit-menu screen, self
137 return
138 }
139 var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
140 compare *cursor-in-trace?, 0/false
141 {
142 break-if-=
143 render-trace-menu screen
144 return
145 }
146 var cursor-in-keyboard?/eax: (addr boolean) <- get self, cursor-in-keyboard?
147 compare *cursor-in-keyboard?, 0/false
148 {
149 break-if-=
150 render-keyboard-menu screen
151 return
152 }
153 }
154
155 fn clear-sandbox-output screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: int, xmax: int, ymax: int {
156
157 var self/esi: (addr sandbox) <- copy _self
158 var data-ah/eax: (addr handle gap-buffer) <- get self, data
159 var _data/eax: (addr gap-buffer) <- lookup *data-ah
160 var data/edx: (addr gap-buffer) <- copy _data
161 var x/eax: int <- copy xmin
162 var y/ecx: int <- copy ymin
163 y <- maybe-render-empty-screen screen, self, xmin, y
164 y <- maybe-render-keyboard screen, self, xmin, y
165 var cursor-in-sandbox?/ebx: (addr boolean) <- get self, cursor-in-data?
166 x, y <- render-gap-buffer-wrapping-right-then-down screen, data, x, y, xmax, ymax, *cursor-in-sandbox?, 3/fg, 0xc5/bg=blue-bg
167 y <- increment
168 clear-rect screen, xmin, y, xmax, ymax, 0xc5/bg=blue-bg
169 }
170
171 fn maybe-render-empty-screen screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: int -> _/ecx: int {
172 var self/esi: (addr sandbox) <- copy _self
173 var screen-obj-cell-ah/eax: (addr handle cell) <- get self, screen-var
174 var screen-obj-cell/eax: (addr cell) <- lookup *screen-obj-cell-ah
175 compare screen-obj-cell, 0
176 {
177 break-if-!=
178 return ymin
179 }
180 var screen-obj-cell-type/ecx: (addr int) <- get screen-obj-cell, type
181 compare *screen-obj-cell-type, 5/screen
182 {
183 break-if-=
184 return ymin
185 }
186 var y/ecx: int <- copy ymin
187 var screen-obj-ah/eax: (addr handle screen) <- get screen-obj-cell, screen-data
188 var _screen-obj/eax: (addr screen) <- lookup *screen-obj-ah
189 var screen-obj/edx: (addr screen) <- copy _screen-obj
190 var x/eax: int <- draw-text-rightward screen, "screen: ", xmin, 0x99/xmax, y, 0x17/fg, 0xc5/bg=blue-bg
191 x <- copy xmin
192 x <- add 2
193 y <- increment
194 y <- render-empty-screen screen, screen-obj, x, y
195 return y
196 }
197
198 fn maybe-render-screen screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: int {
199 var self/esi: (addr sandbox) <- copy _self
200 var screen-obj-cell-ah/eax: (addr handle cell) <- get self, screen-var
201 var screen-obj-cell/eax: (addr cell) <- lookup *screen-obj-cell-ah
202 compare screen-obj-cell, 0
203 {
204 break-if-!=
205 return
206 }
207 var screen-obj-cell-type/ecx: (addr int) <- get screen-obj-cell, type
208 compare *screen-obj-cell-type, 5/screen
209 {
210 break-if-=
211 return
212 }
213 var screen-obj-ah/eax: (addr handle screen) <- get screen-obj-cell, screen-data
214 var _screen-obj/eax: (addr screen) <- lookup *screen-obj-ah
215 var screen-obj/edx: (addr screen) <- copy _screen-obj
216 {
217 var screen-empty?/eax: boolean <- fake-screen-empty? screen-obj
218 compare screen-empty?, 0/false
219 break-if-=
220 return
221 }
222 var x/eax: int <- draw-text-rightward screen, "screen: ", xmin, 0x99/xmax, ymin, 0x17/fg, 0xc5/bg=blue-bg
223 x <- copy xmin
224 x <- add 2
225 var y/ecx: int <- copy ymin
226 y <- increment
227 render-screen screen, screen-obj, x, y
228 }
229
230 fn render-empty-screen screen: (addr screen), _target-screen: (addr screen), xmin: int, ymin: int -> _/ecx: int {
231 var target-screen/esi: (addr screen) <- copy _target-screen
232 var screen-y/edi: int <- copy ymin
233
234 var height/edx: (addr int) <- get target-screen, height
235 var y/ecx: int <- copy 0
236 {
237 compare y, *height
238 break-if->=
239 set-cursor-position screen, xmin, screen-y
240 var width/edx: (addr int) <- get target-screen, width
241 var x/ebx: int <- copy 0
242 {
243 compare x, *width
244 break-if->=
245 draw-code-point-at-cursor screen, 0x20/space, 0x18/fg, 0/bg
246 move-cursor-right screen
247 x <- increment
248 loop
249 }
250 y <- increment
251 screen-y <- increment
252 loop
253 }
254 return screen-y
255 }
256
257 fn render-screen screen: (addr screen), _target-screen: (addr screen), xmin: int, ymin: int {
258 var target-screen/esi: (addr screen) <- copy _target-screen
259 convert-graphemes-to-pixels target-screen
260
261
262 {
263
264 var tmp/eax: int <- copy xmin
265 tmp <- shift-left 3/log2-font-width
266 var left: int
267 copy-to left, tmp
268 tmp <- copy ymin
269 tmp <- shift-left 4/log2-font-height
270 var top: int
271 copy-to top, tmp
272 var pixels-ah/eax: (addr handle array byte) <- get target-screen, pixels
273 var _pixels/eax: (addr array byte) <- lookup *pixels-ah
274 var pixels/edi: (addr array byte) <- copy _pixels
275 compare pixels, 0
276 break-if-=
277 var y/ebx: int <- copy 0
278 var height-addr/edx: (addr int) <- get target-screen, height
279 var height/edx: int <- copy *height-addr
280 height <- shift-left 4/log2-font-height
281 {
282 compare y, height
283 break-if->=
284 var width-addr/edx: (addr int) <- get target-screen, width
285 var width/edx: int <- copy *width-addr
286 width <- shift-left 3/log2-font-width
287 var x/eax: int <- copy 0
288 {
289 compare x, width
290 break-if->=
291 {
292 var idx/ecx: int <- pixel-index target-screen, x, y
293 var color-addr/ecx: (addr byte) <- index pixels, idx
294 var color/ecx: byte <- copy-byte *color-addr
295 var color2/ecx: int <- copy color
296 var x2/eax: int <- copy x
297 x2 <- add left
298 var y2/ebx: int <- copy y
299 y2 <- add top
300 pixel screen, x2, y2, color2
301 }
302 x <- increment
303 loop
304 }
305 y <- increment
306 loop
307 }
308 }
309 }
310
311 fn has-keyboard? _self: (addr sandbox) -> _/eax: boolean {
312 var self/esi: (addr sandbox) <- copy _self
313 var keyboard-obj-cell-ah/eax: (addr handle cell) <- get self, keyboard-var
314 var keyboard-obj-cell/eax: (addr cell) <- lookup *keyboard-obj-cell-ah
315 compare keyboard-obj-cell, 0
316 {
317 break-if-!=
318 return 0/false
319 }
320 var keyboard-obj-cell-type/ecx: (addr int) <- get keyboard-obj-cell, type
321 compare *keyboard-obj-cell-type, 6/keyboard
322 {
323 break-if-=
324 return 0/false
325 }
326 var keyboard-obj-ah/eax: (addr handle gap-buffer) <- get keyboard-obj-cell, keyboard-data
327 var _keyboard-obj/eax: (addr gap-buffer) <- lookup *keyboard-obj-ah
328 var keyboard-obj/edx: (addr gap-buffer) <- copy _keyboard-obj
329 compare keyboard-obj, 0
330 {
331 break-if-!=
332 return 0/false
333 }
334 return 1/true
335 }
336
337 fn maybe-render-keyboard screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: int -> _/ecx: int {
338 var self/esi: (addr sandbox) <- copy _self
339 var keyboard-obj-cell-ah/eax: (addr handle cell) <- get self, keyboard-var
340 var keyboard-obj-cell/eax: (addr cell) <- lookup *keyboard-obj-cell-ah
341 compare keyboard-obj-cell, 0
342 {
343 break-if-!=
344 return ymin
345 }
346 var keyboard-obj-cell-type/ecx: (addr int) <- get keyboard-obj-cell, type
347 compare *keyboard-obj-cell-type, 6/keyboard
348 {
349 break-if-=
350 return ymin
351 }
352 var keyboard-obj-ah/eax: (addr handle gap-buffer) <- get keyboard-obj-cell, keyboard-data
353 var _keyboard-obj/eax: (addr gap-buffer) <- lookup *keyboard-obj-ah
354 var keyboard-obj/edx: (addr gap-buffer) <- copy _keyboard-obj
355 var y/ecx: int <- copy ymin
356 y <- increment
357 var x/eax: int <- draw-text-rightward screen, "keyboard: ", xmin, 0x99/xmax, y, 0x17/fg, 0xc5/bg=blue-bg
358 var cursor-in-keyboard?/esi: (addr boolean) <- get self, cursor-in-keyboard?
359 y <- render-keyboard screen, keyboard-obj, x, y, *cursor-in-keyboard?
360 y <- increment
361 return y
362 }
363
364 fn render-keyboard screen: (addr screen), _keyboard: (addr gap-buffer), xmin: int, ymin: int, render-cursor?: boolean -> _/ecx: int {
365 var keyboard/esi: (addr gap-buffer) <- copy _keyboard
366 var width/edx: int <- copy 0x10/keyboard-capacity
367 var y/edi: int <- copy ymin
368
369 var x/eax: int <- copy xmin
370 var xmax/ecx: int <- copy x
371 xmax <- add 0x10
372 var ymax/edx: int <- copy ymin
373 ymax <- add 1
374 clear-rect screen, x, y, xmax, ymax, 0/bg
375 x <- render-gap-buffer screen, keyboard, x, y, render-cursor?, 3/fg, 0/bg
376 y <- increment
377 return y
378 }
379
380 fn print-screen-cell-of-fake-screen screen: (addr screen), _target: (addr screen), x: int, y: int {
381 var target/ecx: (addr screen) <- copy _target
382 var data-ah/eax: (addr handle array screen-cell) <- get target, data
383 var data/eax: (addr array screen-cell) <- lookup *data-ah
384 var index/ecx: int <- screen-cell-index target, x, y
385 var offset/ecx: (offset screen-cell) <- compute-offset data, index
386 var src-cell/esi: (addr screen-cell) <- index data, offset
387 var src-grapheme/eax: (addr grapheme) <- get src-cell, data
388 var src-color/ecx: (addr int) <- get src-cell, color
389 var src-background-color/edx: (addr int) <- get src-cell, background-color
390 draw-grapheme-at-cursor screen, *src-grapheme, *src-color, *src-background-color
391 }
392
393 fn render-sandbox-edit-menu screen: (addr screen), _self: (addr sandbox) {
394 var _width/eax: int <- copy 0
395 var height/ecx: int <- copy 0
396 _width, height <- screen-size screen
397 var width/edx: int <- copy _width
398 var y/ecx: int <- copy height
399 y <- decrement
400 var height/ebx: int <- copy y
401 height <- increment
402 clear-rect screen, 0/x, y, width, height, 0xc5/bg=blue-bg
403 set-cursor-position screen, 0/x, y
404 draw-text-rightward-from-cursor screen, " ^r ", width, 0/fg, 0x5c/bg=menu-highlight
405 draw-text-rightward-from-cursor screen, " run main ", width, 7/fg, 0xc5/bg=blue-bg
406 draw-text-rightward-from-cursor screen, " ^s ", width, 0/fg, 0x5c/bg=menu-highlight
407 draw-text-rightward-from-cursor screen, " run sandbox ", width, 7/fg, 0xc5/bg=blue-bg
408 draw-text-rightward-from-cursor screen, " ^g ", width, 0/fg, 0x5c/bg=menu-highlight
409 draw-text-rightward-from-cursor screen, " go to ", width, 7/fg, 0xc5/bg=blue-bg
410 $render-sandbox-edit-menu:render-ctrl-m: {
411 var self/eax: (addr sandbox) <- copy _self
412 var has-trace?/eax: boolean <- has-trace? self
413 compare has-trace?, 0/false
414 {
415 break-if-=
416 draw-text-rightward-from-cursor screen, " ^m ", width, 0/fg, 0x38/bg=trace
417 draw-text-rightward-from-cursor screen, " to trace ", width, 7/fg, 0xc5/bg=blue-bg
418 break $render-sandbox-edit-menu:render-ctrl-m
419 }
420 draw-text-rightward-from-cursor screen, " ^m ", width, 0/fg, 3/bg=keyboard
421 draw-text-rightward-from-cursor screen, " to keyboard ", width, 7/fg, 0xc5/bg=blue-bg
422 }
423 draw-text-rightward-from-cursor screen, " ^a ", width, 0/fg, 0x5c/bg=menu-highlight
424 draw-text-rightward-from-cursor screen, " << ", width, 7/fg, 0xc5/bg=blue-bg
425 draw-text-rightward-from-cursor screen, " ^b ", width, 0/fg, 0x5c/bg=menu-highlight
426 draw-text-rightward-from-cursor screen, " <word ", width, 7/fg, 0xc5/bg=blue-bg
427 draw-text-rightward-from-cursor screen, " ^f ", width, 0/fg, 0x5c/bg=menu-highlight
428 draw-text-rightward-from-cursor screen, " word> ", width, 7/fg, 0xc5/bg=blue-bg
429 draw-text-rightward-from-cursor screen, " ^e ", width, 0/fg, 0x5c/bg=menu-highlight
430 draw-text-rightward-from-cursor screen, " >> ", width, 7/fg, 0xc5/bg=blue-bg
431 }
432
433 fn render-keyboard-menu screen: (addr screen) {
434 var width/eax: int <- copy 0
435 var height/ecx: int <- copy 0
436 width, height <- screen-size screen
437 var y/ecx: int <- copy height
438 y <- decrement
439 var height/edx: int <- copy y
440 height <- increment
441 clear-rect screen, 0/x, y, width, height, 0xc5/bg=blue-bg
442 set-cursor-position screen, 0/x, y
443 draw-text-rightward-from-cursor screen, " ^r ", width, 0/fg, 0x5c/bg=menu-highlight
444 draw-text-rightward-from-cursor screen, " run main ", width, 7/fg, 0xc5/bg=blue-bg
445 draw-text-rightward-from-cursor screen, " ^s ", width, 0/fg, 0x5c/bg=menu-highlight
446 draw-text-rightward-from-cursor screen, " run sandbox ", width, 7/fg, 0xc5/bg=blue-bg
447 draw-text-rightward-from-cursor screen, " ^g ", width, 0/fg, 0x5c/bg=menu-highlight
448 draw-text-rightward-from-cursor screen, " go to ", width, 7/fg, 0xc5/bg=blue-bg
449 draw-text-rightward-from-cursor screen, " ^m ", width, 0/fg, 7/bg
450 draw-text-rightward-from-cursor screen, " to sandbox ", width, 7/fg, 0xc5/bg=blue-bg
451 }
452
453 fn edit-sandbox _self: (addr sandbox), key: grapheme, globals: (addr global-table), data-disk: (addr disk) {
454 var self/esi: (addr sandbox) <- copy _self
455
456 {
457 compare key, 0x13/ctrl-s
458 break-if-!=
459
460 var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
461 compare *cursor-in-trace?, 0/false
462 break-if-!=
463
464
465 store-state data-disk, self, globals
466
467 run-sandbox self, globals
468 return
469 }
470
471 {
472 compare key, 0xd/ctrl-m
473 break-if-!=
474
475 {
476 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
477 compare *cursor-in-data?, 0/false
478 break-if-=
479 var has-trace?/eax: boolean <- has-trace? self
480 compare has-trace?, 0/false
481 {
482 break-if-=
483 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
484 copy-to *cursor-in-data?, 0/false
485 var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
486 copy-to *cursor-in-trace?, 1/false
487 return
488 }
489 var has-keyboard?/eax: boolean <- has-keyboard? self
490 compare has-keyboard?, 0/false
491 {
492 break-if-=
493 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
494 copy-to *cursor-in-data?, 0/false
495 var cursor-in-keyboard?/eax: (addr boolean) <- get self, cursor-in-keyboard?
496 copy-to *cursor-in-keyboard?, 1/false
497 return
498 }
499 return
500 }
501
502 {
503 var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
504 compare *cursor-in-trace?, 0/false
505 break-if-=
506 copy-to *cursor-in-trace?, 0/false
507 var cursor-target/ecx: (addr boolean) <- get self, cursor-in-keyboard?
508 var has-keyboard?/eax: boolean <- has-keyboard? self
509 compare has-keyboard?, 0/false
510 {
511 break-if-!=
512 cursor-target <- get self, cursor-in-data?
513 }
514 copy-to *cursor-target, 1/true
515 return
516 }
517
518 {
519 var cursor-in-keyboard?/eax: (addr boolean) <- get self, cursor-in-keyboard?
520 compare *cursor-in-keyboard?, 0/false
521 break-if-=
522 copy-to *cursor-in-keyboard?, 0/false
523 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
524 copy-to *cursor-in-data?, 1/true
525 return
526 }
527 return
528 }
529
530 {
531 var cursor-in-data?/eax: (addr boolean) <- get self, cursor-in-data?
532 compare *cursor-in-data?, 0/false
533 break-if-=
534 var data-ah/eax: (addr handle gap-buffer) <- get self, data
535 var data/eax: (addr gap-buffer) <- lookup *data-ah
536 edit-gap-buffer data, key
537 return
538 }
539
540 {
541 var cursor-in-keyboard?/eax: (addr boolean) <- get self, cursor-in-keyboard?
542 compare *cursor-in-keyboard?, 0/false
543 break-if-=
544 var inner-keyboard-var-ah/eax: (addr handle cell) <- get self, keyboard-var
545 var inner-keyboard-var/eax: (addr cell) <- lookup *inner-keyboard-var-ah
546 compare inner-keyboard-var, 0
547 {
548 break-if-!=
549 return
550 }
551 var inner-keyboard-var-type/ecx: (addr int) <- get inner-keyboard-var, type
552 compare *inner-keyboard-var-type, 6/keyboard
553 {
554 break-if-=
555 return
556 }
557 var keyboard-ah/eax: (addr handle gap-buffer) <- get inner-keyboard-var, keyboard-data
558 var keyboard/eax: (addr gap-buffer) <- lookup *keyboard-ah
559 edit-gap-buffer keyboard, key
560 return
561 }
562
563 {
564 var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
565 compare *cursor-in-trace?, 0/false
566 break-if-=
567 var trace-ah/eax: (addr handle trace) <- get self, trace
568 var trace/eax: (addr trace) <- lookup *trace-ah
569
570 {
571 compare key, 0xa/newline
572 break-if-!=
573 {
574 var need-rerun?/eax: boolean <- cursor-too-deep? trace
575 compare need-rerun?, 0/false
576 }
577 break-if-=
578
579
580 var save: trace-index-stash
581 var save-addr/ecx: (addr trace-index-stash) <- address save
582 save-indices trace, save-addr
583
584 var max-depth-addr/ecx: (addr int) <- get trace, max-depth
585 increment *max-depth-addr
586 run-sandbox self, globals
587
588 recompute-all-visible-lines trace
589 var save-addr/ecx: (addr trace-index-stash) <- address save
590 restore-indices trace, save-addr
591 }
592 edit-trace trace, key
593 return
594 }
595 }
596
597 fn run-sandbox _self: (addr sandbox), globals: (addr global-table) {
598 var self/esi: (addr sandbox) <- copy _self
599 var data-ah/ecx: (addr handle gap-buffer) <- get self, data
600 var eval-result-h: (handle cell)
601 var eval-result-ah/edi: (addr handle cell) <- address eval-result-h
602 var definitions-created-storage: (stream int 0x10)
603 var definitions-created/edx: (addr stream int) <- address definitions-created-storage
604 var trace-ah/eax: (addr handle trace) <- get self, trace
605 var _trace/eax: (addr trace) <- lookup *trace-ah
606 var trace/ebx: (addr trace) <- copy _trace
607 clear-trace trace
608 var tmp/eax: (addr handle cell) <- get self, screen-var
609 var inner-screen-var: (addr handle cell)
610 copy-to inner-screen-var, tmp
611 clear-screen-var inner-screen-var
612 var inner-keyboard-var/eax: (addr handle cell) <- get self, keyboard-var
613 rewind-keyboard-var inner-keyboard-var
614
615 read-and-evaluate-and-save-gap-buffer-to-globals data-ah, eval-result-ah, globals, definitions-created, trace, inner-screen-var, inner-keyboard-var
616
617 {
618 compare globals, 0
619 break-if-=
620 rewind-stream definitions-created
621 var no-definitions?/eax: boolean <- stream-empty? definitions-created
622 compare no-definitions?, 0/false
623 break-if-!=
624
625 var data/eax: (addr gap-buffer) <- lookup *data-ah
626 var capacity/edx: int <- gap-buffer-capacity data
627 allocate data-ah
628 var new-data/eax: (addr gap-buffer) <- lookup *data-ah
629 initialize-gap-buffer new-data, capacity
630 }
631
632 var value-ah/eax: (addr handle stream byte) <- get self, value
633 var value/eax: (addr stream byte) <- lookup *value-ah
634 clear-stream value
635 print-cell eval-result-ah, value, trace
636 }
637
638 fn test-run-integer {
639 var sandbox-storage: sandbox
640 var sandbox/esi: (addr sandbox) <- address sandbox-storage
641 initialize-sandbox-with sandbox, "1"
642
643 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
644
645 var screen-on-stack: screen
646 var screen/edi: (addr screen) <- address screen-on-stack
647 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
648
649 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
650
651 check-screen-row screen, 1/y, " 1 ", "F - test-run-integer/0"
652 check-screen-row screen, 2/y, " ... ", "F - test-run-integer/1"
653 check-screen-row screen, 3/y, " => 1 ", "F - test-run-integer/2"
654 }
655
656 fn test-run-negative-integer {
657 var sandbox-storage: sandbox
658 var sandbox/esi: (addr sandbox) <- address sandbox-storage
659 initialize-sandbox-with sandbox, "-1"
660
661 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
662
663 var screen-on-stack: screen
664 var screen/edi: (addr screen) <- address screen-on-stack
665 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
666
667 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
668
669 check-screen-row screen, 1/y, " -1 ", "F - test-run-negative-integer/0"
670 check-screen-row screen, 2/y, " ... ", "F - test-run-negative-integer/1"
671 check-screen-row screen, 3/y, " => -1 ", "F - test-run-negative-integer/2"
672 }
673
674 fn test-run-error-invalid-integer {
675 var sandbox-storage: sandbox
676 var sandbox/esi: (addr sandbox) <- address sandbox-storage
677 initialize-sandbox-with sandbox, "1a"
678
679 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
680
681 var screen-on-stack: screen
682 var screen/edi: (addr screen) <- address screen-on-stack
683 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
684
685 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
686
687 check-screen-row screen, 1/y, " 1a ", "F - test-run-error-invalid-integer/0"
688 check-screen-row screen, 2/y, " ... ", "F - test-run-error-invalid-integer/1"
689 check-screen-row-in-color screen, 0xc/fg=error, 3/y, " unbound symbol: 1a ", "F - test-run-error-invalid-integer/2"
690 }
691
692 fn test-run-error-unknown-symbol {
693 var sandbox-storage: sandbox
694 var sandbox/esi: (addr sandbox) <- address sandbox-storage
695 initialize-sandbox-with sandbox, "a"
696
697 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
698
699 var screen-on-stack: screen
700 var screen/edi: (addr screen) <- address screen-on-stack
701 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
702
703 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
704
705 check-screen-row screen, 1/y, " a ", "F - test-run-error-unknown-symbol/0"
706 check-screen-row screen, 2/y, " ... ", "F - test-run-error-unknown-symbol/1"
707 check-screen-row-in-color screen, 0xc/fg=error, 3/y, " unbound symbol: a ", "F - test-run-error-unknown-symbol/2"
708 }
709
710 fn test-run-with-spaces {
711 var sandbox-storage: sandbox
712 var sandbox/esi: (addr sandbox) <- address sandbox-storage
713 initialize-sandbox-with sandbox, " 1 \n"
714
715 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
716
717 var screen-on-stack: screen
718 var screen/edi: (addr screen) <- address screen-on-stack
719 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
720
721 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
722
723 check-screen-row screen, 1/y, " 1 ", "F - test-run-with-spaces/0"
724 check-screen-row screen, 2/y, " ", "F - test-run-with-spaces/1"
725 check-screen-row screen, 3/y, " ... ", "F - test-run-with-spaces/2"
726 check-screen-row screen, 4/y, " => 1 ", "F - test-run-with-spaces/3"
727 }
728
729 fn test-run-quote {
730 var sandbox-storage: sandbox
731 var sandbox/esi: (addr sandbox) <- address sandbox-storage
732 initialize-sandbox-with sandbox, "'a"
733
734 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
735
736 var screen-on-stack: screen
737 var screen/edi: (addr screen) <- address screen-on-stack
738 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
739
740 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
741
742 check-screen-row screen, 1/y, " 'a ", "F - test-run-quote/0"
743 check-screen-row screen, 2/y, " ... ", "F - test-run-quote/1"
744 check-screen-row screen, 3/y, " => a ", "F - test-run-quote/2"
745 }
746
747 fn test-run-dotted-list {
748 var sandbox-storage: sandbox
749 var sandbox/esi: (addr sandbox) <- address sandbox-storage
750 initialize-sandbox-with sandbox, "'(a . b)"
751
752 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
753
754 var screen-on-stack: screen
755 var screen/edi: (addr screen) <- address screen-on-stack
756 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
757
758 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
759
760 check-screen-row screen, 1/y, " '(a . b) ", "F - test-run-dotted-list/0"
761 check-screen-row screen, 2/y, " ... ", "F - test-run-dotted-list/1"
762 check-screen-row screen, 3/y, " => (a . b) ", "F - test-run-dotted-list/2"
763 }
764
765 fn test-run-dot-and-list {
766 var sandbox-storage: sandbox
767 var sandbox/esi: (addr sandbox) <- address sandbox-storage
768 initialize-sandbox-with sandbox, "'(a . (b))"
769
770 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
771
772 var screen-on-stack: screen
773 var screen/edi: (addr screen) <- address screen-on-stack
774 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
775
776 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
777
778 check-screen-row screen, 1/y, " '(a . (b)) ", "F - test-run-dot-and-list/0"
779 check-screen-row screen, 2/y, " ... ", "F - test-run-dot-and-list/1"
780 check-screen-row screen, 3/y, " => (a b) ", "F - test-run-dot-and-list/2"
781 }
782
783 fn test-run-final-dot {
784 var sandbox-storage: sandbox
785 var sandbox/esi: (addr sandbox) <- address sandbox-storage
786 initialize-sandbox-with sandbox, "'(a .)"
787
788 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
789
790 var screen-on-stack: screen
791 var screen/edi: (addr screen) <- address screen-on-stack
792 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
793
794 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
795
796 check-screen-row screen, 1/y, " '(a .) ", "F - test-run-final-dot/0"
797 check-screen-row screen, 2/y, " ... ", "F - test-run-final-dot/1"
798 check-screen-row screen, 3/y, " '. )' makes no sense ", "F - test-run-final-dot/2"
799
800 }
801
802 fn test-run-double-dot {
803 var sandbox-storage: sandbox
804 var sandbox/esi: (addr sandbox) <- address sandbox-storage
805 initialize-sandbox-with sandbox, "'(a . .)"
806
807 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
808
809 var screen-on-stack: screen
810 var screen/edi: (addr screen) <- address screen-on-stack
811 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
812
813 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
814
815 check-screen-row screen, 1/y, " '(a . .) ", "F - test-run-double-dot/0"
816 check-screen-row screen, 2/y, " ... ", "F - test-run-double-dot/1"
817 check-screen-row screen, 3/y, " '. .' makes no sense ", "F - test-run-double-dot/2"
818
819 }
820
821 fn test-run-multiple-expressions-after-dot {
822 var sandbox-storage: sandbox
823 var sandbox/esi: (addr sandbox) <- address sandbox-storage
824 initialize-sandbox-with sandbox, "'(a . b c)"
825
826 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
827
828 var screen-on-stack: screen
829 var screen/edi: (addr screen) <- address screen-on-stack
830 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
831
832 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
833
834 check-screen-row screen, 1/y, " '(a . b c) ", "F - test-run-multiple-expressions-after-dot/0"
835 check-screen-row screen, 2/y, " ... ", "F - test-run-multiple-expressions-after-dot/1"
836 check-screen-row screen, 3/y, " cannot have multiple expressions between '.' and ')' ", "F - test-run-multiple-expressions-after-dot/2"
837
838 }
839
840 fn test-run-stream {
841 var sandbox-storage: sandbox
842 var sandbox/esi: (addr sandbox) <- address sandbox-storage
843 initialize-sandbox-with sandbox, "[a b]"
844
845 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
846
847 var screen-on-stack: screen
848 var screen/edi: (addr screen) <- address screen-on-stack
849 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
850
851 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
852
853 check-screen-row screen, 1/y, " [a b] ", "F - test-run-stream/0"
854 check-screen-row screen, 2/y, " ... ", "F - test-run-stream/1"
855 check-screen-row screen, 3/y, " => [a b] ", "F - test-run-stream/2"
856 }
857
858 fn test-run-move-cursor-into-trace {
859 var sandbox-storage: sandbox
860 var sandbox/esi: (addr sandbox) <- address sandbox-storage
861 initialize-sandbox-with sandbox, "12"
862
863 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
864
865 var screen-on-stack: screen
866 var screen/edi: (addr screen) <- address screen-on-stack
867 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
868
869 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
870
871 check-screen-row screen, 1/y, " 12 ", "F - test-run-move-cursor-into-trace/pre-0"
872 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " | ", "F - test-run-move-cursor-into-trace/pre-0/cursor"
873 check-screen-row screen, 2/y, " ... ", "F - test-run-move-cursor-into-trace/pre-1"
874 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/pre-1/cursor"
875 check-screen-row screen, 3/y, " => 12 ", "F - test-run-move-cursor-into-trace/pre-2"
876 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-move-cursor-into-trace/pre-2/cursor"
877
878 edit-sandbox sandbox, 0xd/ctrl-m, 0/no-globals, 0/no-disk
879
880 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
881
882 check-screen-row screen, 1/y, " 12 ", "F - test-run-move-cursor-into-trace/trace-0"
883 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-move-cursor-into-trace/trace-0/cursor"
884 check-screen-row screen, 2/y, " ... ", "F - test-run-move-cursor-into-trace/trace-1"
885 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ||| ", "F - test-run-move-cursor-into-trace/trace-1/cursor"
886 check-screen-row screen, 3/y, " => 12 ", "F - test-run-move-cursor-into-trace/trace-2"
887 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-move-cursor-into-trace/trace-2/cursor"
888
889 edit-sandbox sandbox, 0xd/ctrl-m, 0/no-globals, 0/no-disk
890
891 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
892
893 check-screen-row screen, 1/y, " 12 ", "F - test-run-move-cursor-into-trace/input-0"
894 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " | ", "F - test-run-move-cursor-into-trace/input-0/cursor"
895 check-screen-row screen, 2/y, " ... ", "F - test-run-move-cursor-into-trace/input-1"
896 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/input-1/cursor"
897 check-screen-row screen, 3/y, " => 12 ", "F - test-run-move-cursor-into-trace/input-2"
898 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-move-cursor-into-trace/input-2/cursor"
899 }
900
901 fn has-trace? _self: (addr sandbox) -> _/eax: boolean {
902 var self/esi: (addr sandbox) <- copy _self
903 var trace-ah/eax: (addr handle trace) <- get self, trace
904 var _trace/eax: (addr trace) <- lookup *trace-ah
905 var trace/edx: (addr trace) <- copy _trace
906 compare trace, 0
907 {
908 break-if-!=
909 abort "null trace"
910 }
911 var first-free/ebx: (addr int) <- get trace, first-free
912 compare *first-free, 0
913 {
914 break-if->
915 return 0/false
916 }
917 return 1/true
918 }
919
920 fn test-run-expand-trace {
921 var sandbox-storage: sandbox
922 var sandbox/esi: (addr sandbox) <- address sandbox-storage
923 initialize-sandbox-with sandbox, "12"
924
925 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
926
927 var screen-on-stack: screen
928 var screen/edi: (addr screen) <- address screen-on-stack
929 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
930
931 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
932
933 check-screen-row screen, 1/y, " 12 ", "F - test-run-expand-trace/pre0-0"
934 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " | ", "F - test-run-expand-trace/pre0-0/cursor"
935 check-screen-row screen, 2/y, " ... ", "F - test-run-expand-trace/pre0-1"
936 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-expand-trace/pre0-1/cursor"
937 check-screen-row screen, 3/y, " => 12 ", "F - test-run-expand-trace/pre0-2"
938 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-expand-trace/pre0-2/cursor"
939
940 edit-sandbox sandbox, 0xd/ctrl-m, 0/no-globals, 0/no-disk
941
942 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
943
944 check-screen-row screen, 1/y, " 12 ", "F - test-run-expand-trace/pre1-0"
945 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-expand-trace/pre1-0/cursor"
946 check-screen-row screen, 2/y, " ... ", "F - test-run-expand-trace/pre1-1"
947 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ||| ", "F - test-run-expand-trace/pre1-1/cursor"
948 check-screen-row screen, 3/y, " => 12 ", "F - test-run-expand-trace/pre1-2"
949 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-expand-trace/pre1-2/cursor"
950
951 edit-sandbox sandbox, 0xa/newline, 0/no-globals, 0/no-disk
952
953 clear-screen screen
954 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
955
956 check-screen-row screen, 1/y, " 12 ", "F - test-run-expand-trace/expand-0"
957 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-expand-trace/expand-0/cursor"
958 check-screen-row screen, 2/y, " 1 toke", "F - test-run-expand-trace/expand-1"
959 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ||||||", "F - test-run-expand-trace/expand-1/cursor"
960 check-screen-row screen, 3/y, " ... ", "F - test-run-expand-trace/expand-2"
961 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-expand-trace/expand-2/cursor"
962 check-screen-row screen, 4/y, " 1 inse", "F - test-run-expand-trace/expand-3"
963 check-background-color-in-screen-row screen, 7/bg=cursor, 4/y, " ", "F - test-run-expand-trace/expand-3/cursor"
964 }
965
966 fn test-run-can-rerun-when-expanding-trace {
967 var sandbox-storage: sandbox
968 var sandbox/esi: (addr sandbox) <- address sandbox-storage
969
970 initialize-sandbox-with sandbox, "12"
971
972 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
973
974 var screen-on-stack: screen
975 var screen/edi: (addr screen) <- address screen-on-stack
976 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
977
978 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
979
980 check-screen-row screen, 1/y, " 12 ", "F - test-run-can-rerun-when-expanding-trace/pre0-0"
981 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " | ", "F - test-run-can-rerun-when-expanding-trace/pre0-0/cursor"
982 check-screen-row screen, 2/y, " ... ", "F - test-run-can-rerun-when-expanding-trace/pre0-1"
983 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre0-1/cursor"
984 check-screen-row screen, 3/y, " => 12 ", "F - test-run-can-rerun-when-expanding-trace/pre0-2"
985 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre0-2/cursor"
986
987 edit-sandbox sandbox, 0xd/ctrl-m, 0/no-globals, 0/no-disk
988
989 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
990
991 check-screen-row screen, 1/y, " 12 ", "F - test-run-can-rerun-when-expanding-trace/pre1-0"
992 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre1-0/cursor"
993 check-screen-row screen, 2/y, " ... ", "F - test-run-can-rerun-when-expanding-trace/pre1-1"
994 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ||| ", "F - test-run-can-rerun-when-expanding-trace/pre1-1/cursor"
995 check-screen-row screen, 3/y, " => 12 ", "F - test-run-can-rerun-when-expanding-trace/pre1-2"
996 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre1-2/cursor"
997
998 edit-sandbox sandbox, 0xa/newline, 0/no-globals, 0/no-disk
999
1000 clear-screen screen
1001 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1002
1003 check-screen-row screen, 1/y, " 12 ", "F - test-run-can-rerun-when-expanding-trace/pre2-0"
1004 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre2-0/cursor"
1005 check-screen-row screen, 2/y, " 1 toke", "F - test-run-can-rerun-when-expanding-trace/pre2-1"
1006 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ||||||", "F - test-run-can-rerun-when-expanding-trace/pre2-1/cursor"
1007 check-screen-row screen, 3/y, " ... ", "F - test-run-can-rerun-when-expanding-trace/pre2-2"
1008 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre2-2/cursor"
1009 check-screen-row screen, 4/y, " 1 inse", "F - test-run-can-rerun-when-expanding-trace/pre2-2"
1010 check-background-color-in-screen-row screen, 7/bg=cursor, 4/y, " ", "F - test-run-can-rerun-when-expanding-trace/pre2-2/cursor"
1011
1012 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1013 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1014 edit-sandbox sandbox, 0xa/newline, 0/no-globals, 0/no-disk
1015
1016 clear-screen screen
1017 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1018
1019 check-screen-row screen, 1/y, " 12 ", "F - test-run-can-rerun-when-expanding-trace/expand-0"
1020 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-can-rerun-when-expanding-trace/expand-0/cursor"
1021 check-screen-row screen, 2/y, " 1 toke", "F - test-run-can-rerun-when-expanding-trace/expand-1"
1022 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-can-rerun-when-expanding-trace/expand-1/cursor"
1023 check-screen-row screen, 3/y, " 2 next", "F - test-run-can-rerun-when-expanding-trace/expand-2"
1024 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ||||||", "F - test-run-can-rerun-when-expanding-trace/expand-2/cursor"
1025 check-screen-row screen, 4/y, " ... ", "F - test-run-can-rerun-when-expanding-trace/expand-3"
1026 check-background-color-in-screen-row screen, 7/bg=cursor, 4/y, " ", "F - test-run-can-rerun-when-expanding-trace/expand-3/cursor"
1027 check-screen-row screen, 5/y, " 2 next", "F - test-run-can-rerun-when-expanding-trace/expand-4"
1028 check-background-color-in-screen-row screen, 7/bg=cursor, 5/y, " ", "F - test-run-can-rerun-when-expanding-trace/expand-4/cursor"
1029 check-screen-row screen, 6/y, " ... ", "F - test-run-can-rerun-when-expanding-trace/expand-5"
1030 check-background-color-in-screen-row screen, 7/bg=cursor, 6/y, " ", "F - test-run-can-rerun-when-expanding-trace/expand-5/cursor"
1031 check-screen-row screen, 7/y, " 2 => 1", "F - test-run-can-rerun-when-expanding-trace/expand-6"
1032 check-background-color-in-screen-row screen, 7/bg=cursor, 7/y, " ", "F - test-run-can-rerun-when-expanding-trace/expand-6/cursor"
1033 }
1034
1035 fn test-run-preserves-trace-view-on-rerun {
1036 var sandbox-storage: sandbox
1037 var sandbox/esi: (addr sandbox) <- address sandbox-storage
1038
1039 initialize-sandbox-with sandbox, "7"
1040
1041 edit-sandbox sandbox, 0x13/ctrl-s, 0/no-globals, 0/no-disk
1042
1043 var screen-on-stack: screen
1044 var screen/edi: (addr screen) <- address screen-on-stack
1045 initialize-screen screen, 0x80/width, 0x10/height, 0/no-pixel-graphics
1046
1047 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1048
1049 check-screen-row screen, 1/y, " 7 ", "F - test-run-preserves-trace-view-on-rerun/pre0-0"
1050 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " | ", "F - test-run-preserves-trace-view-on-rerun/pre0-0/cursor"
1051 check-screen-row screen, 2/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre0-1"
1052 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre0-1/cursor"
1053 check-screen-row screen, 3/y, " => 7 ", "F - test-run-preserves-trace-view-on-rerun/pre0-2"
1054 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre0-2/cursor"
1055
1056 edit-sandbox sandbox, 0xd/ctrl-m, 0/no-globals, 0/no-disk
1057 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1058
1059 check-screen-row screen, 1/y, " 7 ", "F - test-run-preserves-trace-view-on-rerun/pre1-0"
1060 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre1-0/cursor"
1061 check-screen-row screen, 2/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre1-1"
1062 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ||| ", "F - test-run-preserves-trace-view-on-rerun/pre1-1/cursor"
1063 check-screen-row screen, 3/y, " => 7 ", "F - test-run-preserves-trace-view-on-rerun/pre1-2"
1064 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre1-2/cursor"
1065
1066 edit-sandbox sandbox, 0xa/newline, 0/no-globals, 0/no-disk
1067 clear-screen screen
1068 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1069
1070 check-screen-row screen, 1/y, " 7 ", "F - test-run-preserves-trace-view-on-rerun/pre2-0"
1071 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-0/cursor"
1072 check-screen-row screen, 2/y, " 1 tokenize ", "F - test-run-preserves-trace-view-on-rerun/pre2-1"
1073 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " |||||||||| ", "F - test-run-preserves-trace-view-on-rerun/pre2-1/cursor"
1074 check-screen-row screen, 3/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre2-2"
1075 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-2/cursor"
1076 check-screen-row screen, 4/y, " 1 insert parens ", "F - test-run-preserves-trace-view-on-rerun/pre2-3"
1077 check-background-color-in-screen-row screen, 7/bg=cursor, 4/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-3/cursor"
1078 check-screen-row screen, 5/y, " 1 parse ", "F - test-run-preserves-trace-view-on-rerun/pre2-4"
1079 check-background-color-in-screen-row screen, 7/bg=cursor, 5/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-4/cursor"
1080 check-screen-row screen, 6/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre2-5"
1081 check-background-color-in-screen-row screen, 7/bg=cursor, 6/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-5/cursor"
1082 check-screen-row screen, 7/y, " 1 transform infix ", "F - test-run-preserves-trace-view-on-rerun/pre2-6"
1083 check-background-color-in-screen-row screen, 7/bg=cursor, 7/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-6/cursor"
1084 check-screen-row screen, 8/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre2-7"
1085 check-background-color-in-screen-row screen, 7/bg=cursor, 8/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-7/cursor"
1086 check-screen-row screen, 9/y, " 1 macroexpand 7 ", "F - test-run-preserves-trace-view-on-rerun/pre2-8"
1087 check-background-color-in-screen-row screen, 7/bg=cursor, 9/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-8/cursor"
1088 check-screen-row screen, 0xa/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre2-9"
1089 check-background-color-in-screen-row screen, 7/bg=cursor, 0xa/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-9/cursor"
1090 check-screen-row screen, 0xb/y, " 1 => 7 ", "F - test-run-preserves-trace-view-on-rerun/pre2-10"
1091 check-background-color-in-screen-row screen, 7/bg=cursor, 0xb/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre2-10/cursor"
1092
1093 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1094 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1095 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1096 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1097 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1098 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1099 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1100 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1101 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1102 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1103 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1104 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1105 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1106 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1107 edit-sandbox sandbox, 0x6a/j, 0/no-globals, 0/no-disk
1108 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1109
1110 check-screen-row screen, 1/y, " 7 ", "F - test-run-preserves-trace-view-on-rerun/pre3-0"
1111 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-0/cursor"
1112 check-screen-row screen, 2/y, " 1 tokenize ", "F - test-run-preserves-trace-view-on-rerun/pre3-1"
1113 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-1/cursor"
1114 check-screen-row screen, 3/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre3-2"
1115 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-2/cursor"
1116 check-screen-row screen, 4/y, " 1 insert parens ", "F - test-run-preserves-trace-view-on-rerun/pre3-3"
1117 check-background-color-in-screen-row screen, 7/bg=cursor, 4/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-3/cursor"
1118 check-screen-row screen, 5/y, " 1 parse ", "F - test-run-preserves-trace-view-on-rerun/pre3-4"
1119 check-background-color-in-screen-row screen, 7/bg=cursor, 5/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-4/cursor"
1120 check-screen-row screen, 6/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre3-5"
1121 check-background-color-in-screen-row screen, 7/bg=cursor, 6/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-5/cursor"
1122 check-screen-row screen, 7/y, " 1 transform infix ", "F - test-run-preserves-trace-view-on-rerun/pre3-6"
1123 check-background-color-in-screen-row screen, 7/bg=cursor, 7/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-6/cursor"
1124 check-screen-row screen, 8/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre3-7"
1125 check-background-color-in-screen-row screen, 7/bg=cursor, 8/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-7/cursor"
1126 check-screen-row screen, 9/y, " 1 macroexpand 7 ", "F - test-run-preserves-trace-view-on-rerun/pre3-8"
1127 check-background-color-in-screen-row screen, 7/bg=cursor, 9/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-8/cursor"
1128 check-screen-row screen, 0xa/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/pre3-9"
1129 check-background-color-in-screen-row screen, 7/bg=cursor, 0xa/y, " ||| ", "F - test-run-preserves-trace-view-on-rerun/pre3-9/cursor"
1130 check-screen-row screen, 0xb/y, " 1 => 7 ", "F - test-run-preserves-trace-view-on-rerun/pre3-10"
1131 check-background-color-in-screen-row screen, 7/bg=cursor, 0xb/y, " ", "F - test-run-preserves-trace-view-on-rerun/pre3-10/cursor"
1132
1133 edit-sandbox sandbox, 0xa/newline, 0/no-globals, 0/no-disk
1134 clear-screen screen
1135 render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height, 1/show-cursor
1136
1137 check-screen-row screen, 1/y, " 7 ", "F - test-run-preserves-trace-view-on-rerun/expand-0"
1138 check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-0/cursor"
1139 check-screen-row screen, 2/y, " 1 tokenize ", "F - test-run-preserves-trace-view-on-rerun/expand-1"
1140 check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-1/cursor"
1141 check-screen-row screen, 3/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/expand-2"
1142 check-background-color-in-screen-row screen, 7/bg=cursor, 3/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-2/cursor"
1143 check-screen-row screen, 4/y, " 1 insert parens ", "F - test-run-preserves-trace-view-on-rerun/expand-3"
1144 check-background-color-in-screen-row screen, 7/bg=cursor, 4/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-3/cursor"
1145 check-screen-row screen, 5/y, " 1 parse ", "F - test-run-preserves-trace-view-on-rerun/expand-4"
1146 check-background-color-in-screen-row screen, 7/bg=cursor, 5/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-4/cursor"
1147 check-screen-row screen, 6/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/expand-5"
1148 check-background-color-in-screen-row screen, 7/bg=cursor, 6/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-5/cursor"
1149 check-screen-row screen, 7/y, " 1 transform infix ", "F - test-run-preserves-trace-view-on-rerun/expand-6"
1150 check-background-color-in-screen-row screen, 7/bg=cursor, 7/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-6/cursor"
1151 check-screen-row screen, 8/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/expand-7"
1152 check-background-color-in-screen-row screen, 7/bg=cursor, 8/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-7/cursor"
1153 check-screen-row screen, 9/y, " 1 macroexpand 7 ", "F - test-run-preserves-trace-view-on-rerun/expand-8"
1154 check-background-color-in-screen-row screen, 7/bg=cursor, 9/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-8/cursor"
1155 check-screen-row screen, 0xa/y, " 2 macroexpand-iter 7 ", "F - test-run-preserves-trace-view-on-rerun/expand-9"
1156 check-background-color-in-screen-row screen, 7/bg=cursor, 0xa/y, " |||||||||||||||||||| ", "F - test-run-preserves-trace-view-on-rerun/expand-9/cursor"
1157 check-screen-row screen, 0xb/y, " ... ", "F - test-run-preserves-trace-view-on-rerun/expand-10"
1158 check-background-color-in-screen-row screen, 7/bg=cursor, 0xb/y, " ", "F - test-run-preserves-trace-view-on-rerun/expand-10/cursor"
1159 }