about summary refs log tree commit diff stats
path: root/baremetal/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-01 23:43:25 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-01 23:43:25 -0800
commit89b7ea80a5502dd3f5a611b15d426605c85aba3b (patch)
treec71a0b72e94b924ced1794cbc83a5befdd1a913b /baremetal/shell
parent124be197a0385f21193c404b7575597dfc19a3f2 (diff)
downloadmu-89b7ea80a5502dd3f5a611b15d426605c85aba3b.tar.gz
7839
Diffstat (limited to 'baremetal/shell')
-rw-r--r--baremetal/shell/cell.mu53
-rw-r--r--baremetal/shell/print.mu49
2 files changed, 67 insertions, 35 deletions
diff --git a/baremetal/shell/cell.mu b/baremetal/shell/cell.mu
index aeda65f6..59558fb9 100644
--- a/baremetal/shell/cell.mu
+++ b/baremetal/shell/cell.mu
@@ -21,6 +21,19 @@ fn allocate-symbol _out: (addr handle cell) {
   populate-stream dest-ah, 0x40/max-symbol-size
 }
 
+fn initialize-symbol _out: (addr handle cell), val: (addr array byte) {
+  var out/eax: (addr handle cell) <- copy _out
+  var out-addr/eax: (addr cell) <- lookup *out
+  var dest-ah/eax: (addr handle stream byte) <- get out-addr, text-data
+  var dest/eax: (addr stream byte) <- lookup *dest-ah
+  write dest, val
+}
+
+fn new-symbol out: (addr handle cell), val: (addr array byte) {
+  allocate-symbol out
+  initialize-symbol out, val
+}
+
 fn allocate-number _out: (addr handle cell) {
   var out/eax: (addr handle cell) <- copy _out
   allocate out
@@ -29,8 +42,48 @@ fn allocate-number _out: (addr handle cell) {
   copy-to *type, 1/number
 }
 
+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 src/xmm0: float <- convert n
+  copy-to *dest-ah, src
+}
+
+fn new-integer out: (addr handle cell), n: int {
+  allocate-number out
+  initialize-integer out, n
+}
+
+fn initialize-float _out: (addr handle cell), n: float {
+  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 src/xmm0: float <- copy n
+  copy-to *dest-ah, src
+}
+
+fn new-float out: (addr handle cell), n: float {
+  allocate-number out
+  initialize-float out, n
+}
+
 fn allocate-pair _out: (addr handle cell) {
   var out/eax: (addr handle cell) <- copy _out
   allocate out
   # new cells have type pair by default
 }
+
+fn initialize-pair _out: (addr handle cell), left: (handle cell), right: (handle cell) {
+  var out/eax: (addr handle cell) <- copy _out
+  var out-addr/eax: (addr cell) <- lookup *out
+  var dest-ah/ecx: (addr handle cell) <- get out-addr, left
+  copy-handle left, dest-ah
+  dest-ah <- get out-addr, right
+  copy-handle right, dest-ah
+}
+
+fn new-pair out: (addr handle cell), left: (handle cell), right: (handle cell) {
+  allocate-pair out
+  initialize-pair out, left, right
+}
diff --git a/baremetal/shell/print.mu b/baremetal/shell/print.mu
index da35c049..9c8c719b 100644
--- a/baremetal/shell/print.mu
+++ b/baremetal/shell/print.mu
@@ -144,8 +144,7 @@ fn is-nil? _in: (addr cell) -> _/eax: boolean {
 fn test-print-cell-zero {
   var num-storage: (handle cell)
   var num/esi: (addr handle cell) <- address num-storage
-  allocate-number num
-  # value is 0 by default
+  new-integer num, 0
   var out-storage: (stream byte 0x40)
   var out/edi: (addr stream byte) <- address out-storage
   print-cell num, out, 0/no-trace
@@ -155,11 +154,7 @@ fn test-print-cell-zero {
 fn test-print-cell-integer {
   var num-storage: (handle cell)
   var num/esi: (addr handle cell) <- address num-storage
-  allocate-number num
-  var num-addr/eax: (addr cell) <- lookup *num
-  var num-data/eax: (addr float) <- get num-addr, number-data
-  var src/xmm0: float <- rational 1, 1
-  copy-to *num-data, src
+  new-integer num, 1
   var out-storage: (stream byte 0x40)
   var out/edi: (addr stream byte) <- address out-storage
   print-cell num, out, 0/no-trace
@@ -169,11 +164,7 @@ fn test-print-cell-integer {
 fn test-print-cell-integer-2 {
   var num-storage: (handle cell)
   var num/esi: (addr handle cell) <- address num-storage
-  allocate-number num
-  var num-addr/eax: (addr cell) <- lookup *num
-  var num-data/eax: (addr float) <- get num-addr, number-data
-  var src/xmm0: float <- rational 0x30, 1
-  copy-to *num-data, src
+  new-integer num, 0x30
   var out-storage: (stream byte 0x40)
   var out/edi: (addr stream byte) <- address out-storage
   print-cell num, out, 0/no-trace
@@ -183,11 +174,8 @@ fn test-print-cell-integer-2 {
 fn test-print-cell-fraction {
   var num-storage: (handle cell)
   var num/esi: (addr handle cell) <- address num-storage
-  allocate-number num
-  var num-addr/eax: (addr cell) <- lookup *num
-  var num-data/eax: (addr float) <- get num-addr, number-data
-  var src/xmm0: float <- rational 1, 2
-  copy-to *num-data, src
+  var val/xmm0: float <- rational 1, 2
+  new-float num, val
   var out-storage: (stream byte 0x40)
   var out/edi: (addr stream byte) <- address out-storage
   print-cell num, out, 0/no-trace
@@ -197,11 +185,7 @@ fn test-print-cell-fraction {
 fn test-print-cell-symbol {
   var sym-storage: (handle cell)
   var sym/esi: (addr handle cell) <- address sym-storage
-  allocate-symbol sym
-  var sym-addr/eax: (addr cell) <- lookup *sym
-  var sym-data-ah/eax: (addr handle stream byte) <- get sym-addr, text-data
-  var sym-data/eax: (addr stream byte) <- lookup *sym-data-ah
-  write sym-data, "abc"
+  new-symbol sym, "abc"
   var out-storage: (stream byte 0x40)
   var out/edi: (addr stream byte) <- address out-storage
   print-cell sym, out, 0/no-trace
@@ -219,21 +203,16 @@ fn test-print-cell-nil-list {
 }
 
 fn test-print-cell-singleton-list {
+  # list
+  var left-storage: (handle cell)
+  var left/ecx: (addr handle cell) <- address left-storage
+  new-symbol left, "abc"
+  var nil-storage: (handle cell)
+  var nil/edx: (addr handle cell) <- address nil-storage
+  allocate-pair nil
   var list-storage: (handle cell)
   var list/esi: (addr handle cell) <- address list-storage
-  allocate-pair list
-  # left
-  var list-addr/eax: (addr cell) <- lookup *list
-  var list-left/eax: (addr handle cell) <- get list-addr, left
-  allocate-symbol list-left
-  var sym-addr/eax: (addr cell) <- lookup *list-left
-  var sym-data-ah/eax: (addr handle stream byte) <- get sym-addr, text-data
-  var sym-data/eax: (addr stream byte) <- lookup *sym-data-ah
-  write sym-data, "abc"
-  # right
-  var list-addr/eax: (addr cell) <- lookup *list
-  var list-right/eax: (addr handle cell) <- get list-addr, right
-  allocate-pair list-right
+  new-pair list, *left, *nil
   #
   var out-storage: (stream byte 0x40)
   var out/edi: (addr stream byte) <- address out-storage