diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-17 23:29:02 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-17 23:29:02 -0700 |
commit | dc0e03e4a52adf914d8ed55ca5f833947cc264d3 (patch) | |
tree | 59561ea097071cb776b583d2e2479ae7f14f45c5 /apps/tile | |
parent | 1fc218bf9d274d739d37284a58fec61c283ee33f (diff) | |
download | mu-dc0e03e4a52adf914d8ed55ca5f833947cc264d3.tar.gz |
7053
Rename seems to now be working. State still isn't rendered right, so we can't be sure.
Diffstat (limited to 'apps/tile')
-rw-r--r-- | apps/tile/environment.mu | 37 | ||||
-rw-r--r-- | apps/tile/grapheme-stack.mu | 10 | ||||
-rw-r--r-- | apps/tile/main.mu | 4 | ||||
-rw-r--r-- | apps/tile/word.mu | 59 |
4 files changed, 100 insertions, 10 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 31d8ef8c..d6317d8c 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -70,11 +70,13 @@ $process:body: { compare rename-word-mode?, 0 { break-if-!= +#? print-string 0, "processing sandbox\n" process-sandbox self, sandbox, key break $process:body } { break-if-= +#? print-string 0, "processing sandbox rename\n" process-sandbox-rename sandbox, key } } @@ -97,7 +99,7 @@ $process-sandbox:body: { var at-start?/eax: boolean <- cursor-at-start? cursor-word compare at-start?, 0 # false { - break-if-= + break-if-!= #? print-string 0, "cursor left within word\n" cursor-left cursor-word break $process-sandbox:body @@ -174,7 +176,7 @@ $process-sandbox:body: { var at-end?/eax: boolean <- cursor-at-end? cursor-word compare at-end?, 0 # false { - break-if-= + break-if-!= #? print-string 0, "a\n" cursor-right cursor-word break $process-sandbox:body @@ -362,7 +364,7 @@ $process-sandbox:body: { var at-start?/eax: boolean <- cursor-at-start? cursor-word compare at-start?, 0 # false { - break-if-= + break-if-!= delete-before-cursor cursor-word break $process-sandbox:body } @@ -431,13 +433,31 @@ $process-sandbox-rename:body: { compare key, 0xa # enter $process-sandbox-rename:commit: { break-if-!= +#? print-string 0, "newline\n" + # new line var new-line-h: (handle line) var new-line-ah/eax: (addr handle line) <- address new-line-h allocate new-line-ah var new-line/eax: (addr line) <- lookup *new-line-ah - # new-line->word = sandbox-partial-name-for-cursor-word - var new-line-word/ecx: (addr handle word) <- get new-line, data - copy-object new-name-ah, new-line-word + initialize-line new-line + var new-line-word-ah/ecx: (addr handle word) <- get new-line, data + { + # move word at cursor to new line + var cursor-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor/eax: (addr call-path-element) <- lookup *cursor-ah + var word-at-cursor-ah/eax: (addr handle word) <- get cursor, word + move-word-contents word-at-cursor-ah, new-line-word-ah + # copy name to word at cursor + copy-word-contents-before-cursor new-name-ah, word-at-cursor-ah + } + # prepend '=' to name + { + var new-name/eax: (addr word) <- lookup *new-name-ah + cursor-to-start new-name + add-grapheme-to-word new-name, 0x3d # '=' + } + # append name to new line + chain-words new-line-word-ah, new-name-ah # new-line->next = sandbox->data var new-line-next/ecx: (addr handle line) <- get new-line, next var sandbox-slot/edx: (addr handle line) <- get sandbox, data @@ -458,7 +478,7 @@ $process-sandbox-rename:body: { var at-start?/eax: boolean <- cursor-at-start? new-name compare at-start?, 0 # false { - break-if-= + break-if-!= var new-name/eax: (addr word) <- lookup *new-name-ah delete-before-cursor new-name } @@ -583,6 +603,9 @@ fn render-sandbox screen: (addr screen), functions: (addr handle function), bind var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah var cursor-word/ebx: (addr word) <- copy _cursor-word +#? print-string 0, "cursor word is " +#? print-word 0, cursor-word +#? print-string 0, "\n" # cursor-col var cursor-col: int var cursor-col-a/edx: (addr int) <- address cursor-col diff --git a/apps/tile/grapheme-stack.mu b/apps/tile/grapheme-stack.mu index 2b7c8a87..401dda2d 100644 --- a/apps/tile/grapheme-stack.mu +++ b/apps/tile/grapheme-stack.mu @@ -11,14 +11,20 @@ fn initialize-grapheme-stack _self: (addr grapheme-stack), n: int { copy-to *top, 0 } +fn clear-grapheme-stack _self: (addr grapheme-stack) { + var self/esi: (addr grapheme-stack) <- copy _self + var top/eax: (addr int) <- get self, top + copy-to *top, 0 +} + fn grapheme-stack-empty? _self: (addr grapheme-stack) -> result/eax: boolean { $grapheme-stack-empty?:body: { var self/esi: (addr grapheme-stack) <- copy _self var top/eax: (addr int) <- get self, top compare *top, 0 { - break-if-= - result <- copy 1 # false + break-if-!= + result <- copy 1 # true break $grapheme-stack-empty?:body } result <- copy 0 # false diff --git a/apps/tile/main.mu b/apps/tile/main.mu index 045c8374..73488d2a 100644 --- a/apps/tile/main.mu +++ b/apps/tile/main.mu @@ -81,7 +81,9 @@ fn test { process env, g g <- copy 0x32 # '2' process env, g - g <- copy 0x2a # '*' + g <- copy 0x12 # ctrl-r + process env, g + g <- copy 0x61 # 'a' process env, g g <- copy 0xa # newline process env, g diff --git a/apps/tile/word.mu b/apps/tile/word.mu index 3d43a593..b8b9f7c0 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -49,6 +49,53 @@ fn prepend-word-with self-h: (handle word), s: (addr array byte) { ## real primitives +fn move-word-contents _src-ah: (addr handle word), _dest-ah: (addr handle word) { + var dest-ah/eax: (addr handle word) <- copy _dest-ah + var _dest/eax: (addr word) <- lookup *dest-ah + var dest/edi: (addr word) <- copy _dest + var src-ah/eax: (addr handle word) <- copy _src-ah + var _src/eax: (addr word) <- lookup *src-ah + var src/esi: (addr word) <- copy _src + cursor-to-start src + var src-data-ah/eax: (addr handle gap-buffer) <- get src, scalar-data + var src-data/eax: (addr gap-buffer) <- lookup *src-data-ah + var src-stack/ecx: (addr grapheme-stack) <- get src-data, right + { + var done?/eax: boolean <- grapheme-stack-empty? src-stack + compare done?, 0 # false + break-if-!= + var g/eax: grapheme <- pop-grapheme-stack src-stack +#? print-grapheme 0, g +#? print-string 0, "\n" + add-grapheme-to-word dest, g + loop + } +} + +fn copy-word-contents-before-cursor _src-ah: (addr handle word), _dest-ah: (addr handle word) { + var dest-ah/eax: (addr handle word) <- copy _dest-ah + var _dest/eax: (addr word) <- lookup *dest-ah + var dest/edi: (addr word) <- copy _dest + var src-ah/eax: (addr handle word) <- copy _src-ah + var src/eax: (addr word) <- lookup *src-ah + var src-data-ah/eax: (addr handle gap-buffer) <- get src, scalar-data + var src-data/eax: (addr gap-buffer) <- lookup *src-data-ah + var src-stack/ecx: (addr grapheme-stack) <- get src-data, left + var src-stack-data-ah/eax: (addr handle array grapheme) <- get src-stack, data + var _src-stack-data/eax: (addr array grapheme) <- lookup *src-stack-data-ah + var src-stack-data/edx: (addr array grapheme) <- copy _src-stack-data + var top-addr/ecx: (addr int) <- get src-stack, top + var i/eax: int <- copy 0 + { + compare i, *top-addr + break-if->= + var g/edx: (addr grapheme) <- index src-stack-data, i + add-grapheme-to-word dest, *g + i <- increment + loop + } +} + fn word-equal? _self: (addr word), s: (addr array byte) -> result/eax: boolean { var self/esi: (addr word) <- copy _self var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data @@ -222,6 +269,18 @@ fn append-word _self-ah: (addr handle word) { copy-object new-ah, dest } +fn chain-words _self-ah: (addr handle word), _next: (addr handle word) { + var self-ah/esi: (addr handle word) <- copy _self-ah + var _self/eax: (addr word) <- lookup *self-ah + var self/ecx: (addr word) <- copy _self + var next-ah/edi: (addr handle word) <- copy _next + var next/eax: (addr word) <- lookup *next-ah + var dest/edx: (addr handle word) <- get next, prev + copy-object self-ah, dest + dest <- get self, next + copy-object next-ah, dest +} + fn emit-word _self: (addr word), out: (addr stream byte) { var self/esi: (addr word) <- copy _self var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data |