From 0cdbfff25664d2bd3257220ca1509e7bfbd84c75 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 19 Oct 2020 23:53:45 -0700 Subject: [PATCH] 7079 --- apps/tile/environment.mu | 36 +++++++++++++++++++++++++++++++++++- apps/tile/gap-buffer.mu | 18 ++++++++++++++++++ apps/tile/grapheme-stack.mu | 17 +++++++++++++++++ apps/tile/word.mu | 26 ++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 664cd102..4bfc4cdc 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -637,10 +637,44 @@ $process-sandbox-define:body: { # aren't defined in the rest of 'functions'. Append them in order. # Assumes function body is a single line for now. fn copy-unbound-words-to-args _functions: (addr handle function) { + # target + var target-ah/eax: (addr handle function) <- copy _functions + var _target/eax: (addr function) <- lookup *target-ah + var target/esi: (addr function) <- copy _target + var dest/edi: (addr handle word) <- get target, args + # next + var functions-ah/eax: (addr handle function) <- get target, next + var _functions/eax: (addr function) <- lookup *functions-ah + var functions/ecx: (addr function) <- copy _functions + # src + var line-ah/eax: (addr handle line) <- get target, body + var line/eax: (addr line) <- lookup *line-ah + var curr-ah/eax: (addr handle word) <- get line, data + var curr/eax: (addr word) <- lookup *curr-ah + { + compare curr, 0 + break-if-= + # HERE + var next-ah/ecx: (addr handle word) <- get curr, next + curr <- lookup *next-ah + loop + } } # construct a call to `f` with copies of exactly its args -fn construct-call f: (addr handle function), out: (addr handle word) { +fn construct-call _f-ah: (addr handle function), out: (addr handle word) { + var f-ah/eax: (addr handle function) <- copy _f-ah + var _f/eax: (addr function) <- lookup *f-ah + var f/esi: (addr function) <- copy _f + var name-ah/eax: (addr handle array byte) <- get f, name + var name/eax: (addr array byte) <- lookup *name-ah + var dest/edi: (addr handle word) <- copy out + allocate-word-with dest, name + var tmp/eax: (addr word) <- lookup *dest + dest <- get tmp, next + var _args-ah/eax: (addr handle word) <- get f, args + var args-ah/esi: (addr handle word) <- copy _args-ah + copy-words args-ah, dest } fn word-index _words: (addr handle word), _n: int, out: (addr handle word) { diff --git a/apps/tile/gap-buffer.mu b/apps/tile/gap-buffer.mu index 47417b96..a6d6a85e 100644 --- a/apps/tile/gap-buffer.mu +++ b/apps/tile/gap-buffer.mu @@ -288,3 +288,21 @@ fn test-gap-buffer-equal-from-start? { var result/eax: int <- copy _result check-ints-equal result, 1, "F - test-gap-buffer-equal-from-start?" } + +fn copy-gap-buffer _src-ah: (addr handle gap-buffer), _dest-ah: (addr handle gap-buffer) { + # obtain src-a, dest-a + var src-ah/eax: (addr handle gap-buffer) <- copy _src-ah + var _src-a/eax: (addr gap-buffer) <- lookup *src-ah + var src-a/esi: (addr gap-buffer) <- copy _src-a + var dest-ah/eax: (addr handle gap-buffer) <- copy _dest-ah + var _dest-a/eax: (addr gap-buffer) <- lookup *dest-ah + var dest-a/edi: (addr gap-buffer) <- copy _dest-a + # copy left grapheme-stack + var src/ecx: (addr grapheme-stack) <- get src-a, left + var dest/edx: (addr grapheme-stack) <- get dest-a, left + copy-grapheme-stack src, dest + # copy right grapheme-stack + src <- get src-a, right + dest <- get dest-a, right + copy-grapheme-stack src, dest +} diff --git a/apps/tile/grapheme-stack.mu b/apps/tile/grapheme-stack.mu index 401dda2d..3b8d95f9 100644 --- a/apps/tile/grapheme-stack.mu +++ b/apps/tile/grapheme-stack.mu @@ -62,6 +62,23 @@ $pop-grapheme-stack:body: { } } +fn copy-grapheme-stack _src: (addr grapheme-stack), dest: (addr grapheme-stack) { + var src/esi: (addr grapheme-stack) <- copy _src + var data-ah/edi: (addr handle array grapheme) <- get src, data + var _data/eax: (addr array grapheme) <- lookup *data-ah + var data/edi: (addr array grapheme) <- copy _data + var top-addr/ecx: (addr int) <- get src, top + var i/eax: int <- copy 0 + { + compare i, *top-addr + break-if->= + var g/edx: (addr grapheme) <- index data, i + push-grapheme-stack dest, *g + i <- increment + loop + } +} + # dump stack to screen from bottom to top # don't move the cursor or anything fn render-stack-from-bottom _self: (addr grapheme-stack), screen: (addr screen) { diff --git a/apps/tile/word.mu b/apps/tile/word.mu index d630b176..e9101eb2 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -264,6 +264,32 @@ fn print-words-in-reverse screen: (addr screen), _words-ah: (addr handle word) { print-string screen, " " } +fn copy-words _src-ah: (addr handle word), _dest-ah: (addr handle word) { + var src-ah/eax: (addr handle word) <- copy _src-ah + var src-a/eax: (addr word) <- lookup *src-ah + compare src-a, 0 + break-if-= + # copy + var dest-ah/edi: (addr handle word) <- copy _dest-ah + copy-word src-a, dest-ah + # recurse + var next-src-ah/esi: (addr handle word) <- get src-a, next + var dest-a/eax: (addr word) <- lookup *dest-ah + var next-dest-ah/eax: (addr handle word) <- get dest-a, next + copy-words next-src-ah, next-dest-ah +} + +fn copy-word _src-a: (addr word), _dest-ah: (addr handle word) { + var dest-ah/eax: (addr handle word) <- copy _dest-ah + allocate dest-ah + var _dest-a/eax: (addr word) <- lookup *dest-ah + var dest-a/eax: (addr word) <- copy _dest-a + var dest/edi: (addr handle gap-buffer) <- get dest-a, scalar-data + var src-a/eax: (addr word) <- copy _src-a + var src/eax: (addr handle gap-buffer) <- get src-a, scalar-data + copy-gap-buffer src, dest +} + # one implication of handles: append must take a handle fn append-word _self-ah: (addr handle word) { var self-ah/esi: (addr handle word) <- copy _self-ah