diff options
-rw-r--r-- | apps/tile/data.mu | 79 | ||||
-rw-r--r-- | apps/tile/environment.mu | 186 | ||||
-rw-r--r-- | apps/tile/main.mu | 6 |
3 files changed, 89 insertions, 182 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index b7ed36d6..23a78d65 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -62,7 +62,7 @@ type call-path { # Calls are denoted by their position in the caller's body. They also include # the function being called. type call-path-element { - index-in-body: int + word: (handle word) next: (handle call-path-element) } @@ -73,12 +73,16 @@ type result { fn initialize-sandbox _sandbox: (addr sandbox) { var sandbox/esi: (addr sandbox) <- copy _sandbox - var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path - allocate cursor-call-path-ah var line-ah/eax: (addr handle line) <- get sandbox, data allocate line-ah var line/eax: (addr line) <- lookup *line-ah initialize-line line + var word-ah/ecx: (addr handle word) <- get line, data + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + allocate cursor-call-path-ah + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + var dest/eax: (addr handle word) <- get cursor-call-path, word + copy-object word-ah, dest } # initialize line with a single empty word @@ -331,6 +335,17 @@ fn populate-text-with _out: (addr handle array byte), _in: (addr array byte) { } } +fn initialize-path-from-sandbox _in: (addr sandbox), _out: (addr handle call-path-element) { + var sandbox/esi: (addr sandbox) <- copy _in + var line-ah/eax: (addr handle line) <- get sandbox, data + var line/eax: (addr line) <- lookup *line-ah + var src/esi: (addr handle word) <- get line, data + var out-ah/edi: (addr handle call-path-element) <- copy _out + var out/eax: (addr call-path-element) <- lookup *out-ah + var dest/edi: (addr handle word) <- get out, word + copy-object src, dest +} + fn find-in-call-path in: (addr handle call-path), needle: (addr handle call-path-element) -> result/eax: boolean { var curr-ah/esi: (addr handle call-path) <- copy in var out/edi: boolean <- copy 0 # false @@ -380,9 +395,12 @@ $call-path-element-match?:body: { result <- copy 0 # false break $call-path-element-match?:body } - var x-data-a/ecx: (addr int) <- get x, index-in-body + # compare word addresses, not contents + var x-data-ah/ecx: (addr handle word) <- get x, word + var x-data-a/eax: (addr word) <- lookup *x-data-ah var x-data/ecx: int <- copy *x-data-a - var y-data-a/eax: (addr int) <- get y, index-in-body + var y-data-ah/eax: (addr handle word) <- get y, word + var y-data-a/eax: (addr word) <- lookup *y-data-ah var y-data/eax: int <- copy *y-data-a compare x-data, y-data { @@ -423,10 +441,9 @@ fn deep-copy-call-path-element _src: (addr handle call-path-element), _dest: (ad # copy data var dest-addr/eax: (addr call-path-element) <- lookup *dest { - var dest-data-addr/ecx: (addr int) <- get dest-addr, index-in-body - var tmp/eax: (addr int) <- get src-addr, index-in-body - var tmp2/eax: int <- copy *tmp - copy-to *dest-data-addr, tmp2 + var dest-data-addr/ecx: (addr handle word) <- get dest-addr, word + var src-data-addr/eax: (addr handle word) <- get src-addr, word + copy-object src-data-addr, dest-data-addr } # recurse var src-next/esi: (addr handle call-path-element) <- get src-addr, next @@ -462,36 +479,36 @@ $delete-in-call-path:body: { fn increment-final-element list: (addr handle call-path-element) { var final-ah/eax: (addr handle call-path-element) <- copy list var final/eax: (addr call-path-element) <- lookup *final-ah - var val/eax: (addr int) <- get final, index-in-body - increment *val + var val-ah/ecx: (addr handle word) <- get final, word + var val/eax: (addr word) <- lookup *val-ah + var new-ah/edx: (addr handle word) <- get val, next + var target/eax: (addr word) <- lookup *new-ah + compare target, 0 + break-if-= + copy-object new-ah, val-ah } fn decrement-final-element list: (addr handle call-path-element) { var final-ah/eax: (addr handle call-path-element) <- copy list var final/eax: (addr call-path-element) <- lookup *final-ah - var val/eax: (addr int) <- get final, index-in-body - compare *val, 0 + var val-ah/ecx: (addr handle word) <- get final, word + var val/eax: (addr word) <- lookup *val-ah + var new-ah/edx: (addr handle word) <- get val, prev + var target/eax: (addr word) <- lookup *new-ah + compare target, 0 break-if-= - decrement *val + copy-object new-ah, val-ah } -fn final-element-value list: (addr handle call-path-element) -> result/eax: int { - var final-ah/eax: (addr handle call-path-element) <- copy list - var final/eax: (addr call-path-element) <- lookup *final-ah - var val/eax: (addr int) <- get final, index-in-body - result <- copy *val -} - -fn push-to-call-path-element list: (addr handle call-path-element), new: int { +fn push-to-call-path-element list: (addr handle call-path-element), new: (addr handle word) { var new-element-storage: (handle call-path-element) var new-element-ah/edi: (addr handle call-path-element) <- address new-element-storage allocate new-element-ah var new-element/eax: (addr call-path-element) <- lookup *new-element-ah - # index-in-body - var dest/ecx: (addr int) <- get new-element, index-in-body - var src/edx: int <- copy new - copy-to *dest, src - # next + # save word + var dest/ecx: (addr handle word) <- get new-element, word + copy-object new, dest + # save next var dest2/ecx: (addr handle call-path-element) <- get new-element, next copy-object list, dest2 # return @@ -508,9 +525,11 @@ fn drop-from-call-path-element _list: (addr handle call-path-element) { fn dump-call-path-element screen: (addr screen), _x-ah: (addr handle call-path-element) { $dump-call-path-element:body: { var x-ah/ecx: (addr handle call-path-element) <- copy _x-ah - var x/eax: (addr call-path-element) <- lookup *x-ah - var src/ecx: (addr int) <- get x, index-in-body - print-int32-hex screen, *src + var _x/eax: (addr call-path-element) <- lookup *x-ah + var x/esi: (addr call-path-element) <- copy _x + var word-ah/eax: (addr handle word) <- get x, word + var word/eax: (addr word) <- lookup *word-ah + print-word screen, word var next-ah/ecx: (addr handle call-path-element) <- get x, next var next/eax: (addr call-path-element) <- lookup *next-ah compare next, 0 diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index e444b34c..9b45b43a 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -58,31 +58,12 @@ fn initialize-environment-with-fake-screen _self: (addr environment), nrows: int fn process _self: (addr environment), key: grapheme { $process:body: { var self/esi: (addr environment) <- copy _self - var functions/ecx: (addr handle function) <- get self, functions var sandbox-ah/eax: (addr handle sandbox) <- get self, sandboxes var _sandbox/eax: (addr sandbox) <- lookup *sandbox-ah var sandbox/edi: (addr sandbox) <- copy _sandbox - var cursor-word-storage: (handle word) - var cursor-word-ah/ebx: (addr handle word) <- address cursor-word-storage -#? { -#? print-string 0, "A: line starts with " -#? var line-ah/eax: (addr handle line) <- get sandbox, data -#? var line/eax: (addr line) <- lookup *line-ah -#? var first-word-ah/eax: (addr handle word) <- get line, data -#? var curr-word/eax: (addr word) <- lookup *first-word-ah -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } - get-cursor-word sandbox, functions, cursor-word-ah -#? { -#? print-string 0, "Z: line starts with " -#? var line-ah/eax: (addr handle line) <- get sandbox, data -#? var line/eax: (addr line) <- lookup *line-ah -#? var first-word-ah/eax: (addr handle word) <- get line, data -#? var curr-word/eax: (addr word) <- lookup *first-word-ah -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + var cursor-word-ah/ebx: (addr handle word) <- get cursor-call-path, word var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah var cursor-word/ecx: (addr word) <- copy _cursor-word compare key, 0x445b1b # left-arrow @@ -109,11 +90,19 @@ $process:body: { #? print-string 0, "curr word is expanded\n" var self/ecx: (addr environment) <- copy _self var functions/ecx: (addr handle function) <- get self, functions - var n/eax: int <- body-length functions, cursor-word-ah - n <- decrement - push-to-call-path-element cursor-call-path, n + var body: (handle line) + var body-ah/eax: (addr handle line) <- address body + function-body functions, cursor-word-ah, body-ah + var body-addr/eax: (addr line) <- lookup *body-ah + var first-word-ah/edx: (addr handle word) <- get body-addr, data + var final-word-h: (handle word) + var final-word-ah/eax: (addr handle word) <- address final-word-h + final-word first-word-ah, final-word-ah + push-to-call-path-element cursor-call-path, final-word-ah # move cursor to end of word - get-cursor-word sandbox, functions, cursor-word-ah + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word var cursor-word/eax: (addr word) <- lookup *cursor-word-ah cursor-to-end cursor-word break $process:body @@ -135,8 +124,9 @@ $process:body: { break-if-= $process:key-left-arrow-first-word-and-caller copy-object next-cursor-element-ah, cursor-call-path-ah } - var functions/eax: (addr handle function) <- get self, functions - get-cursor-word sandbox, functions, cursor-word-ah + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah cursor-word <- copy _cursor-word } @@ -203,8 +193,9 @@ $process:body: { break-if-= push-to-call-path-element cursor-call-path, 0 # position cursor at left - var functions/eax: (addr handle function) <- get self, functions - get-cursor-word sandbox, functions, cursor-word-ah + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word var cursor-word/eax: (addr word) <- lookup *cursor-word-ah cursor-to-start cursor-word #? print-string 0, "d\n" @@ -224,7 +215,6 @@ $process:body: { compare key, 2 # ctrl-b $process:prev-word: { break-if-!= -#? print-string 0, "AA\n" # jump to previous word at same level var prev-word-ah/edx: (addr handle word) <- get cursor-word, prev var prev-word/eax: (addr word) <- lookup *prev-word-ah @@ -238,7 +228,6 @@ $process:body: { break $process:body } # if previous word doesn't exist, try to bump up one level -#? print-string 0, "BB\n" { var cursor-call-path-ah/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah @@ -247,13 +236,14 @@ $process:body: { compare caller-cursor-element, 0 break-if-= # check if previous word exists in caller -#? print-string 0, "CC\n" - var caller-index/eax: (addr int) <- get caller-cursor-element, index-in-body - compare *caller-index, 0 - break-if-<= + var caller-word-ah/eax: (addr handle word) <- get caller-cursor-element, word + var caller-word/eax: (addr word) <- lookup *caller-word-ah + var word-before-caller-ah/eax: (addr handle word) <- get caller-word, prev + var word-before-caller/eax: (addr word) <- lookup *word-before-caller-ah + compare word-before-caller, 0 + break-if-= # if so jump to it -#? print-string 0, "DD\n" - copy-object caller-cursor-element-ah, cursor-call-path-ah + drop-from-call-path-element cursor-call-path-ah decrement-final-element cursor-call-path-ah break $process:body } @@ -295,8 +285,9 @@ $process:body: { var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path allocate cursor-call-path-ah # move cursor to start of initial word - var functions/ecx: (addr handle function) <- get self, functions - get-cursor-word sandbox, functions, cursor-word-ah + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + var cursor-word-ah/eax: (addr handle word) <- get cursor-call-path, word var cursor-word/eax: (addr word) <- lookup *cursor-word-ah cursor-to-start cursor-word # this works as long as the first word isn't expanded @@ -307,18 +298,12 @@ $process:body: { $process:end-of-line: { break-if-!= # move cursor to final word of sandbox - var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path-ah/ecx: (addr handle call-path-element) <- get sandbox, cursor-call-path allocate cursor-call-path-ah var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah - var dest/edx: (addr int) <- get cursor-call-path, index-in-body - var line-ah/eax: (addr handle line) <- get sandbox, data - var line/eax: (addr line) <- lookup *line-ah - var n/eax: int <- line-length line - n <- decrement - copy-to *dest, n + var dest/eax: (addr handle word) <- get cursor-call-path, word + final-word dest, dest # move cursor to end of final word - var functions/ecx: (addr handle function) <- get self, functions - get-cursor-word sandbox, functions, cursor-word-ah var cursor-word/eax: (addr word) <- lookup *cursor-word-ah cursor-to-end cursor-word # this works because expanded words lie to the right of their bodies @@ -391,91 +376,6 @@ $process:body: { } } -fn get-cursor-word _sandbox: (addr sandbox), functions: (addr handle function), out: (addr handle word) { - var sandbox/esi: (addr sandbox) <- copy _sandbox - var cursor-call-path/edi: (addr handle call-path-element) <- get sandbox, cursor-call-path - var line/ecx: (addr handle line) <- get sandbox, data -#? { -#? print-string 0, "B: line starts with " -#? var line-ah/eax: (addr handle line) <- get sandbox, data -#? var line/eax: (addr line) <- lookup *line-ah -#? var first-word-ah/eax: (addr handle word) <- get line, data -#? var curr-word/eax: (addr word) <- lookup *first-word-ah -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } - get-word-from-path line, functions, cursor-call-path, out -#? { -#? print-string 0, "Y: line starts with " -#? var line-ah/eax: (addr handle line) <- get sandbox, data -#? var line/eax: (addr line) <- lookup *line-ah -#? var first-word-ah/eax: (addr handle word) <- get line, data -#? var curr-word/eax: (addr word) <- lookup *first-word-ah -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } -} - -fn get-word-from-path _line: (addr handle line), functions: (addr handle function), _path-ah: (addr handle call-path-element), out: (addr handle word) { - # var tmp = line - # if (path->next) - # get-word-from-path(line, functions, path->next, out) - # tmp = function-body(functions, out) - # word-index(tmp, path->index-in-body, out) -#? print-string 0, "C\n" - var tmp: (handle line) - { - var tmp-ah/eax: (addr handle line) <- address tmp - copy-object _line, tmp-ah - } - var path-ah/eax: (addr handle call-path-element) <- copy _path-ah - var _path/eax: (addr call-path-element) <- lookup *path-ah - var path/ecx: (addr call-path-element) <- copy _path - var next-ah/edx: (addr handle call-path-element) <- get path, next - var next/eax: (addr call-path-element) <- lookup *next-ah - { - compare next, 0 - break-if-= - get-word-from-path _line, functions, next-ah, out -#? { -#? print-string 0, "D: line starts with " -#? var line/eax: (addr line) <- lookup *line-ah -#? var words/eax: (addr handle word) <- get line, data -#? var curr-word/eax: (addr word) <- lookup *words -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } - var tmp-ah/eax: (addr handle line) <- address tmp - function-body functions, out, tmp-ah -#? { -#? print-string 0, "G: line starts with " -#? var line/eax: (addr line) <- lookup *line-ah -#? var words/eax: (addr handle word) <- get line, data -#? var curr-word/eax: (addr word) <- lookup *words -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } - # TODO: support multiple levels - } - var n/ecx: (addr int) <- get path, index-in-body - var line/eax: (addr line) <- lookup tmp - var words/eax: (addr handle word) <- get line, data -#? { -#? print-string 0, "M: line starts with " -#? var curr-word/eax: (addr word) <- lookup *words -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } - word-index words, *n, out -#? { -#? print-string 0, "P: line starts with " -#? var curr-word/eax: (addr word) <- lookup *words -#? print-word 0, curr-word -#? print-string 0, "\n" -#? } -#? print-string 0, "X\n" -} - fn word-index _words: (addr handle word), _n: int, out: (addr handle word) { $word-index:body: { var n/ecx: int <- copy _n @@ -573,9 +473,9 @@ fn render-sandbox screen: (addr screen), functions: (addr handle function), bind var _line/eax: (addr line) <- lookup *line-ah var line/ecx: (addr line) <- copy _line # cursor-word - var cursor-word-storage: (handle word) - var cursor-word-ah/eax: (addr handle word) <- address cursor-word-storage - get-cursor-word sandbox, functions, cursor-word-ah + var cursor-call-path-ah/eax: (addr handle call-path-element) <- get sandbox, cursor-call-path + var cursor-call-path/eax: (addr call-path-element) <- lookup *cursor-call-path-ah + 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 # cursor-col @@ -591,6 +491,8 @@ fn render-sandbox screen: (addr screen), functions: (addr handle function), bind var curr-path-storage: (handle call-path-element) var curr-path/esi: (addr handle call-path-element) <- address curr-path-storage allocate curr-path # leak + var sandbox/eax: (addr sandbox) <- copy _sandbox + initialize-path-from-sandbox sandbox, curr-path #? print-string 0, "==\n" var dummy/ecx: int <- render-line screen, functions, 0, line, expanded-words, 3, left-col, curr-path, cursor-word, cursor-call-path, cursor-col-a # input-row=3 var cursor-row/eax: int <- call-depth-at-cursor _sandbox @@ -707,16 +609,6 @@ fn render-line screen: (addr screen), functions: (addr handle function), binding curr-col <- add 2 decrement top-row } - # debug info: print word index -#? decrement top-row -#? move-cursor screen, top-row, curr-col -#? start-color screen, 8, 7 -#? { -#? var word-index-val/eax: int <- final-element-value word-index -#? print-int32-hex-bits screen, word-index-val, 4 -#? } -#? reset-formatting screen -#? increment top-row # render main column var old-col/edx: int <- copy curr-col #? move-cursor 0, debug-row, 1 diff --git a/apps/tile/main.mu b/apps/tile/main.mu index cb6cde68..e9d1066f 100644 --- a/apps/tile/main.mu +++ b/apps/tile/main.mu @@ -74,13 +74,9 @@ fn interactive { fn test { var env-storage: environment var env/esi: (addr environment) <- address env-storage - initialize-environment-with-fake-screen env, 0x30, 0xd4 # 48 rows, 160 columns + initialize-environment-with-fake-screen env, 5, 0xa var g/eax: grapheme <- copy 0x61 # 'a' process env, g - g <- copy 0x61 - process env, g - g <- copy 0x20 - process env, g render env } |