diff options
-rw-r--r-- | apps/tile/data.mu | 64 | ||||
-rw-r--r-- | apps/tile/environment.mu | 33 | ||||
-rw-r--r-- | apps/tile/word.mu | 18 |
3 files changed, 102 insertions, 13 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index 9bf08502..ead9948e 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -385,11 +385,11 @@ fn body-length functions: (addr handle function), function-name: (addr handle wo var body-ah/edi: (addr handle line) <- address body-storage function-body functions, function-name, body-ah var body/eax: (addr line) <- lookup *body-ah - var result/eax: int <- line-length body + var result/eax: int <- num-words-in-line body return result } -fn line-length _in: (addr line) -> _/eax: int { +fn num-words-in-line _in: (addr line) -> _/eax: int { var in/esi: (addr line) <- copy _in var curr-ah/ecx: (addr handle word) <- get in, data var result/edi: int <- copy 0 @@ -699,3 +699,63 @@ fn dump-call-paths screen: (addr screen), _x-ah: (addr handle call-path) { dump-call-paths screen, next-ah } } + +fn function-width _self: (addr function) -> _/eax: int { + var self/esi: (addr function) <- copy _self + var args/ecx: (addr handle word) <- get self, args + var arg-width/eax: int <- word-list-length args + var result/edi: int <- copy arg-width + result <- add 4 # function-header-indent + body-indent + var body-ah/eax: (addr handle line) <- get self, body + var body-width/eax: int <- body-width body-ah + body-width <- add 1 # right margin + body-width <- add 2 # body-indent for "≡ " + compare result, body-width + { + break-if->= + result <- copy body-width + } + return result +} + +fn body-width lines: (addr handle line) -> _/eax: int { + var curr-ah/esi: (addr handle line) <- copy lines + var result/edi: int <- copy 0 + { + var curr/eax: (addr line) <- lookup *curr-ah + compare curr, 0 + break-if-= + { + var words/ecx: (addr handle word) <- get curr, data + var curr-len/eax: int <- word-list-length words + compare curr-len, result + break-if-<= + result <- copy curr-len + } + curr-ah <- get curr, next + loop + } + return result +} + +fn function-height _self: (addr function) -> _/eax: int { + var self/esi: (addr function) <- copy _self + var body-ah/eax: (addr handle line) <- get self, body + var result/eax: int <- line-list-length body-ah + result <- increment # for function header + return result +} + +fn line-list-length lines: (addr handle line) -> _/eax: int { + var curr-ah/esi: (addr handle line) <- copy lines + var result/edi: int <- copy 0 + { + var curr/eax: (addr line) <- lookup *curr-ah + compare curr, 0 + break-if-= + curr-ah <- get curr, next + result <- increment + loop + } + return result +} diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 28a4d731..853264ce 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -1537,6 +1537,7 @@ fn render-primitives screen: (addr screen), bottom-margin-row: int, right-col: i move-cursor screen, row, 1 start-bold screen print-string screen, "primitives:" + reset-formatting screen return row } @@ -1571,27 +1572,38 @@ fn render-primitive-group screen: (addr screen), _row: int, _col: int, right-col } fn render-functions screen: (addr screen), right-col: int, _env: (addr environment) { - var left-col/ecx: int <- copy right-col - left-col <- subtract 0x28 - move-cursor screen, 8, left-col - print-string screen, "functions:" - left-col <- add 2 - var row/ebx: int <- copy 9 + var row/ecx: int <- copy 1 + var dummy-col/edx: int <- copy right-col var env/esi: (addr environment) <- copy _env var functions/esi: (addr handle function) <- get env, functions { var curr/eax: (addr function) <- lookup *functions compare curr, 0 break-if-= - row <- render-function screen, row, left-col, curr + row, dummy-col <- render-function-right-aligned screen, row, right-col, curr functions <- get curr, next - row <- increment + row <- add 1 # inter-function-margin loop } } +# print function starting at row, right-aligned before right-col +# return row, col printed until +fn render-function-right-aligned screen: (addr screen), row: int, right-col: int, f: (addr function) -> _/ecx: int, _/edx: int { + var col/edx: int <- copy right-col + col <- decrement # margin + var width/eax: int <- function-width f + col <- subtract width + render-function screen, row, col, f + var new-row/ecx: int <- copy row + var height/eax: int <- function-height f + new-row <- add height + return new-row, col +} + +# render function starting at row, col # only single-line functions supported for now -fn render-function screen: (addr screen), row: int, col: int, _f: (addr function) -> _/ebx: int { +fn render-function screen: (addr screen), row: int, col: int, _f: (addr function) { var f/esi: (addr function) <- copy _f var args/ecx: (addr handle word) <- get f, args move-cursor screen, row, col @@ -1604,12 +1616,11 @@ fn render-function screen: (addr screen), row: int, col: int, _f: (addr function increment row add-to col, 2 move-cursor screen, row, col - print-string screen, "= " + print-string screen, "≡ " var body-ah/eax: (addr handle line) <- get f, body var body/eax: (addr line) <- lookup *body-ah var body-words-ah/eax: (addr handle word) <- get body, data print-words screen, body-words-ah - return row } fn real-grapheme? g: grapheme -> _/eax: boolean { diff --git a/apps/tile/word.mu b/apps/tile/word.mu index e01c8353..69142234 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -553,3 +553,21 @@ fn word-exists? _haystack-ah: (addr handle word), _needle: (addr word) -> _/ebx: var result/ebx: boolean <- word-exists? next-haystack-ah, _needle return result } + +fn word-list-length words: (addr handle word) -> _/eax: int { + var curr-ah/esi: (addr handle word) <- copy words + var result/edi: int <- copy 0 + { + var curr/eax: (addr word) <- lookup *curr-ah + compare curr, 0 + break-if-= + { + var word-len/eax: int <- word-length curr + result <- add word-len + result <- add 1 # inter-word-margin + } + curr-ah <- get curr, next + loop + } + return result +} |