about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-19 20:05:00 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-19 20:05:00 -0700
commit4b5a6f6c30f4c95fc339b54a9d0a70e685b18e7c (patch)
treebf7b37a5c8774de86f8073ea9f4b82e05cb88001 /shell
parent8be28fdd4630e8457cfcebe19dac2e3aa68712d3 (diff)
downloadmu-4b5a6f6c30f4c95fc339b54a9d0a70e685b18e7c.tar.gz
.
Diffstat (limited to 'shell')
-rw-r--r--shell/cell.mu68
-rw-r--r--shell/environment.mu6
2 files changed, 71 insertions, 3 deletions
diff --git a/shell/cell.mu b/shell/cell.mu
index a65402ce..57ea0110 100644
--- a/shell/cell.mu
+++ b/shell/cell.mu
@@ -41,6 +41,17 @@ fn new-symbol out: (addr handle cell), val: (addr array byte) {
   initialize-symbol out, val
 }
 
+fn symbol? _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
+  }
+  return 1/true
+}
+
 fn symbol-equal? _in: (addr cell), name: (addr array byte) -> _/eax: boolean {
   var in/esi: (addr cell) <- copy _in
   var in-type/eax: (addr int) <- get in, type
@@ -99,6 +110,17 @@ fn new-float out: (addr handle cell), n: float {
   initialize-float out, n
 }
 
+fn number? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 1/number
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}
+
 fn allocate-pair out: (addr handle cell) {
   allocate out
   # new cells have type pair by default
@@ -122,6 +144,17 @@ fn nil out: (addr handle cell) {
   allocate-pair out
 }
 
+fn pair? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 0/pair
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}
+
 fn allocate-primitive-function _out: (addr handle cell) {
   var out/eax: (addr handle cell) <- copy _out
   allocate out
@@ -133,6 +166,8 @@ fn allocate-primitive-function _out: (addr handle cell) {
 fn initialize-primitive-function _out: (addr handle cell), n: int {
   var out/eax: (addr handle cell) <- copy _out
   var out-addr/eax: (addr cell) <- lookup *out
+  var type/ecx: (addr int) <- get out-addr, type
+  copy-to *type, 4/primitive
   var dest-addr/eax: (addr int) <- get out-addr, index-data
   var src/ecx: int <- copy n
   copy-to *dest-addr, src
@@ -143,6 +178,17 @@ fn new-primitive-function out: (addr handle cell), n: int {
   initialize-primitive-function out, n
 }
 
+fn primitive? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 4/primitive
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}
+
 fn allocate-screen _out: (addr handle cell) {
   var out/eax: (addr handle cell) <- copy _out
   allocate out
@@ -161,6 +207,17 @@ fn new-fake-screen _out: (addr handle cell), width: int, height: int, pixel-grap
   initialize-screen dest-addr, width, height, pixel-graphics?
 }
 
+fn screen? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 5/screen
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}
+
 fn clear-screen-var _self-ah: (addr handle cell) {
   var self-ah/eax: (addr handle cell) <- copy _self-ah
   var self/eax: (addr cell) <- lookup *self-ah
@@ -192,6 +249,17 @@ fn new-fake-keyboard _out: (addr handle cell), capacity: int {
   initialize-gap-buffer dest-addr, capacity
 }
 
+fn keyboard? _x: (addr cell) -> _/eax: boolean {
+  var x/esi: (addr cell) <- copy _x
+  var type/eax: (addr int) <- get x, type
+  compare *type, 6/keyboard
+  {
+    break-if-=
+    return 0/false
+  }
+  return 1/true
+}
+
 fn rewind-keyboard-var _self-ah: (addr handle cell) {
   var self-ah/eax: (addr handle cell) <- copy _self-ah
   var self/eax: (addr cell) <- lookup *self-ah
diff --git a/shell/environment.mu b/shell/environment.mu
index 51256d02..688590dd 100644
--- a/shell/environment.mu
+++ b/shell/environment.mu
@@ -285,9 +285,9 @@ fn edit-environment _self: (addr environment), key: grapheme, data-disk: (addr d
         var curr/ebx: (addr global) <- index global-data, curr-offset
         var curr-value-ah/eax: (addr handle cell) <- get curr, value
         var curr-value/eax: (addr cell) <- lookup *curr-value-ah
-        var curr-type/eax: (addr int) <- get curr-value, type
-        compare *curr-type, 4/primitive
-        break-if-!=
+        var primitive?/eax: boolean <- primitive? curr-value
+        compare primitive?, 0/false
+        break-if-=
         var go-modal-error-ah/eax: (addr handle array byte) <- get self, go-modal-error
         copy-array-object "sorry, primitives can't be edited yet", go-modal-error-ah
         return