about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-28 23:28:29 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-28 23:28:29 -0700
commite2f18e8866bd75669c04bff52c3f8e96d13eeb4e (patch)
tree129495b1009aa08f7715c5d58f6eba8fcad7e566 /shell
parente2f6e9011eb64b9f2372dbed6ed3838ce8e26ec0 (diff)
downloadmu-e2f18e8866bd75669c04bff52c3f8e96d13eeb4e.tar.gz
shell: literal images
Diffstat (limited to 'shell')
-rw-r--r--shell/evaluate.mu28
-rw-r--r--shell/macroexpand.mu9
-rw-r--r--shell/print.mu2
3 files changed, 38 insertions, 1 deletions
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