diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-09 08:12:11 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-09 08:12:11 -0800 |
commit | d253a3182859c7c989449122a60d5f362f19ded0 (patch) | |
tree | 7459cddc57f93107fa4cee89d4f0a94dd0f0f131 /linux/browse | |
parent | d1808995b2c6b99749237a29e6ac6477d00ff8f9 (diff) | |
download | mu-d253a3182859c7c989449122a60d5f362f19ded0.tar.gz |
rename grapheme to code-point-utf8
Longer name, but it doesn't lie. We have no data structure right now for combining multiple code points. And it makes no sense for the notion of a grapheme to conflate its Unicode encoding.
Diffstat (limited to 'linux/browse')
-rw-r--r-- | linux/browse/main.mu | 40 | ||||
-rw-r--r-- | linux/browse/paginated-screen.mu | 176 |
2 files changed, 108 insertions, 108 deletions
diff --git a/linux/browse/main.mu b/linux/browse/main.mu index 5b4f2e06..27504afe 100644 --- a/linux/browse/main.mu +++ b/linux/browse/main.mu @@ -49,7 +49,7 @@ fn interactive fs: (addr buffered-file) { # { render paginated-screen, fs - var key/eax: grapheme <- read-key-from-real-keyboard + var key/eax: code-point-utf8 <- read-key-from-real-keyboard compare key, 0x71/'q' loop-if-!= } @@ -160,13 +160,13 @@ fn test-render-asterisk-in-text { fn render-normal screen: (addr paginated-screen), fs: (addr buffered-file) { var newline-seen?/esi: boolean <- copy 0/false var start-of-paragraph?/edi: boolean <- copy 1/true - var previous-grapheme/ebx: grapheme <- copy 0 + var previous-code-point-utf8/ebx: code-point-utf8 <- copy 0 $render-normal:loop: { # if done-drawing?(screen) break var done?/eax: boolean <- done-drawing? screen compare done?, 0/false break-if-!= - var c/eax: grapheme <- read-grapheme-buffered fs + var c/eax: code-point-utf8 <- read-code-point-utf8-buffered fs $render-normal:loop-body: { # if (c == EOF) break compare c, 0xffffffff/end-of-file @@ -186,8 +186,8 @@ $render-normal:loop-body: { # otherwise render two newlines { break-if-= - add-grapheme screen, 0xa/newline - add-grapheme screen, 0xa/newline + add-code-point-utf8 screen, 0xa/newline + add-code-point-utf8 screen, 0xa/newline newline-seen? <- copy 0/false start-of-paragraph? <- copy 1/true break $render-normal:loop-body @@ -221,20 +221,20 @@ $render-normal:flush-buffered-newline: { { compare c, 0x20 break-if-!= - add-grapheme screen, 0xa/newline + add-code-point-utf8 screen, 0xa/newline break $render-normal:flush-buffered-newline } - add-grapheme screen, 0x20/space + add-code-point-utf8 screen, 0x20/space # fall through to print c } ## end soft newline support $render-normal:whitespace-separated-regions: { - # if previous-grapheme wasn't whitespace, skip this block + # if previous-code-point-utf8 wasn't whitespace, skip this block { - compare previous-grapheme, 0x20/space + compare previous-code-point-utf8, 0x20/space break-if-= - compare previous-grapheme, 0xa/newline + compare previous-code-point-utf8, 0xa/newline break-if-= break $render-normal:whitespace-separated-regions } @@ -260,9 +260,9 @@ $render-normal:whitespace-separated-regions: { } } # - add-grapheme screen, c + add-code-point-utf8 screen, c } # $render-normal:loop-body - previous-grapheme <- copy c + previous-code-point-utf8 <- copy c loop } # $render-normal:loop } @@ -271,7 +271,7 @@ fn render-header-line screen: (addr paginated-screen), fs: (addr buffered-file) $render-header-line:body: { # compute color based on number of '#'s var header-level/esi: int <- copy 1 # caller already grabbed one - var c/eax: grapheme <- copy 0 + var c/eax: code-point-utf8 <- copy 0 { # if done-drawing?(screen) return { @@ -280,7 +280,7 @@ $render-header-line:body: { break-if-!= $render-header-line:body } # - c <- read-grapheme-buffered fs + c <- read-code-point-utf8-buffered fs # if (c != '#') break compare c, 0x23/'#' break-if-!= @@ -298,7 +298,7 @@ $render-header-line:body: { break-if-!= } # - c <- read-grapheme-buffered fs + c <- read-code-point-utf8-buffered fs # if (c == EOF) break compare c, 0xffffffff/end-of-file break-if-= @@ -306,7 +306,7 @@ $render-header-line:body: { compare c, 0xa/newline break-if-= # - add-grapheme screen, c + add-code-point-utf8 screen, c # loop } @@ -353,7 +353,7 @@ fn render-until-asterisk screen: (addr paginated-screen), fs: (addr buffered-fil compare done?, 0/false break-if-!= # - var c/eax: grapheme <- read-grapheme-buffered fs + var c/eax: code-point-utf8 <- read-code-point-utf8-buffered fs # if (c == EOF) break compare c, 0xffffffff/end-of-file break-if-= @@ -361,7 +361,7 @@ fn render-until-asterisk screen: (addr paginated-screen), fs: (addr buffered-fil compare c, 0x2a/'*' break-if-= # - add-grapheme screen, c + add-code-point-utf8 screen, c # loop } @@ -374,7 +374,7 @@ fn render-until-underscore screen: (addr paginated-screen), fs: (addr buffered-f compare done?, 0/false break-if-!= # - var c/eax: grapheme <- read-grapheme-buffered fs + var c/eax: code-point-utf8 <- read-code-point-utf8-buffered fs # if (c == EOF) break compare c, 0xffffffff/end-of-file break-if-= @@ -382,7 +382,7 @@ fn render-until-underscore screen: (addr paginated-screen), fs: (addr buffered-f compare c, 0x5f/'_' break-if-= # - add-grapheme screen, c + add-code-point-utf8 screen, c # loop } diff --git a/linux/browse/paginated-screen.mu b/linux/browse/paginated-screen.mu index f4579d95..05f954a7 100644 --- a/linux/browse/paginated-screen.mu +++ b/linux/browse/paginated-screen.mu @@ -7,7 +7,7 @@ # on each frame # start-drawing # while !done-drawing -# add-grapheme ... +# add-code-point-utf8 ... type paginated-screen { screen: (handle screen) @@ -152,23 +152,23 @@ fn done-drawing? _self: (addr paginated-screen) -> _/eax: boolean { return 1/true } -fn add-grapheme _self: (addr paginated-screen), c: grapheme { -#? print-string-to-real-screen "add-grapheme: " -#? print-grapheme-to-real-screen c +fn add-code-point-utf8 _self: (addr paginated-screen), c: code-point-utf8 { +#? print-string-to-real-screen "add-code-point-utf8: " +#? print-code-point-utf8-to-real-screen c #? print-string-to-real-screen "\n" -$add-grapheme:body: { +$add-code-point-utf8:body: { var self/esi: (addr paginated-screen) <- copy _self { compare c, 0xa/newline break-if-!= next-line self reposition-cursor self - break $add-grapheme:body + break $add-code-point-utf8:body } # print c var screen-ah/eax: (addr handle screen) <- get self, screen var screen-addr/eax: (addr screen) <- lookup *screen-ah - print-grapheme screen-addr, c + print-code-point-utf8 screen-addr, c # self->col++ var tmp/eax: (addr int) <- get self, col increment *tmp @@ -186,21 +186,21 @@ $add-grapheme:body: { ## tests -fn test-print-grapheme-on-paginated-screen { +fn test-print-code-point-utf8-on-paginated-screen { var pg-on-stack: paginated-screen var pg/eax: (addr paginated-screen) <- address pg-on-stack initialize-fake-paginated-screen pg, 3/rows, 0xa/cols, 0xa/page-width, 0, 0 start-drawing pg { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-grapheme-on-paginated-screen/done" + check-ints-equal done, 0, "F - test-print-code-point-utf8-on-paginated-screen/done" } var screen-ah/eax: (addr handle screen) <- get pg, screen var screen-addr/eax: (addr screen) <- lookup *screen-ah - check-screen-row screen-addr, 1, "a", "F - test-print-grapheme-on-paginated-screen" + check-screen-row screen-addr, 1, "a", "F - test-print-code-point-utf8-on-paginated-screen" } fn test-print-single-page { @@ -210,29 +210,29 @@ fn test-print-single-page { start-drawing pg # pages at columns [1, 3), [3, 5) { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page/done-1" } { - var c/ecx: grapheme <- copy 0x62/b - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x62/b + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page/done-2" } { - var c/ecx: grapheme <- copy 0x63/c - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x63/c + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page/done-3" } { - var c/ecx: grapheme <- copy 0x64/d - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x64/d + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page/done-4" @@ -250,36 +250,36 @@ fn test-print-single-page-narrower-than-page-width { initialize-fake-paginated-screen pg, 2/rows, 4/cols, 5/page-width, 0, 0 start-drawing pg { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width/done-1" } { - var c/ecx: grapheme <- copy 0x62/b - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x62/b + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width/done-2" } { - var c/ecx: grapheme <- copy 0x63/c - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x63/c + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width/done-3" } { - var c/ecx: grapheme <- copy 0x64/d - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x64/d + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width/done-4" } { - var c/ecx: grapheme <- copy 0x65/e - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x65/e + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width/done-5" @@ -297,36 +297,36 @@ fn test-print-single-page-narrower-than-page-width-with-margin { initialize-fake-paginated-screen pg, 2/rows, 4/cols, 5/page-width, 0/top-margin, 1/left-margin start-drawing pg { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width-with-margin/done-1" } { - var c/ecx: grapheme <- copy 0x62/b - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x62/b + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width-with-margin/done-2" } { - var c/ecx: grapheme <- copy 0x63/c - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x63/c + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width-with-margin/done-3" } { - var c/ecx: grapheme <- copy 0x64/d - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x64/d + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width-with-margin/done-4" } { - var c/ecx: grapheme <- copy 0x65/e - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x65/e + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-single-page-narrower-than-page-width-with-margin/done-5" @@ -344,29 +344,29 @@ fn test-print-multiple-pages { initialize-fake-paginated-screen pg, 2/rows, 2/cols, 1/page-width, 0, 0 start-drawing pg { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages/done-1" } { - var c/ecx: grapheme <- copy 0x62/b - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x62/b + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages/done-2" } { - var c/ecx: grapheme <- copy 0x63/c - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x63/c + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages/done-3" } { - var c/ecx: grapheme <- copy 0x64/d - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x64/d + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 1, "F - test-print-multiple-pages/done-4" @@ -384,57 +384,57 @@ fn test-print-multiple-pages-2 { initialize-fake-paginated-screen pg, 2/rows, 4/cols, 2/page-width, 0, 0 start-drawing pg { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-1" } { - var c/ecx: grapheme <- copy 0x62/b - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x62/b + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-2" } { - var c/ecx: grapheme <- copy 0x63/c - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x63/c + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-3" } { - var c/ecx: grapheme <- copy 0x64/d - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x64/d + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-4" } { - var c/ecx: grapheme <- copy 0x65/e - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x65/e + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-5" } { - var c/ecx: grapheme <- copy 0x66/f - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x66/f + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-6" } { - var c/ecx: grapheme <- copy 0x67/g - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x67/g + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 0, "F - test-print-multiple-pages-2/done-7" } { - var c/ecx: grapheme <- copy 0x68/h - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x68/h + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? check-ints-equal done, 1, "F - test-print-multiple-pages-2/done-8" @@ -452,60 +452,60 @@ fn test-print-multiple-pages-with-margins { initialize-fake-paginated-screen pg, 3/rows, 6/cols, 2/page-width, 1/top-margin, 1/left-margin start-drawing pg { - var c/ecx: grapheme <- copy 0x61/a - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x61/a + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-1" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-1" } { - var c/ecx: grapheme <- copy 0x62/b - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x62/b + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-2" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-2" } { - var c/ecx: grapheme <- copy 0x63/c - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x63/c + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-3" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-3" } { - var c/ecx: grapheme <- copy 0x64/d - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x64/d + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-4" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-4" } { - var c/ecx: grapheme <- copy 0x65/e - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x65/e + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-5" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-5" } { - var c/ecx: grapheme <- copy 0x66/f - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x66/f + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-6" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-6" } { - var c/ecx: grapheme <- copy 0x67/g - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x67/g + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/grapheme-7" + check-ints-equal done, 0, "F - test-print-multiple-pages-with-margins/code-point-utf8-7" } { - var c/ecx: grapheme <- copy 0x68/h - add-grapheme pg, c + var c/ecx: code-point-utf8 <- copy 0x68/h + add-code-point-utf8 pg, c var done?/eax: boolean <- done-drawing? pg var done/eax: int <- copy done? - check-ints-equal done, 1, "F - test-print-multiple-pages-with-margins/grapheme-8" + check-ints-equal done, 1, "F - test-print-multiple-pages-with-margins/code-point-utf8-8" } var screen-ah/eax: (addr handle screen) <- get pg, screen var screen-addr/eax: (addr screen) <- lookup *screen-ah |