From 8b8d0fc77130c6f39aae42319aee1f449fd4db70 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 21 Feb 2021 21:25:38 -0800 Subject: 7772 --- baremetal/shell/eval.mu | 19 ------------------- baremetal/shell/main.mu | 20 ++++++++++++++++++++ baremetal/shell/sandbox.mu | 10 +++++++++- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/baremetal/shell/eval.mu b/baremetal/shell/eval.mu index 8af64a95..e69de29b 100644 --- a/baremetal/shell/eval.mu +++ b/baremetal/shell/eval.mu @@ -1,19 +0,0 @@ -type interpreter { - # tokenize - # insert parens - # transform infix - # token tree - # syntax tree -} - -fn evaluate _self: (addr interpreter), in: (addr stream byte), out: (addr stream byte) { - clear-stream out - { - var done?/eax: boolean <- stream-empty? in - compare done?, 0/false - break-if-!= - var g/eax: grapheme <- read-grapheme in - write-grapheme out, g - loop - } -} diff --git a/baremetal/shell/main.mu b/baremetal/shell/main.mu index f3f6240c..e54515ed 100644 --- a/baremetal/shell/main.mu +++ b/baremetal/shell/main.mu @@ -20,3 +20,23 @@ fn main { loop } } + +type interpreter { + # tokenize + # insert parens + # transform infix + # token tree + # syntax tree +} + +fn run _self: (addr interpreter), in: (addr stream byte), out: (addr stream byte) { + clear-stream out + { + var done?/eax: boolean <- stream-empty? in + compare done?, 0/false + break-if-!= + var g/eax: grapheme <- read-grapheme in + write-grapheme out, g + loop + } +} diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu index d1a24c47..b002ce0a 100644 --- a/baremetal/shell/sandbox.mu +++ b/baremetal/shell/sandbox.mu @@ -68,6 +68,14 @@ fn edit-sandbox _self: (addr sandbox), key: byte, interpreter: (addr interpreter delete-grapheme-before-cursor self return } + { + 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 + } { compare g, 0x13/ctrl-s break-if-!= @@ -79,7 +87,7 @@ fn edit-sandbox _self: (addr sandbox), key: byte, interpreter: (addr interpreter emit-gap-buffer data, buffer var value-ah/eax: (addr handle stream byte) <- get self, value var value/eax: (addr stream byte) <- lookup *value-ah - evaluate interpreter, buffer, value + run interpreter, buffer, value return } add-grapheme-to-sandbox self, g -- cgit 1.4.1-2-gfad0