diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-05-07 09:22:54 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-05-07 09:22:54 -0700 |
commit | 7105b73fd3f0952a62de125ee70fe81a9ae683fd (patch) | |
tree | 412b991600b0b34c9dd025f2b91919636fbd51b0 /shell | |
parent | f791cd9da9472d2ec81525a440dca68a54e9a6a4 (diff) | |
download | mu-7105b73fd3f0952a62de125ee70fe81a9ae683fd.tar.gz |
give up on nested backquotes for now
Diffstat (limited to 'shell')
-rw-r--r-- | shell/macroexpand.mu | 81 | ||||
-rw-r--r-- | shell/tokenize.mu | 8 |
2 files changed, 82 insertions, 7 deletions
diff --git a/shell/macroexpand.mu b/shell/macroexpand.mu index 48d9bf92..2003c8a4 100644 --- a/shell/macroexpand.mu +++ b/shell/macroexpand.mu @@ -122,7 +122,16 @@ fn macroexpand-iter _expr-ah: (addr handle cell), globals: (addr global-table), trace-higher trace return 0/false } - # TODO: expand within backquotes + $macroexpand-iter:backquote: { + # nested backquote not supported for now + var backquote?/eax: boolean <- symbol-equal? first, "`" + compare backquote?, 0/false + break-if-= + # + error trace, "nested backquote not supported yet" + trace-higher trace + return 0/false + } $macroexpand-iter:def: { # trees starting with "def" define globals var def?/eax: boolean <- symbol-equal? first, "def" @@ -311,3 +320,73 @@ fn test-macroexpand-inside-fn-call { var assertion/eax: boolean <- cell-isomorphic? result, expected, 0/no-trace check assertion, "F - test-macroexpand-inside-fn-call" } + +fn pending-test-macroexpand-inside-backquote-unquote { + var globals-storage: global-table + var globals/edx: (addr global-table) <- address globals-storage + initialize-globals globals + # new macro: m + var sandbox-storage: sandbox + var sandbox/esi: (addr sandbox) <- address sandbox-storage + initialize-sandbox-with sandbox, "(def m (litmac litfn () (a b) `(+ ,a ,b)))" + edit-sandbox sandbox, 0x13/ctrl-s, globals, 0/no-disk, 0/no-screen, 0/no-tweak-screen + # invoke macro + initialize-sandbox-with sandbox, "`(print [result is ] ,(m 3 4)))" + var gap-ah/ecx: (addr handle gap-buffer) <- get sandbox, data + var gap/eax: (addr gap-buffer) <- lookup *gap-ah + var result-h: (handle cell) + var result-ah/ebx: (addr handle cell) <- address result-h + read-cell gap, result-ah, 0/no-trace + var dummy/eax: boolean <- macroexpand-iter result-ah, globals, 0/no-trace + dump-cell-from-cursor-over-full-screen result-ah + var _result/eax: (addr cell) <- lookup *result-ah + var result/edi: (addr cell) <- copy _result + # expected + initialize-sandbox-with sandbox, "`(print [result is ] ,(+ 3 4)))" + var expected-gap-ah/ecx: (addr handle gap-buffer) <- get sandbox, data + var expected-gap/eax: (addr gap-buffer) <- lookup *expected-gap-ah + var expected-h: (handle cell) + var expected-ah/ecx: (addr handle cell) <- address expected-h + read-cell expected-gap, expected-ah, 0/no-trace + dump-cell-from-cursor-over-full-screen expected-ah + var expected/eax: (addr cell) <- lookup *expected-ah + # + var assertion/eax: boolean <- cell-isomorphic? result, expected, 0/no-trace + check assertion, "F - test-macroexpand-inside-backquote-unquote" +} + +fn pending-test-macroexpand-inside-nested-backquote-unquote { + var globals-storage: global-table + var globals/edx: (addr global-table) <- address globals-storage + initialize-globals globals + # new macro: m + var sandbox-storage: sandbox + var sandbox/esi: (addr sandbox) <- address sandbox-storage + initialize-sandbox-with sandbox, "(def m (litmac litfn () (a b) `(+ ,a ,b)))" + edit-sandbox sandbox, 0x13/ctrl-s, globals, 0/no-disk, 0/no-screen, 0/no-tweak-screen + # invoke macro + initialize-sandbox-with sandbox, "`(a ,(m 3 4) `(b ,(m 3 4) ,,(m 3 4)))" + var gap-ah/ecx: (addr handle gap-buffer) <- get sandbox, data + var gap/eax: (addr gap-buffer) <- lookup *gap-ah + var result-h: (handle cell) + var result-ah/ebx: (addr handle cell) <- address result-h + read-cell gap, result-ah, 0/no-trace + var dummy/eax: boolean <- macroexpand-iter result-ah, globals, 0/no-trace + dump-cell-from-cursor-over-full-screen result-ah + var _result/eax: (addr cell) <- lookup *result-ah + var result/edi: (addr cell) <- copy _result + # expected + initialize-sandbox-with sandbox, "`(a ,(+ 3 4) `(b ,(m 3 4) ,,(+ 3 4)))" + var expected-gap-ah/ecx: (addr handle gap-buffer) <- get sandbox, data + var expected-gap/eax: (addr gap-buffer) <- lookup *expected-gap-ah + var expected-h: (handle cell) + var expected-ah/ecx: (addr handle cell) <- address expected-h + read-cell expected-gap, expected-ah, 0/no-trace + dump-cell-from-cursor-over-full-screen expected-ah + var expected/eax: (addr cell) <- lookup *expected-ah + # + var assertion/eax: boolean <- cell-isomorphic? result, expected, 0/no-trace + check assertion, "F - test-macroexpand-inside-nested-backquote-unquote" +} + +# TODO: unquote-splice, nested and unnested diff --git a/shell/tokenize.mu b/shell/tokenize.mu index 0ec4d57c..ed05b2de 100644 --- a/shell/tokenize.mu +++ b/shell/tokenize.mu @@ -9,19 +9,16 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace) var token-storage: cell var token/edx: (addr cell) <- address token-storage { -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "a", 7/fg 0/bg skip-whitespace-from-gap-buffer in var done?/eax: boolean <- gap-buffer-scan-done? in compare done?, 0/false break-if-!= -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "b", 7/fg 0/bg # initialize token data each iteration to avoid aliasing var dest-ah/eax: (addr handle stream byte) <- get token, text-data + # I'm allocating 1KB for every. single. token. Just because a whole definition needs to fit in a string sometimes. Absolutely bonkers. populate-stream dest-ah, 0x400/max-definition-size # -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "c", 7/fg 0/bg next-token in, token, trace -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "d", 7/fg 0/bg var skip?/eax: boolean <- comment-token? token compare skip?, 0/false loop-if-!= @@ -31,9 +28,7 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace) break-if-= return } -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "y", 7/fg 0/bg write-to-stream out, token # shallow-copy text-data -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen "z", 7/fg 0/bg loop } trace-higher trace @@ -319,6 +314,7 @@ fn next-token in: (addr gap-buffer), _out-cell: (addr cell), trace: (addr trace) } break $next-token:body } + abort "unknown token type" } trace-higher trace var stream-storage: (stream byte 0x400) # maximum possible token size (next-stream-token) |