about summary refs log tree commit diff stats
path: root/shell/cell.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-27 22:37:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-27 22:38:26 -0700
commit267c74b59a5f148bd28233f25bc794a3a4893e8e (patch)
tree0b583a305e2fe13edb477d88d15ac0be5a43dbd2 /shell/cell.mu
parent619944524382bee5fb10efae2273e6cc57fbd421 (diff)
downloadmu-267c74b59a5f148bd28233f25bc794a3a4893e8e.tar.gz
shell: render image from pbm data stream
Diffstat (limited to 'shell/cell.mu')
-rw-r--r--shell/cell.mu25
1 files changed, 25 insertions, 0 deletions
diff --git a/shell/cell.mu b/shell/cell.mu
index 79a9fb17..ada86a29 100644
--- a/shell/cell.mu
+++ b/shell/cell.mu
@@ -16,6 +16,8 @@ type cell {
   keyboard-data: (handle gap-buffer)
   # type 7: array
   array-data: (handle array handle cell)
+  # type 8: image
+  image-data: (handle image)
   # TODO: (associative) table
   # if you add types here, don't forget to update cell-isomorphic?
 }
@@ -295,3 +297,26 @@ fn array? _x: (addr cell) -> _/eax: boolean {
   }
   return 1/true
 }
+
+fn new-image _out-ah: (addr handle cell), in: (addr stream byte) {
+  var out-ah/eax: (addr handle cell) <- copy _out-ah
+  allocate out-ah
+  var out/eax: (addr cell) <- lookup *out-ah
+  var type/ecx: (addr int) <- get out, type
+  copy-to *type, 8/image
+  var dest-ah/eax: (addr handle image) <- get out, image-data
+  allocate dest-ah
+  var dest/eax: (addr image) <- lookup *dest-ah
+  initialize-image dest, in
+}
+
+fn image? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 8/image
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}