From 53d69dd1c5707a1cddd5c2ca6827b9a517659eeb Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 9 Nov 2021 09:29:56 -0800 Subject: keep 'grapheme-stack' We want to at least document intent there. --- linux/tile/gap-buffer.mu | 102 +++++++++++++++++++++---------------------- linux/tile/grapheme-stack.mu | 50 ++++++++++----------- linux/tile/word.mu | 8 ++-- 3 files changed, 80 insertions(+), 80 deletions(-) (limited to 'linux') diff --git a/linux/tile/gap-buffer.mu b/linux/tile/gap-buffer.mu index 1441684b..3c22501d 100644 --- a/linux/tile/gap-buffer.mu +++ b/linux/tile/gap-buffer.mu @@ -1,14 +1,14 @@ type gap-buffer { - left: code-point-utf8-stack - right: code-point-utf8-stack + left: grapheme-stack + right: grapheme-stack } fn initialize-gap-buffer _self: (addr gap-buffer) { var self/esi: (addr gap-buffer) <- copy _self - var left/eax: (addr code-point-utf8-stack) <- get self, left - initialize-code-point-utf8-stack left, 0x10/max-word-size - var right/eax: (addr code-point-utf8-stack) <- get self, right - initialize-code-point-utf8-stack right, 0x10/max-word-size + var left/eax: (addr grapheme-stack) <- get self, left + initialize-grapheme-stack left, 0x10/max-word-size + var right/eax: (addr grapheme-stack) <- get self, right + initialize-grapheme-stack right, 0x10/max-word-size } # just for tests @@ -37,15 +37,15 @@ fn gap-buffer-to-string self: (addr gap-buffer), out: (addr handle array byte) { fn emit-gap-buffer _self: (addr gap-buffer), out: (addr stream byte) { var self/esi: (addr gap-buffer) <- copy _self clear-stream out - var left/eax: (addr code-point-utf8-stack) <- get self, left + var left/eax: (addr grapheme-stack) <- get self, left emit-stack-from-bottom left, out - var right/eax: (addr code-point-utf8-stack) <- get self, right + var right/eax: (addr grapheme-stack) <- get self, right emit-stack-from-top right, out } # dump stack from bottom to top -fn emit-stack-from-bottom _self: (addr code-point-utf8-stack), out: (addr stream byte) { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn emit-stack-from-bottom _self: (addr grapheme-stack), out: (addr stream byte) { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/edi: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -62,8 +62,8 @@ fn emit-stack-from-bottom _self: (addr code-point-utf8-stack), out: (addr stream } # dump stack from top to bottom -fn emit-stack-from-top _self: (addr code-point-utf8-stack), out: (addr stream byte) { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn emit-stack-from-top _self: (addr grapheme-stack), out: (addr stream byte) { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/edi: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -82,18 +82,18 @@ fn emit-stack-from-top _self: (addr code-point-utf8-stack), out: (addr stream by fn render-gap-buffer screen: (addr screen), _gap: (addr gap-buffer) { var gap/esi: (addr gap-buffer) <- copy _gap - var left/eax: (addr code-point-utf8-stack) <- get gap, left + var left/eax: (addr grapheme-stack) <- get gap, left render-stack-from-bottom left, screen - var right/eax: (addr code-point-utf8-stack) <- get gap, right + var right/eax: (addr grapheme-stack) <- get gap, right render-stack-from-top right, screen } fn gap-buffer-length _gap: (addr gap-buffer) -> _/eax: int { var gap/esi: (addr gap-buffer) <- copy _gap - var left/eax: (addr code-point-utf8-stack) <- get gap, left + var left/eax: (addr grapheme-stack) <- get gap, left var tmp/eax: (addr int) <- get left, top var left-length/ecx: int <- copy *tmp - var right/esi: (addr code-point-utf8-stack) <- get gap, right + var right/esi: (addr grapheme-stack) <- get gap, right tmp <- get right, top var result/eax: int <- copy *tmp result <- add left-length @@ -102,8 +102,8 @@ fn gap-buffer-length _gap: (addr gap-buffer) -> _/eax: int { fn add-code-point-utf8-at-gap _self: (addr gap-buffer), g: code-point-utf8 { var self/esi: (addr gap-buffer) <- copy _self - var left/eax: (addr code-point-utf8-stack) <- get self, left - push-code-point-utf8-stack left, g + var left/eax: (addr grapheme-stack) <- get self, left + push-grapheme-stack left, g } fn gap-to-start self: (addr gap-buffer) { @@ -124,28 +124,28 @@ fn gap-to-end self: (addr gap-buffer) { fn gap-at-start? _self: (addr gap-buffer) -> _/eax: boolean { var self/esi: (addr gap-buffer) <- copy _self - var left/eax: (addr code-point-utf8-stack) <- get self, left - var result/eax: boolean <- code-point-utf8-stack-empty? left + var left/eax: (addr grapheme-stack) <- get self, left + var result/eax: boolean <- grapheme-stack-empty? left return result } fn gap-at-end? _self: (addr gap-buffer) -> _/eax: boolean { var self/esi: (addr gap-buffer) <- copy _self - var right/eax: (addr code-point-utf8-stack) <- get self, right - var result/eax: boolean <- code-point-utf8-stack-empty? right + var right/eax: (addr grapheme-stack) <- get self, right + var result/eax: boolean <- grapheme-stack-empty? right return result } fn gap-right _self: (addr gap-buffer) -> _/eax: code-point-utf8 { var self/esi: (addr gap-buffer) <- copy _self var g/eax: code-point-utf8 <- copy 0 - var right/ecx: (addr code-point-utf8-stack) <- get self, right - g <- pop-code-point-utf8-stack right + var right/ecx: (addr grapheme-stack) <- get self, right + g <- pop-grapheme-stack right compare g, -1 { break-if-= - var left/ecx: (addr code-point-utf8-stack) <- get self, left - push-code-point-utf8-stack left, g + var left/ecx: (addr grapheme-stack) <- get self, left + push-grapheme-stack left, g } return g } @@ -154,21 +154,21 @@ fn gap-left _self: (addr gap-buffer) -> _/eax: code-point-utf8 { var self/esi: (addr gap-buffer) <- copy _self var g/eax: code-point-utf8 <- copy 0 { - var left/ecx: (addr code-point-utf8-stack) <- get self, left - g <- pop-code-point-utf8-stack left + var left/ecx: (addr grapheme-stack) <- get self, left + g <- pop-grapheme-stack left } compare g, -1 { break-if-= - var right/ecx: (addr code-point-utf8-stack) <- get self, right - push-code-point-utf8-stack right, g + var right/ecx: (addr grapheme-stack) <- get self, right + push-grapheme-stack right, g } return g } fn gap-index _self: (addr gap-buffer) -> _/eax: int { var self/eax: (addr gap-buffer) <- copy _self - var left/eax: (addr code-point-utf8-stack) <- get self, left + var left/eax: (addr grapheme-stack) <- get self, left var top-addr/eax: (addr int) <- get left, top var result/eax: int <- copy *top-addr return result @@ -177,7 +177,7 @@ fn gap-index _self: (addr gap-buffer) -> _/eax: int { fn first-code-point-utf8-in-gap-buffer _self: (addr gap-buffer) -> _/eax: code-point-utf8 { var self/esi: (addr gap-buffer) <- copy _self # try to read from left - var left/eax: (addr code-point-utf8-stack) <- get self, left + var left/eax: (addr grapheme-stack) <- get self, left var top-addr/ecx: (addr int) <- get left, top compare *top-addr, 0 { @@ -188,7 +188,7 @@ fn first-code-point-utf8-in-gap-buffer _self: (addr gap-buffer) -> _/eax: code-p return *result-addr } # try to read from right - var right/eax: (addr code-point-utf8-stack) <- get self, right + var right/eax: (addr grapheme-stack) <- get self, right top-addr <- get right, top compare *top-addr, 0 { @@ -207,13 +207,13 @@ fn first-code-point-utf8-in-gap-buffer _self: (addr gap-buffer) -> _/eax: code-p fn code-point-utf8-before-cursor-in-gap-buffer _self: (addr gap-buffer) -> _/eax: code-point-utf8 { var self/esi: (addr gap-buffer) <- copy _self # try to read from left - var left/ecx: (addr code-point-utf8-stack) <- get self, left + var left/ecx: (addr grapheme-stack) <- get self, left var top-addr/edx: (addr int) <- get left, top compare *top-addr, 0 { break-if-<= - var result/eax: code-point-utf8 <- pop-code-point-utf8-stack left - push-code-point-utf8-stack left, result + var result/eax: code-point-utf8 <- pop-grapheme-stack left + push-grapheme-stack left, result return result } # give up @@ -222,14 +222,14 @@ fn code-point-utf8-before-cursor-in-gap-buffer _self: (addr gap-buffer) -> _/eax fn delete-before-gap _self: (addr gap-buffer) { var self/eax: (addr gap-buffer) <- copy _self - var left/eax: (addr code-point-utf8-stack) <- get self, left - var dummy/eax: code-point-utf8 <- pop-code-point-utf8-stack left + var left/eax: (addr grapheme-stack) <- get self, left + var dummy/eax: code-point-utf8 <- pop-grapheme-stack left } fn pop-after-gap _self: (addr gap-buffer) -> _/eax: code-point-utf8 { var self/eax: (addr gap-buffer) <- copy _self - var right/eax: (addr code-point-utf8-stack) <- get self, right - var result/eax: code-point-utf8 <- pop-code-point-utf8-stack right + var right/eax: (addr grapheme-stack) <- get self, right + var result/eax: code-point-utf8 <- pop-grapheme-stack right return result } @@ -242,7 +242,7 @@ fn gap-buffer-equal? _self: (addr gap-buffer), s: (addr array byte) -> _/eax: bo var expected-stream/ecx: (addr stream byte) <- address stream-storage write expected-stream, s # compare left - var left/edx: (addr code-point-utf8-stack) <- get self, left + var left/edx: (addr grapheme-stack) <- get self, left var result/eax: boolean <- prefix-match? left, expected-stream compare result, 0/false { @@ -250,7 +250,7 @@ fn gap-buffer-equal? _self: (addr gap-buffer), s: (addr array byte) -> _/eax: bo return result } # compare right - var right/edx: (addr code-point-utf8-stack) <- get self, right + var right/edx: (addr grapheme-stack) <- get self, right result <- suffix-match? right, expected-stream compare result, 0/false { @@ -319,25 +319,25 @@ fn copy-gap-buffer _src-ah: (addr handle gap-buffer), _dest-ah: (addr handle gap 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 code-point-utf8-stack - var src/ecx: (addr code-point-utf8-stack) <- get src-a, left - var dest/edx: (addr code-point-utf8-stack) <- get dest-a, left - copy-code-point-utf8-stack src, dest - # copy right code-point-utf8-stack + # 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-code-point-utf8-stack src, dest + copy-grapheme-stack src, dest } fn gap-buffer-is-decimal-integer? _self: (addr gap-buffer) -> _/eax: boolean { var self/esi: (addr gap-buffer) <- copy _self - var curr/ecx: (addr code-point-utf8-stack) <- get self, left - var result/eax: boolean <- code-point-utf8-stack-is-decimal-integer? curr + var curr/ecx: (addr grapheme-stack) <- get self, left + var result/eax: boolean <- grapheme-stack-is-decimal-integer? curr { compare result, 0/false break-if-= curr <- get self, right - result <- code-point-utf8-stack-is-decimal-integer? curr + result <- grapheme-stack-is-decimal-integer? curr } return result } diff --git a/linux/tile/grapheme-stack.mu b/linux/tile/grapheme-stack.mu index c7565a1c..0966be6c 100644 --- a/linux/tile/grapheme-stack.mu +++ b/linux/tile/grapheme-stack.mu @@ -1,24 +1,24 @@ -type code-point-utf8-stack { +type grapheme-stack { data: (handle array code-point-utf8) top: int } -fn initialize-code-point-utf8-stack _self: (addr code-point-utf8-stack), n: int { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn initialize-grapheme-stack _self: (addr grapheme-stack), n: int { + var self/esi: (addr grapheme-stack) <- copy _self var d/edi: (addr handle array code-point-utf8) <- get self, data populate d, n var top/eax: (addr int) <- get self, top copy-to *top, 0 } -fn clear-code-point-utf8-stack _self: (addr code-point-utf8-stack) { - var self/esi: (addr code-point-utf8-stack) <- copy _self +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 code-point-utf8-stack-empty? _self: (addr code-point-utf8-stack) -> _/eax: boolean { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn grapheme-stack-empty? _self: (addr grapheme-stack) -> _/eax: boolean { + var self/esi: (addr grapheme-stack) <- copy _self var top/eax: (addr int) <- get self, top compare *top, 0 { @@ -28,8 +28,8 @@ fn code-point-utf8-stack-empty? _self: (addr code-point-utf8-stack) -> _/eax: bo return 0/false } -fn push-code-point-utf8-stack _self: (addr code-point-utf8-stack), _val: code-point-utf8 { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn push-grapheme-stack _self: (addr grapheme-stack), _val: code-point-utf8 { + var self/esi: (addr grapheme-stack) <- copy _self var top-addr/ecx: (addr int) <- get self, top var data-ah/edx: (addr handle array code-point-utf8) <- get self, data var data/eax: (addr array code-point-utf8) <- lookup *data-ah @@ -40,8 +40,8 @@ fn push-code-point-utf8-stack _self: (addr code-point-utf8-stack), _val: code-po add-to *top-addr, 1 } -fn pop-code-point-utf8-stack _self: (addr code-point-utf8-stack) -> _/eax: code-point-utf8 { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn pop-grapheme-stack _self: (addr grapheme-stack) -> _/eax: code-point-utf8 { + var self/esi: (addr grapheme-stack) <- copy _self var top-addr/ecx: (addr int) <- get self, top { compare *top-addr, 0 @@ -56,8 +56,8 @@ fn pop-code-point-utf8-stack _self: (addr code-point-utf8-stack) -> _/eax: code- return *result-addr } -fn copy-code-point-utf8-stack _src: (addr code-point-utf8-stack), dest: (addr code-point-utf8-stack) { - var src/esi: (addr code-point-utf8-stack) <- copy _src +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 code-point-utf8) <- get src, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -67,7 +67,7 @@ fn copy-code-point-utf8-stack _src: (addr code-point-utf8-stack), dest: (addr co compare i, *top-addr break-if->= var g/edx: (addr code-point-utf8) <- index data, i - push-code-point-utf8-stack dest, *g + push-grapheme-stack dest, *g i <- increment loop } @@ -75,8 +75,8 @@ fn copy-code-point-utf8-stack _src: (addr code-point-utf8-stack), dest: (addr co # dump stack to screen from bottom to top # don't move the cursor or anything -fn render-stack-from-bottom _self: (addr code-point-utf8-stack), screen: (addr screen) { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn render-stack-from-bottom _self: (addr grapheme-stack), screen: (addr screen) { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/edi: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -94,8 +94,8 @@ fn render-stack-from-bottom _self: (addr code-point-utf8-stack), screen: (addr s # dump stack to screen from top to bottom # don't move the cursor or anything -fn render-stack-from-top _self: (addr code-point-utf8-stack), screen: (addr screen) { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn render-stack-from-top _self: (addr grapheme-stack), screen: (addr screen) { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/edi: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -114,8 +114,8 @@ fn render-stack-from-top _self: (addr code-point-utf8-stack), screen: (addr scre # compare from bottom # beware: modifies 'stream', which must be disposed of after a false result -fn prefix-match? _self: (addr code-point-utf8-stack), s: (addr stream byte) -> _/eax: boolean { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn prefix-match? _self: (addr grapheme-stack), s: (addr stream byte) -> _/eax: boolean { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/edi: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -142,8 +142,8 @@ fn prefix-match? _self: (addr code-point-utf8-stack), s: (addr stream byte) -> _ # compare from bottom # beware: modifies 'stream', which must be disposed of after a false result -fn suffix-match? _self: (addr code-point-utf8-stack), s: (addr stream byte) -> _/eax: boolean { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn suffix-match? _self: (addr grapheme-stack), s: (addr stream byte) -> _/eax: boolean { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/edi: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edi: (addr array code-point-utf8) <- copy _data @@ -169,15 +169,15 @@ fn suffix-match? _self: (addr code-point-utf8-stack), s: (addr stream byte) -> _ return 1 # true } -fn code-point-utf8-stack-is-decimal-integer? _self: (addr code-point-utf8-stack) -> _/eax: boolean { - var self/esi: (addr code-point-utf8-stack) <- copy _self +fn grapheme-stack-is-decimal-integer? _self: (addr grapheme-stack) -> _/eax: boolean { + var self/esi: (addr grapheme-stack) <- copy _self var data-ah/eax: (addr handle array code-point-utf8) <- get self, data var _data/eax: (addr array code-point-utf8) <- lookup *data-ah var data/edx: (addr array code-point-utf8) <- copy _data var top-addr/ecx: (addr int) <- get self, top var i/ebx: int <- copy 0 var result/eax: boolean <- copy 1/true - $code-point-utf8-stack-is-integer?:loop: { + $grapheme-stack-is-integer?:loop: { compare i, *top-addr break-if->= var g/edx: (addr code-point-utf8) <- index data, i diff --git a/linux/tile/word.mu b/linux/tile/word.mu index 3b4851f0..ba4877fa 100644 --- a/linux/tile/word.mu +++ b/linux/tile/word.mu @@ -58,12 +58,12 @@ fn move-word-contents _src-ah: (addr handle word), _dest-ah: (addr handle word) 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 code-point-utf8-stack) <- get src-data, right + var src-stack/ecx: (addr grapheme-stack) <- get src-data, right { - var done?/eax: boolean <- code-point-utf8-stack-empty? src-stack + var done?/eax: boolean <- grapheme-stack-empty? src-stack compare done?, 0/false break-if-!= - var g/eax: code-point-utf8 <- pop-code-point-utf8-stack src-stack + var g/eax: code-point-utf8 <- pop-grapheme-stack src-stack #? print-code-point-utf8 0, g #? print-string 0, "\n" add-code-point-utf8-to-word dest, g @@ -79,7 +79,7 @@ fn copy-word-contents-before-cursor _src-ah: (addr handle word), _dest-ah: (addr 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 code-point-utf8-stack) <- get src-data, left + var src-stack/ecx: (addr grapheme-stack) <- get src-data, left var src-stack-data-ah/eax: (addr handle array code-point-utf8) <- get src-stack, data var _src-stack-data/eax: (addr array code-point-utf8) <- lookup *src-stack-data-ah var src-stack-data/edx: (addr array code-point-utf8) <- copy _src-stack-data -- cgit 1.4.1-2-gfad0