diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-04-05 23:09:05 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-04-05 23:09:05 -0700 |
commit | 07bc1eeb90e1ff4e0c9931f4ad568fdd466b4298 (patch) | |
tree | 469489a0bb5b0721746698e511756e8c1799fd21 /shell | |
parent | 4861c39474965eeb69b34b63a99e09c812c5fefc (diff) | |
download | mu-07bc1eeb90e1ff4e0c9931f4ad568fdd466b4298.tar.gz |
shell: save repl input to disk before running
Diffstat (limited to 'shell')
-rw-r--r-- | shell/main.mu | 4 | ||||
-rw-r--r-- | shell/sandbox.mu | 51 |
2 files changed, 31 insertions, 24 deletions
diff --git a/shell/main.mu b/shell/main.mu index 1fafa42c..b6ceff95 100644 --- a/shell/main.mu +++ b/shell/main.mu @@ -16,7 +16,7 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) compare key, 0 loop-if-= # no way to quit right now; just reboot - edit-sandbox sandbox, key + edit-sandbox sandbox, key, screen, keyboard, data-disk } loop } @@ -36,7 +36,7 @@ fn load-sandbox data-disk: (addr disk), _self: (addr sandbox) { var key/eax: byte <- read-byte s compare key, 0/null break-if-= - edit-sandbox self, key + edit-sandbox self, key, 0/no-screen, 0/no-keyboard, 0/no-disk loop } } diff --git a/shell/sandbox.mu b/shell/sandbox.mu index e419063e..dec1cc94 100644 --- a/shell/sandbox.mu +++ b/shell/sandbox.mu @@ -100,25 +100,35 @@ fn render-sandbox-menu screen: (addr screen) { draw-text-rightward-from-cursor screen, " move to trace ", width, 7/fg, 0/bg } -fn edit-sandbox _self: (addr sandbox), key: byte { +fn edit-sandbox _self: (addr sandbox), key: byte, real-screen: (addr screen), real-keyboard: (addr keyboard), data-disk: (addr disk) { var self/esi: (addr sandbox) <- copy _self var g/edx: grapheme <- copy key - # running code + # ctrl-r { compare g, 0x12/ctrl-r break-if-!= - # ctrl-r: run function outside sandbox + # run function outside sandbox # required: fn (addr screen), (addr keyboard) # Mu will pass in the real screen and keyboard. return } + # ctrl-s { compare g, 0x13/ctrl-s break-if-!= - # ctrl-s: run sandbox(es) + # save to disk var data-ah/eax: (addr handle gap-buffer) <- get self, data var _data/eax: (addr gap-buffer) <- lookup *data-ah var data/ecx: (addr gap-buffer) <- copy _data + { + compare data-disk, 0/no-disk + break-if-= + var stream-storage: (stream byte 0x200) + var stream/esi: (addr stream byte) <- address stream-storage + emit-gap-buffer data, stream + store-sector data-disk, 0/lba, stream + } + # run sandbox var value-ah/eax: (addr handle stream byte) <- get self, value var _value/eax: (addr stream byte) <- lookup *value-ah var value/edx: (addr stream byte) <- copy _value @@ -126,9 +136,6 @@ fn edit-sandbox _self: (addr sandbox), key: byte { var trace/eax: (addr trace) <- lookup *trace-ah clear-trace trace run data, value, trace - # testing write to disk -#? rewind-stream value -#? store-first-sector-to-primary-bus-secondary-drive value return } # tab @@ -195,9 +202,9 @@ fn test-run-integer { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type "1" - edit-sandbox sandbox, 0x31/1 + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -214,12 +221,12 @@ fn test-run-with-spaces { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type input with whitespace before and after - edit-sandbox sandbox, 0x20/space - edit-sandbox sandbox, 0x31/1 - edit-sandbox sandbox, 0x20/space - edit-sandbox sandbox, 0xa/newline + edit-sandbox sandbox, 0x20/space, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x20/space, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0xa/newline, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -237,10 +244,10 @@ fn test-run-error-invalid-integer { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type "1a" - edit-sandbox sandbox, 0x31/1 - edit-sandbox sandbox, 0x61/a + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x61/a, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -257,10 +264,10 @@ fn test-run-move-cursor-into-trace { var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox # type "12" - edit-sandbox sandbox, 0x31/1 - edit-sandbox sandbox, 0x32/2 + edit-sandbox sandbox, 0x31/1, 0/no-screen, 0/no-keyboard, 0/no-disk + edit-sandbox sandbox, 0x32/2, 0/no-screen, 0/no-keyboard, 0/no-disk # eval - edit-sandbox sandbox, 0x13/ctrl-s + edit-sandbox sandbox, 0x13/ctrl-s, 0/no-screen, 0/no-keyboard, 0/no-disk # setup: screen var screen-on-stack: screen var screen/edi: (addr screen) <- address screen-on-stack @@ -274,7 +281,7 @@ fn test-run-move-cursor-into-trace { 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" # move cursor into trace - edit-sandbox sandbox, 9/tab + edit-sandbox sandbox, 9/tab, 0/no-screen, 0/no-keyboard, 0/no-disk # 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" @@ -284,7 +291,7 @@ fn test-run-move-cursor-into-trace { check-screen-row screen, 2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/trace-2" 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 + edit-sandbox sandbox, 9/tab, 0/no-screen, 0/no-keyboard, 0/no-disk # 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" |