diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-06-09 21:28:45 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-06-09 21:28:45 -0700 |
commit | a2d4e415836867967eb2b179eb825149d13aa245 (patch) | |
tree | b394c0df6be624166b58fd68be926ea8572560cb | |
parent | 117229ae1708aa0e3aaab16bad34d4b6759d3fb0 (diff) | |
download | mu-a2d4e415836867967eb2b179eb825149d13aa245.tar.gz |
.
-rw-r--r-- | shell/global.mu | 21 | ||||
-rw-r--r-- | shell/sandbox.mu | 13 |
2 files changed, 19 insertions, 15 deletions
diff --git a/shell/global.mu b/shell/global.mu index 78caebfa..8506f4f6 100644 --- a/shell/global.mu +++ b/shell/global.mu @@ -517,9 +517,9 @@ fn mutate-binding-in-globals name: (addr stream byte), val: (addr handle cell), } # Accepts an input s-expression, naively checks if it is a definition, and if -# so saves the gap-buffer to the appropriate global, spinning up a new empty -# one to replace it with. -fn maybe-stash-gap-buffer-to-global _globals: (addr global-table), _expr-ah: (addr handle cell), gap: (addr handle gap-buffer) { +# so saves the gap-buffer to the appropriate global. +# Return true if stashed. +fn maybe-stash-gap-buffer-to-global _globals: (addr global-table), _expr-ah: (addr handle cell), gap: (addr handle gap-buffer) -> _/eax: boolean { # if 'expr' is not a pair, return var expr-ah/eax: (addr handle cell) <- copy _expr-ah var _expr/eax: (addr cell) <- lookup *expr-ah @@ -528,14 +528,14 @@ fn maybe-stash-gap-buffer-to-global _globals: (addr global-table), _expr-ah: (ad compare *expr-type, 0/pair { break-if-= - return + return 0/false } # if expr is not a definition, return { var is-definition?/eax: boolean <- is-definition? expr compare is-definition?, 0/false break-if-!= - return + return 0/false } # locate the global for definition->right->left var right-ah/eax: (addr handle cell) <- get expr, right @@ -548,7 +548,7 @@ fn maybe-stash-gap-buffer-to-global _globals: (addr global-table), _expr-ah: (ad { compare index, -1/not-found break-if-!= - return + return 0/false } # stash 'gap' to it var globals/eax: (addr global-table) <- copy _globals @@ -556,7 +556,6 @@ fn maybe-stash-gap-buffer-to-global _globals: (addr global-table), _expr-ah: (ad { break-if-!= abort "stash to globals" - return } var global-data-ah/eax: (addr handle array global) <- get globals, data var global-data/eax: (addr array global) <- lookup *global-data-ah @@ -564,13 +563,7 @@ fn maybe-stash-gap-buffer-to-global _globals: (addr global-table), _expr-ah: (ad var dest-global/eax: (addr global) <- index global-data, offset var dest-ah/eax: (addr handle gap-buffer) <- get dest-global, input copy-object gap, dest-ah - # initialize a new gap-buffer in 'gap' - var dest/eax: (addr gap-buffer) <- lookup *dest-ah - var capacity/ecx: int <- gap-buffer-capacity dest - var gap2/eax: (addr handle gap-buffer) <- copy gap - allocate gap2 - var gap-addr/eax: (addr gap-buffer) <- lookup *gap2 - initialize-gap-buffer gap-addr, capacity + return 1/true } fn is-definition? _expr: (addr cell) -> _/eax: boolean { diff --git a/shell/sandbox.mu b/shell/sandbox.mu index 2b184ebc..5cc75a0f 100644 --- a/shell/sandbox.mu +++ b/shell/sandbox.mu @@ -674,7 +674,18 @@ fn run _in-ah: (addr handle gap-buffer), out: (addr stream byte), globals: (addr # if there was no error and the read-result starts with "set" or "def", save # the gap buffer in the modified global, then create a new one for the next # command. - maybe-stash-gap-buffer-to-global globals, read-result-ah, _in-ah + var stashed?/eax: boolean <- maybe-stash-gap-buffer-to-global globals, read-result-ah, _in-ah + # if necessary, initialize a new gap-buffer in 'gap' + { + compare stashed?, 0/false + break-if-= + var in-ah/edi: (addr handle gap-buffer) <- copy _in-ah + var in/eax: (addr gap-buffer) <- lookup *in-ah + var capacity/ecx: int <- gap-buffer-capacity in + allocate in-ah + var new-gap/eax: (addr gap-buffer) <- lookup *in-ah + initialize-gap-buffer new-gap, capacity + } } fn read-evaluate-and-move-to-globals _in-ah: (addr handle gap-buffer), globals: (addr global-table), definition-name: (addr stream byte) { |