2021-02-21 06:37:44 +00:00
|
|
|
type sandbox {
|
|
|
|
data: (handle gap-buffer)
|
2021-02-21 20:20:31 +00:00
|
|
|
value: (handle stream byte)
|
2021-02-23 03:46:23 +00:00
|
|
|
trace: (handle trace)
|
2021-02-23 06:02:28 +00:00
|
|
|
cursor-in-trace?: boolean
|
2021-02-21 06:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn initialize-sandbox _self: (addr sandbox) {
|
|
|
|
var self/esi: (addr sandbox) <- copy _self
|
|
|
|
var data-ah/eax: (addr handle gap-buffer) <- get self, data
|
|
|
|
allocate data-ah
|
|
|
|
var data/eax: (addr gap-buffer) <- lookup *data-ah
|
|
|
|
initialize-gap-buffer data, 0x1000/4KB
|
2021-02-21 20:20:31 +00:00
|
|
|
var value-ah/eax: (addr handle stream byte) <- get self, value
|
|
|
|
populate-stream value-ah, 0x1000/4KB
|
2021-02-23 04:23:43 +00:00
|
|
|
var trace-ah/eax: (addr handle trace) <- get self, trace
|
|
|
|
allocate trace-ah
|
|
|
|
var trace/eax: (addr trace) <- lookup *trace-ah
|
2021-02-27 05:29:39 +00:00
|
|
|
initialize-trace trace, 0x1000/lines, 0x80/visible-lines
|
2021-02-21 06:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
## some helpers for tests
|
|
|
|
|
|
|
|
fn initialize-sandbox-with _self: (addr sandbox), s: (addr array byte) {
|
|
|
|
var self/esi: (addr sandbox) <- copy _self
|
|
|
|
var data-ah/eax: (addr handle gap-buffer) <- get self, data
|
|
|
|
allocate data-ah
|
|
|
|
var data/eax: (addr gap-buffer) <- lookup *data-ah
|
|
|
|
initialize-gap-buffer-with data, s
|
|
|
|
}
|
|
|
|
|
|
|
|
fn allocate-sandbox-with _out: (addr handle sandbox), s: (addr array byte) {
|
|
|
|
var out/eax: (addr handle sandbox) <- copy _out
|
|
|
|
allocate out
|
|
|
|
var out-addr/eax: (addr sandbox) <- lookup *out
|
|
|
|
initialize-sandbox-with out-addr, s
|
|
|
|
}
|
|
|
|
|
2021-02-23 07:25:52 +00:00
|
|
|
##
|
2021-02-21 06:45:10 +00:00
|
|
|
|
2021-02-23 07:59:35 +00:00
|
|
|
fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin: int, xmax: int, ymax: int {
|
2021-02-21 06:45:10 +00:00
|
|
|
clear-screen screen
|
2021-02-21 06:37:44 +00:00
|
|
|
var self/esi: (addr sandbox) <- copy _self
|
2021-02-23 04:23:43 +00:00
|
|
|
# data
|
2021-02-21 06:37:44 +00:00
|
|
|
var data-ah/eax: (addr handle gap-buffer) <- get self, data
|
2021-02-21 22:32:46 +00:00
|
|
|
var _data/eax: (addr gap-buffer) <- lookup *data-ah
|
|
|
|
var data/edx: (addr gap-buffer) <- copy _data
|
2021-02-23 07:59:35 +00:00
|
|
|
var x/eax: int <- copy xmin
|
|
|
|
var y/ecx: int <- copy ymin
|
2021-02-23 06:02:28 +00:00
|
|
|
var cursor-in-sandbox?/ebx: boolean <- copy 0/false
|
|
|
|
{
|
|
|
|
var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
|
|
|
|
compare *cursor-in-trace?, 0/false
|
|
|
|
break-if-!=
|
|
|
|
cursor-in-sandbox? <- copy 1/true
|
|
|
|
}
|
2021-02-23 07:59:35 +00:00
|
|
|
x, y <- render-gap-buffer-wrapping-right-then-down screen, data, x, y, xmax, ymax, cursor-in-sandbox?
|
2021-02-21 22:32:46 +00:00
|
|
|
y <- increment
|
2021-02-23 04:23:43 +00:00
|
|
|
# trace
|
|
|
|
var trace-ah/eax: (addr handle trace) <- get self, trace
|
|
|
|
var _trace/eax: (addr trace) <- lookup *trace-ah
|
|
|
|
var trace/edx: (addr trace) <- copy _trace
|
2021-02-23 06:02:28 +00:00
|
|
|
var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
|
2021-02-23 07:59:35 +00:00
|
|
|
y <- render-trace screen, trace, xmin, y, xmax, ymax, *cursor-in-trace?
|
2021-02-23 04:23:43 +00:00
|
|
|
# value
|
2021-02-23 07:59:35 +00:00
|
|
|
$render-sandbox:value: {
|
|
|
|
var value-ah/eax: (addr handle stream byte) <- get self, value
|
|
|
|
var _value/eax: (addr stream byte) <- lookup *value-ah
|
|
|
|
var value/esi: (addr stream byte) <- copy _value
|
2021-02-23 16:58:43 +00:00
|
|
|
rewind-stream value
|
2021-02-23 07:59:35 +00:00
|
|
|
var done?/eax: boolean <- stream-empty? value
|
|
|
|
compare done?, 0/false
|
|
|
|
break-if-!=
|
|
|
|
var x/eax: int <- copy 0
|
|
|
|
x, y <- draw-text-wrapping-right-then-down screen, "=> ", xmin, y, xmax, ymax, xmin, y, 7/fg, 0/bg
|
|
|
|
var x2/edx: int <- copy x
|
|
|
|
var dummy/eax: int <- draw-stream-rightward screen, value, x2, xmax, y, 7/fg=grey, 0/bg
|
|
|
|
}
|
|
|
|
# render menu
|
|
|
|
var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
|
|
|
|
compare *cursor-in-trace?, 0/false
|
2021-02-23 05:25:30 +00:00
|
|
|
{
|
|
|
|
break-if-=
|
2021-02-23 07:59:35 +00:00
|
|
|
render-trace-menu screen
|
2021-02-23 05:25:30 +00:00
|
|
|
return
|
|
|
|
}
|
2021-02-23 07:59:35 +00:00
|
|
|
render-sandbox-menu screen
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render-sandbox-menu screen: (addr screen) {
|
|
|
|
var width/eax: int <- copy 0
|
|
|
|
var height/ecx: int <- copy 0
|
|
|
|
width, height <- screen-size screen
|
|
|
|
var y/ecx: int <- copy height
|
|
|
|
y <- decrement
|
|
|
|
set-cursor-position screen, 0/x, y
|
|
|
|
draw-text-rightward-from-cursor screen, " ctrl-s ", width, 0/fg, 7/bg=grey
|
|
|
|
draw-text-rightward-from-cursor screen, " run sandbox ", width, 7/fg, 0/bg
|
|
|
|
draw-text-rightward-from-cursor screen, " ctrl-d ", width, 0/fg, 7/bg=grey
|
|
|
|
draw-text-rightward-from-cursor screen, " cursor down ", width, 7/fg, 0/bg
|
|
|
|
draw-text-rightward-from-cursor screen, " ctrl-u ", width, 0/fg, 7/bg=grey
|
|
|
|
draw-text-rightward-from-cursor screen, " cursor up ", width, 7/fg, 0/bg
|
|
|
|
draw-text-rightward-from-cursor screen, " tab ", width, 0/fg, 9/bg=blue
|
|
|
|
draw-text-rightward-from-cursor screen, " move to trace ", width, 7/fg, 0/bg
|
|
|
|
}
|
|
|
|
|
2021-02-22 05:27:42 +00:00
|
|
|
fn edit-sandbox _self: (addr sandbox), key: byte {
|
2021-02-21 20:20:31 +00:00
|
|
|
var self/esi: (addr sandbox) <- copy _self
|
2021-02-21 06:37:44 +00:00
|
|
|
var g/edx: grapheme <- copy key
|
2021-02-23 06:02:28 +00:00
|
|
|
# running code
|
2021-02-22 05:25:38 +00:00
|
|
|
{
|
|
|
|
compare g, 0x12/ctrl-r
|
|
|
|
break-if-!=
|
|
|
|
# ctrl-r: run function outside sandbox
|
|
|
|
# required: fn (addr screen), (addr keyboard)
|
|
|
|
# Mu will pass in the real screen and keyboard.
|
|
|
|
return
|
|
|
|
}
|
2021-02-21 20:20:31 +00:00
|
|
|
{
|
|
|
|
compare g, 0x13/ctrl-s
|
|
|
|
break-if-!=
|
|
|
|
# ctrl-s: run sandbox(es)
|
2021-02-22 05:21:36 +00:00
|
|
|
var data-ah/eax: (addr handle gap-buffer) <- get self, data
|
2021-02-22 05:30:57 +00:00
|
|
|
var _data/eax: (addr gap-buffer) <- lookup *data-ah
|
|
|
|
var data/ecx: (addr gap-buffer) <- copy _data
|
2021-02-21 20:20:31 +00:00
|
|
|
var value-ah/eax: (addr handle stream byte) <- get self, value
|
2021-02-23 03:46:23 +00:00
|
|
|
var _value/eax: (addr stream byte) <- lookup *value-ah
|
|
|
|
var value/edx: (addr stream byte) <- copy _value
|
|
|
|
var trace-ah/eax: (addr handle trace) <- get self, trace
|
|
|
|
var trace/eax: (addr trace) <- lookup *trace-ah
|
2021-02-23 04:23:43 +00:00
|
|
|
clear-trace trace
|
2021-02-23 03:46:23 +00:00
|
|
|
run data, value, trace
|
2021-02-21 20:20:31 +00:00
|
|
|
return
|
|
|
|
}
|
2021-02-23 16:58:43 +00:00
|
|
|
# tab
|
2021-02-23 07:25:52 +00:00
|
|
|
var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
|
2021-02-23 06:02:28 +00:00
|
|
|
{
|
2021-02-23 07:59:35 +00:00
|
|
|
compare g, 9/tab
|
2021-02-23 06:02:28 +00:00
|
|
|
break-if-!=
|
2021-02-23 07:59:35 +00:00
|
|
|
# if cursor in input, switch to trace
|
2021-02-23 06:02:28 +00:00
|
|
|
{
|
|
|
|
compare *cursor-in-trace?, 0/false
|
|
|
|
break-if-!=
|
|
|
|
copy-to *cursor-in-trace?, 1/true
|
|
|
|
return
|
|
|
|
}
|
2021-02-23 07:59:35 +00:00
|
|
|
# if cursor in trace, switch to input
|
|
|
|
copy-to *cursor-in-trace?, 0/false
|
|
|
|
return
|
2021-02-23 07:25:52 +00:00
|
|
|
}
|
|
|
|
# if cursor in trace, send cursor to trace
|
|
|
|
{
|
|
|
|
compare *cursor-in-trace?, 0/false
|
|
|
|
break-if-=
|
|
|
|
var trace-ah/eax: (addr handle trace) <- get self, trace
|
|
|
|
var trace/eax: (addr trace) <- lookup *trace-ah
|
|
|
|
edit-trace trace, g
|
2021-02-23 06:02:28 +00:00
|
|
|
return
|
|
|
|
}
|
2021-02-23 07:25:52 +00:00
|
|
|
# otherwise send cursor to input
|
|
|
|
var data-ah/eax: (addr handle gap-buffer) <- get self, data
|
|
|
|
var data/eax: (addr gap-buffer) <- lookup *data-ah
|
|
|
|
edit-gap-buffer data, g
|
|
|
|
return
|
2021-02-21 06:37:44 +00:00
|
|
|
}
|
2021-02-22 05:36:33 +00:00
|
|
|
|
2021-02-23 03:46:23 +00:00
|
|
|
fn run in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
|
2021-02-22 06:06:03 +00:00
|
|
|
var read-result-storage: (handle cell)
|
|
|
|
var read-result/esi: (addr handle cell) <- address read-result-storage
|
2021-02-23 03:46:23 +00:00
|
|
|
read-cell in, read-result, trace
|
|
|
|
var error?/eax: boolean <- has-errors? trace
|
|
|
|
{
|
|
|
|
compare error?, 0/false
|
|
|
|
break-if-=
|
|
|
|
return
|
|
|
|
}
|
2021-03-05 07:08:44 +00:00
|
|
|
var nil-storage: (handle cell)
|
2021-03-05 14:19:21 +00:00
|
|
|
var nil-ah/eax: (addr handle cell) <- address nil-storage
|
2021-03-05 07:08:44 +00:00
|
|
|
allocate-pair nil-ah
|
2021-03-05 05:24:48 +00:00
|
|
|
var eval-result-storage: (handle cell)
|
|
|
|
var eval-result/edi: (addr handle cell) <- address eval-result-storage
|
2021-03-07 07:27:14 +00:00
|
|
|
evaluate read-result, eval-result, *nil-ah, trace
|
2021-03-05 05:24:48 +00:00
|
|
|
var error?/eax: boolean <- has-errors? trace
|
|
|
|
{
|
|
|
|
compare error?, 0/false
|
|
|
|
break-if-=
|
|
|
|
return
|
|
|
|
}
|
2021-03-02 07:25:22 +00:00
|
|
|
clear-stream out
|
2021-03-05 05:24:48 +00:00
|
|
|
print-cell eval-result, out, trace
|
2021-02-25 06:37:13 +00:00
|
|
|
mark-lines-dirty trace
|
2021-02-22 05:36:33 +00:00
|
|
|
}
|
2021-02-23 06:02:28 +00:00
|
|
|
|
|
|
|
fn test-run-integer {
|
|
|
|
var sandbox-storage: sandbox
|
|
|
|
var sandbox/esi: (addr sandbox) <- address sandbox-storage
|
|
|
|
initialize-sandbox sandbox
|
|
|
|
# type "1"
|
|
|
|
edit-sandbox sandbox, 0x31/1
|
|
|
|
# eval
|
|
|
|
edit-sandbox sandbox, 0x13/ctrl-s
|
|
|
|
# setup: screen
|
|
|
|
var screen-on-stack: screen
|
|
|
|
var screen/edi: (addr screen) <- address screen-on-stack
|
2021-02-23 07:59:35 +00:00
|
|
|
initialize-screen screen, 0x80/width, 0x10/height
|
2021-02-23 06:02:28 +00:00
|
|
|
#
|
2021-02-23 07:59:35 +00:00
|
|
|
render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
|
2021-02-23 06:02:28 +00:00
|
|
|
check-screen-row screen, 0/y, "1 ", "F - test-run-integer/0"
|
2021-02-23 06:35:08 +00:00
|
|
|
check-screen-row screen, 1/y, "... ", "F - test-run-integer/1"
|
|
|
|
check-screen-row screen, 2/y, "=> 1 ", "F - test-run-integer/2"
|
2021-02-23 06:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test-run-error-invalid-integer {
|
|
|
|
var sandbox-storage: sandbox
|
|
|
|
var sandbox/esi: (addr sandbox) <- address sandbox-storage
|
|
|
|
initialize-sandbox sandbox
|
|
|
|
# type "1a"
|
|
|
|
edit-sandbox sandbox, 0x31/1
|
|
|
|
edit-sandbox sandbox, 0x61/a
|
|
|
|
# eval
|
|
|
|
edit-sandbox sandbox, 0x13/ctrl-s
|
|
|
|
# setup: screen
|
|
|
|
var screen-on-stack: screen
|
|
|
|
var screen/edi: (addr screen) <- address screen-on-stack
|
2021-02-23 07:59:35 +00:00
|
|
|
initialize-screen screen, 0x80/width, 0x10/height
|
2021-02-23 06:02:28 +00:00
|
|
|
#
|
2021-02-23 07:59:35 +00:00
|
|
|
render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
|
2021-02-23 06:02:28 +00:00
|
|
|
check-screen-row screen, 0/y, "1a ", "F - test-run-error-invalid-integer/0"
|
2021-02-23 06:35:08 +00:00
|
|
|
check-screen-row screen, 1/y, "... ", "F - test-run-error-invalid-integer/0"
|
|
|
|
check-screen-row screen, 2/y, "invalid number ", "F - test-run-error-invalid-integer/2"
|
2021-02-23 06:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test-run-move-cursor-into-trace {
|
|
|
|
var sandbox-storage: sandbox
|
|
|
|
var sandbox/esi: (addr sandbox) <- address sandbox-storage
|
|
|
|
initialize-sandbox sandbox
|
2021-02-23 06:35:08 +00:00
|
|
|
# type "12"
|
2021-02-23 06:02:28 +00:00
|
|
|
edit-sandbox sandbox, 0x31/1
|
2021-02-23 06:35:08 +00:00
|
|
|
edit-sandbox sandbox, 0x32/2
|
2021-02-23 06:02:28 +00:00
|
|
|
# eval
|
|
|
|
edit-sandbox sandbox, 0x13/ctrl-s
|
|
|
|
# setup: screen
|
|
|
|
var screen-on-stack: screen
|
|
|
|
var screen/edi: (addr screen) <- address screen-on-stack
|
2021-02-23 07:59:35 +00:00
|
|
|
initialize-screen screen, 0x80/width, 0x10/height
|
2021-02-23 06:02:28 +00:00
|
|
|
#
|
2021-02-23 07:59:35 +00:00
|
|
|
render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
|
2021-02-23 06:35:08 +00:00
|
|
|
check-screen-row screen, 0/y, "12 ", "F - test-run-move-cursor-into-trace/pre-0"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, " | ", "F - test-run-move-cursor-into-trace/pre-0/cursor"
|
|
|
|
check-screen-row screen, 1/y, "... ", "F - test-run-move-cursor-into-trace/pre-1"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-move-cursor-into-trace/pre-1/cursor"
|
|
|
|
check-screen-row screen, 2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/pre-2"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/pre-2/cursor"
|
2021-02-23 07:59:35 +00:00
|
|
|
# move cursor into trace
|
|
|
|
edit-sandbox sandbox, 9/tab
|
|
|
|
#
|
|
|
|
render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
|
|
|
|
check-screen-row screen, 0/y, "12 ", "F - test-run-move-cursor-into-trace/trace-0"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, " ", "F - test-run-move-cursor-into-trace/trace-0/cursor"
|
|
|
|
check-screen-row screen, 1/y, "... ", "F - test-run-move-cursor-into-trace/trace-1"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, "||| ", "F - test-run-move-cursor-into-trace/trace-1/cursor"
|
2021-02-23 16:58:43 +00:00
|
|
|
check-screen-row screen, 2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/trace-2"
|
2021-02-23 07:59:35 +00:00
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/trace-2/cursor"
|
|
|
|
# move cursor into input
|
|
|
|
edit-sandbox sandbox, 9/tab
|
2021-02-23 06:02:28 +00:00
|
|
|
#
|
2021-02-23 07:59:35 +00:00
|
|
|
render-sandbox screen, sandbox, 0/x, 0/y, 0x80/width, 0x10/height
|
|
|
|
check-screen-row screen, 0/y, "12 ", "F - test-run-move-cursor-into-trace/input-0"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, " | ", "F - test-run-move-cursor-into-trace/input-0/cursor"
|
|
|
|
check-screen-row screen, 1/y, "... ", "F - test-run-move-cursor-into-trace/input-1"
|
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, " ", "F - test-run-move-cursor-into-trace/input-1/cursor"
|
2021-02-23 16:58:43 +00:00
|
|
|
check-screen-row screen, 2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/input-2"
|
2021-02-23 07:59:35 +00:00
|
|
|
check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, " ", "F - test-run-move-cursor-into-trace/input-2/cursor"
|
2021-02-23 06:02:28 +00:00
|
|
|
}
|