From e2f18e8866bd75669c04bff52c3f8e96d13eeb4e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 28 Jul 2021 23:28:29 -0700 Subject: shell: literal images --- shell/evaluate.mu | 28 ++++++++++++++++++++++++++++ shell/macroexpand.mu | 9 +++++++++ shell/print.mu | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'shell') diff --git a/shell/evaluate.mu b/shell/evaluate.mu index 932a0fa5..c78f1e23 100644 --- a/shell/evaluate.mu +++ b/shell/evaluate.mu @@ -171,6 +171,20 @@ fn evaluate _in-ah: (addr handle cell), _out-ah: (addr handle cell), env-h: (han trace-higher trace return } + $evaluate:literal-image: { + # trees starting with "litimg" are literals + var expr/esi: (addr cell) <- copy in + var in/edx: (addr cell) <- copy in + var first-ah/ecx: (addr handle cell) <- get in, left + var first/eax: (addr cell) <- lookup *first-ah + var litimg?/eax: boolean <- litimg? first + compare litimg?, 0/false + break-if-= + trace-text trace, "eval", "literal image" + copy-object _in-ah, _out-ah + trace-higher trace + return + } $evaluate:anonymous-function: { # trees starting with "fn" are anonymous functions var expr/esi: (addr cell) <- copy in @@ -1546,6 +1560,20 @@ fn litmac? _x: (addr cell) -> _/eax: boolean { return result } +fn litimg? _x: (addr cell) -> _/eax: boolean { + var x/esi: (addr cell) <- copy _x + var type/eax: (addr int) <- get x, type + compare *type, 2/symbol + { + break-if-= + return 0/false + } + var contents-ah/eax: (addr handle stream byte) <- get x, text-data + var contents/eax: (addr stream byte) <- lookup *contents-ah + var result/eax: boolean <- stream-data-equal? contents, "litimg" + return result +} + fn test-evaluate-is-well-behaved { var t-storage: trace var t/esi: (addr trace) <- address t-storage diff --git a/shell/macroexpand.mu b/shell/macroexpand.mu index f65ead85..6cfae474 100644 --- a/shell/macroexpand.mu +++ b/shell/macroexpand.mu @@ -103,6 +103,15 @@ fn macroexpand-iter _expr-ah: (addr handle cell), globals: (addr global-table), trace-higher trace return 0/false } + { + var litimg?/eax: boolean <- litimg? first + compare litimg?, 0/false + break-if-= + # litimg is a literal + trace-text trace, "mac", "literal image" + trace-higher trace + return 0/false + } var result/edi: boolean <- copy 0/false # for each builtin, expand only what will later be evaluated $macroexpand-iter:anonymous-function: { diff --git a/shell/print.mu b/shell/print.mu index 470ceae3..90e4a832 100644 --- a/shell/print.mu +++ b/shell/print.mu @@ -235,7 +235,7 @@ fn print-stream _in: (addr cell), out: (addr stream byte), trace: (addr trace) { compare should-trace?, 0/false break-if-= rewind-stream data - var stream-storage: (stream byte 0x40) + var stream-storage: (stream byte 0x400) var stream/ecx: (addr stream byte) <- address stream-storage write stream, "=> stream " write-stream-immutable stream, data -- cgit 1.4.1-2-gfad0