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-25 16:18:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-25 16:24:45 -0700
commit17e50d27d4842048d17704df1be292c42e2d5506 (patch)
tree92c6e5a16f7ab55bb9d230a1e32bf3851999826b /shell/cell.mu
parent7ed4a6aed94bbf80a6e4ed3017382a58feb5cd10 (diff)
downloadmu-17e50d27d4842048d17704df1be292c42e2d5506.tar.gz
shell: array type
Diffstat (limited to 'shell/cell.mu')
-rw-r--r--shell/cell.mu25
1 files changed, 24 insertions, 1 deletions
diff --git a/shell/cell.mu b/shell/cell.mu
index 57ea0110..79a9fb17 100644
--- a/shell/cell.mu
+++ b/shell/cell.mu
@@ -14,7 +14,9 @@ type cell {
   screen-data: (handle screen)
   # type 6: keyboard
   keyboard-data: (handle gap-buffer)
-  # TODO: array, (associative) table
+  # type 7: array
+  array-data: (handle array handle cell)
+  # TODO: (associative) table
   # if you add types here, don't forget to update cell-isomorphic?
 }
 
@@ -272,3 +274,24 @@ fn rewind-keyboard-var _self-ah: (addr handle cell) {
   var keyboard/eax: (addr gap-buffer) <- lookup *keyboard-ah
   rewind-gap-buffer keyboard
 }
+
+fn new-array _out: (addr handle cell), capacity: int {
+  var out/eax: (addr handle cell) <- copy _out
+  allocate out
+  var out-addr/eax: (addr cell) <- lookup *out
+  var type/ecx: (addr int) <- get out-addr, type
+  copy-to *type, 7/array
+  var dest-ah/eax: (addr handle array handle cell) <- get out-addr, array-data
+  populate dest-ah, capacity
+}
+
+fn array? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 7/array
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}