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-03-05 09:27:15 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-05 09:30:15 -0800
commite4fc67ee44cda0769ce4d1e844ff8b5b4a937491 (patch)
treef0651a5503eae14283fffb9146ab85f4e7b53691 /shell/cell.mu
parentd3b508b16c4114d05ee93d352e9a1af3c9c9b033 (diff)
downloadmu-e4fc67ee44cda0769ce4d1e844ff8b5b4a937491.tar.gz
7856 - shell: primitive functions
Diffstat (limited to 'shell/cell.mu')
-rw-r--r--shell/cell.mu27
1 files changed, 25 insertions, 2 deletions
diff --git a/shell/cell.mu b/shell/cell.mu
index 59558fb9..d9e95ce6 100644
--- a/shell/cell.mu
+++ b/shell/cell.mu
@@ -8,6 +8,8 @@ type cell {
   # type 2: symbol
   # type 3: string
   text-data: (handle stream byte)
+  # type 4: primitive function
+  index-data: int
   # TODO: array, (associative) table, stream
 }
 
@@ -45,9 +47,9 @@ fn allocate-number _out: (addr handle cell) {
 fn initialize-integer _out: (addr handle cell), n: int {
   var out/eax: (addr handle cell) <- copy _out
   var out-addr/eax: (addr cell) <- lookup *out
-  var dest-ah/eax: (addr float) <- get out-addr, number-data
+  var dest-addr/eax: (addr float) <- get out-addr, number-data
   var src/xmm0: float <- convert n
-  copy-to *dest-ah, src
+  copy-to *dest-addr, src
 }
 
 fn new-integer out: (addr handle cell), n: int {
@@ -87,3 +89,24 @@ fn new-pair out: (addr handle cell), left: (handle cell), right: (handle cell) {
   allocate-pair out
   initialize-pair out, left, right
 }
+
+fn allocate-primitive-function _out: (addr handle cell) {
+  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, 4/primitive-function
+}
+
+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 dest-addr/eax: (addr int) <- get out-addr, index-data
+  var src/ecx: int <- copy n
+  copy-to *dest-addr, src
+}
+
+fn new-primitive-function out: (addr handle cell), n: int {
+  allocate-primitive-function out
+  initialize-primitive-function out, n
+}