about summary refs log tree commit diff stats
path: root/baremetal/shell/value.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-12 23:18:33 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-12 23:49:00 -0800
commit378ffca74c7a1428431da5d4572b70731d41074d (patch)
treebea0d3e0571d5350ab928e66de656b2ff2a49f4b /baremetal/shell/value.mu
parent97a77434c5950d7a491f77ec2543fcad3157c460 (diff)
downloadmu-378ffca74c7a1428431da5d4572b70731d41074d.tar.gz
7730 - baremetal/shell: boolean values
In the process I found a bug in the Mu compiler. Limitations of just asserting
the emitted code but not running it.
Diffstat (limited to 'baremetal/shell/value.mu')
-rw-r--r--baremetal/shell/value.mu29
1 files changed, 29 insertions, 0 deletions
diff --git a/baremetal/shell/value.mu b/baremetal/shell/value.mu
index 4a93227e..5b5ec142 100644
--- a/baremetal/shell/value.mu
+++ b/baremetal/shell/value.mu
@@ -4,6 +4,7 @@ type value {
   number-data: float  # if type = 0
   text-data: (handle array byte)  # if type = 1
   array-data: (handle array value)  # if type = 2
+  boolean-data: boolean  # if type = 3
 }
 
 # top-level? is a hack just for numbers
@@ -29,6 +30,13 @@ fn render-value screen: (addr screen), _val: (addr value), x: int, y: int, top-l
     var new-x/eax: int <- render-array screen, val-array, x, y
     return new-x
   }
+  compare *val-type, 3/boolean
+  {
+    break-if-!=
+    var val/eax: (addr boolean) <- get val, boolean-data
+    var new-x/eax: int <- render-boolean screen, *val, x, y
+    return new-x
+  }
   # render ints by default for now
   var val-num/eax: (addr float) <- get val, number-data
   var new-x/eax: int <- render-number screen, *val-num, x, y, top-level?
@@ -232,3 +240,24 @@ fn test-render-array {
   check-screen-row screen, 0/y, "[0 1 2]", "F - test-render-array"
   check-ints-equal new-x, 7, "F - test-render-array: result"
 }
+
+fn initialize-value-with-boolean _self: (addr value), _b: boolean {
+  var self/esi: (addr value) <- copy _self
+  var type/eax: (addr int) <- get self, type
+  copy-to *type, 3/boolean
+  var dest/edi: (addr boolean) <- get self, boolean-data
+  var b/esi: boolean <- copy _b
+  copy-to *dest, b
+}
+
+fn render-boolean screen: (addr screen), val: boolean, x: int, y: int -> _/eax: int {
+  var new-x/eax: int <- copy 0
+  compare val, 0/false
+  {
+    break-if-=
+    new-x <- draw-text-rightward-over-full-screen screen, "true", new-x, y, 7/fg, 0/bg
+    return new-x
+  }
+  new-x <- draw-text-rightward-over-full-screen screen, "false", new-x, y, 7/fg, 0/bg
+  return new-x
+}