diff options
-rw-r--r-- | apps/tile/data.mu | 166 | ||||
-rw-r--r-- | apps/tile/word.mu | 29 |
2 files changed, 39 insertions, 156 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index 6b6d4775..dada0b5b 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -112,31 +112,7 @@ fn create-primitive-functions _self: (addr handle function) { var body/eax: (addr line) <- lookup *body-ah initialize-line body var curr-word-ah/ecx: (addr handle word) <- get body, data - # *curr-word = "x" - allocate curr-word-ah - var tmp/eax: (addr word) <- lookup *curr-word-ah - var curr-word/edx: (addr word) <- copy tmp - initialize-word-with curr-word, "x" - # *curr-word->next = "2" - var next-word-ah/ebx: (addr handle word) <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "2" - # *curr-word->next->prev = curr-word - var prev-word-ah/edi: (addr handle word) <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - # curr-word = curr-word->next - curr-word-ah <- copy next-word-ah - curr-word <- copy tmp - # *curr-word->next = "*" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "*" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - tmp <- lookup *prev-word-ah + parse-words "x 2 *", curr-word-ah # x 1+ = x 1 + var next/esi: (addr handle function) <- get f, next allocate next @@ -152,32 +128,8 @@ fn create-primitive-functions _self: (addr handle function) { allocate body-ah var body/eax: (addr line) <- lookup *body-ah initialize-line body - var curr-word-ah/ecx: (addr handle word) <- get body, data - # *curr-word = "x" - allocate curr-word-ah - var tmp/eax: (addr word) <- lookup *curr-word-ah - curr-word <- copy tmp - initialize-word-with curr-word, "x" - # *curr-word->next = "1" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "1" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - # curr-word = curr-word->next - curr-word-ah <- copy next-word-ah - curr-word <- copy tmp - # *curr-word->next = "+" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "+" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - tmp <- lookup *prev-word-ah + curr-word-ah <- get body, data + parse-words "x 1 +", curr-word-ah # x 2+ = x 1+ 1+ var next/esi: (addr handle function) <- get f, next allocate next @@ -193,32 +145,8 @@ fn create-primitive-functions _self: (addr handle function) { allocate body-ah var body/eax: (addr line) <- lookup *body-ah initialize-line body - var curr-word-ah/ecx: (addr handle word) <- get body, data - # *curr-word = "x" - allocate curr-word-ah - var tmp/eax: (addr word) <- lookup *curr-word-ah - curr-word <- copy tmp - initialize-word-with curr-word, "x" - # *curr-word->next = "1+" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "1+" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - # curr-word = curr-word->next - curr-word-ah <- copy next-word-ah - curr-word <- copy tmp - # *curr-word->next = "1+" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "1+" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - tmp <- lookup *prev-word-ah + curr-word-ah <- get body, data + parse-words "x 1+ 1+", curr-word-ah # x square = x x * var next/esi: (addr handle function) <- get f, next allocate next @@ -234,32 +162,8 @@ fn create-primitive-functions _self: (addr handle function) { allocate body-ah var body/eax: (addr line) <- lookup *body-ah initialize-line body - var curr-word-ah/ecx: (addr handle word) <- get body, data - # *curr-word = "x" - allocate curr-word-ah - var tmp/eax: (addr word) <- lookup *curr-word-ah - var curr-word/edx: (addr word) <- copy tmp - initialize-word-with curr-word, "x" - # *curr-word->next = "x" - var next-word-ah/ebx: (addr handle word) <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "x" - # *curr-word->next->prev = curr-word - var prev-word-ah/edi: (addr handle word) <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - # curr-word = curr-word->next - curr-word-ah <- copy next-word-ah - curr-word <- copy tmp - # *curr-word->next = "*" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "*" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - tmp <- lookup *prev-word-ah + curr-word-ah <- get body, data + parse-words "x x *", curr-word-ah # x 1- = x 1 - var next/esi: (addr handle function) <- get f, next allocate next @@ -275,32 +179,8 @@ fn create-primitive-functions _self: (addr handle function) { allocate body-ah var body/eax: (addr line) <- lookup *body-ah initialize-line body - var curr-word-ah/ecx: (addr handle word) <- get body, data - # *curr-word = "x" - allocate curr-word-ah - var tmp/eax: (addr word) <- lookup *curr-word-ah - curr-word <- copy tmp - initialize-word-with curr-word, "x" - # *curr-word->next = "1" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "1" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - # curr-word = curr-word->next - curr-word-ah <- copy next-word-ah - curr-word <- copy tmp - # *curr-word->next = "-" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "-" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - tmp <- lookup *prev-word-ah + curr-word-ah <- get body, data + parse-words "x 1 -", curr-word-ah # x y sub = x y - var next/esi: (addr handle function) <- get f, next allocate next @@ -321,32 +201,8 @@ fn create-primitive-functions _self: (addr handle function) { allocate body-ah var body/eax: (addr line) <- lookup *body-ah initialize-line body - var curr-word-ah/ecx: (addr handle word) <- get body, data - # *curr-word = "x" - allocate curr-word-ah - var tmp/eax: (addr word) <- lookup *curr-word-ah - curr-word <- copy tmp - initialize-word-with curr-word, "x" - # *curr-word->next = "y" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "y" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - # curr-word = curr-word->next - curr-word-ah <- copy next-word-ah - curr-word <- copy tmp - # *curr-word->next = "-" - next-word-ah <- get curr-word, next - allocate next-word-ah - tmp <- lookup *next-word-ah - initialize-word-with tmp, "-" - # *curr-word->next->prev = curr-word - prev-word-ah <- get tmp, prev - copy-object curr-word-ah, prev-word-ah - tmp <- lookup *prev-word-ah + curr-word-ah <- get body, data + parse-words "x y -", curr-word-ah } fn function-body functions: (addr handle function), _word: (addr handle word), out: (addr handle line) { diff --git a/apps/tile/word.mu b/apps/tile/word.mu index 69142234..9baa4b94 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -4,7 +4,6 @@ fn initialize-word _self: (addr word) { allocate data-ah var data/eax: (addr gap-buffer) <- lookup *data-ah initialize-gap-buffer data - # TODO: sometimes initialize box-data rather than scalar-data } ## some helpers for creating words. mostly for tests @@ -571,3 +570,31 @@ fn word-list-length words: (addr handle word) -> _/eax: int { } return result } + +# out-ah already has a word allocated and initialized +fn parse-words in: (addr array byte), out-ah: (addr handle word) { + var in-stream: (stream byte 0x100) + var in-stream-a/esi: (addr stream byte) <- address in-stream + write in-stream-a, in + var cursor-word-ah/ebx: (addr handle word) <- copy out-ah + $parse-words:loop: { + var done?/eax: boolean <- stream-empty? in-stream-a + compare done?, 0 # false + break-if-!= + var _g/eax: grapheme <- read-grapheme in-stream-a + var g/ecx: grapheme <- copy _g + # if not space, insert + compare g, 0x20 # space + { + break-if-= + var cursor-word/eax: (addr word) <- lookup *cursor-word-ah + add-grapheme-to-word cursor-word, g + loop $parse-words:loop + } + # otherwise insert word after and move cursor to it + append-word cursor-word-ah + var cursor-word/eax: (addr word) <- lookup *cursor-word-ah + cursor-word-ah <- get cursor-word, next + loop + } +} |