about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-12 11:39:28 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-12 11:39:28 -0700
commit6c21568f03cc50462eb5fc7c10b4aabe204f4cc0 (patch)
tree81f31f420be5686c38b36753369ccc2e470bef95
parent598f942624cb162132b7f7c2b7858516d95e73c4 (diff)
downloadmu-6c21568f03cc50462eb5fc7c10b4aabe204f4cc0.tar.gz
7011 - tile: keep garbage out of the stack
-rw-r--r--311decimal-int.subx15
-rw-r--r--apps/tile/environment.mu12
-rw-r--r--apps/tile/main.mu15
3 files changed, 28 insertions, 14 deletions
diff --git a/311decimal-int.subx b/311decimal-int.subx
index 2b69872e..c7c2b03c 100644
--- a/311decimal-int.subx
+++ b/311decimal-int.subx
@@ -1,5 +1,6 @@
 # Helpers for decimal ints.
 
+# if slice doesn't contain a decimal number, return 0
 parse-decimal-int-from-slice:  # in: (addr slice) -> out/eax: int
     # . prologue
     55/push-ebp
@@ -18,6 +19,7 @@ $parse-decimal-int-from-slice:end:
     5d/pop-to-ebp
     c3/return
 
+# if slice doesn't contain a decimal number, return 0
 parse-decimal-int:  # in: (addr array byte) -> result/eax: int
     # . prologue
     55/push-ebp
@@ -110,8 +112,19 @@ $parse-decimal-int-helper:loop:
       # if (curr >= in->end) break
       39/compare %esi 7/r32/edi
       73/jump-if-addr>= break/disp8
-      # digit = from-decimal-char(*curr)
+      # if !is-decimal-digit?(*curr) return 0
       8a/copy-byte *esi 1/r32/CL
+      50/push-eax
+      (is-decimal-digit? %ecx)  # => eax
+      {
+        3d/compare-eax-and 0/imm32/false
+        75/jump-if-!= break/disp8
+        58/pop-to-eax
+        b8/copy-to-eax 0/imm32
+        eb/jump $parse-decimal-int-helper:negate/disp8
+      }
+      58/pop-to-eax
+      # digit = from-decimal-char(*curr)
       81 5/subop/subtract %ecx 0x30/imm32/zero
       # TODO: error checking
       # result = result * 10 + digit
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 58168673..339b6401 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -563,6 +563,9 @@ fn render _env: (addr environment) {
 
 fn render-sandbox screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int {
   var sandbox/esi: (addr sandbox) <- copy _sandbox
+#?   print-string 0, "rendering sandbox from "
+#?   print-int32-decimal 0, left-col
+#?   print-string 0, "\n"
   # expanded-words
   var expanded-words/edi: (addr handle call-path) <- get sandbox, expanded-words
   # line
@@ -714,6 +717,9 @@ fn render-line screen: (addr screen), functions: (addr handle function), binding
 #?     increment top-row
     # render main column
     var old-col/edx: int <- copy curr-col
+#?     print-string 0, "rendering line from "
+#?     print-int32-decimal 0, curr-col
+#?     print-string 0, "\n"
     curr-col <- render-column screen, functions, bindings, line, curr-word, top-row, curr-col
     # cache cursor column if necessary
     $render-line:cache-cursor-column: {
@@ -747,6 +753,9 @@ fn render-column screen: (addr screen), functions: (addr handle function), bindi
     # indent stack
     var indented-col/ebx: int <- copy left-col
     indented-col <- add 1  # margin-right - 2 for padding spaces
+#?     print-string 0, "rendering stack from "
+#?     print-int32-decimal 0, indented-col
+#?     print-string 0, "\n"
     # compute stack
     var stack: value-stack
     var stack-addr/edi: (addr value-stack) <- address stack
@@ -761,6 +770,9 @@ fn render-column screen: (addr screen), functions: (addr handle function), bindi
     {
       compare i, 0
       break-if-<=
+#?       print-string 0, "rendering stack row from "
+#?       print-int32-decimal 0, indented-col
+#?       print-string 0, "\n"
       move-cursor screen, curr-row, indented-col
       {
         var val/eax: int <- pop-int-from-value-stack stack-addr
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index f3e8a34a..573a7457 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -75,20 +75,9 @@ fn test {
   var env-storage: environment
   var env/esi: (addr environment) <- address env-storage
   initialize-environment-with-fake-screen env, 0x30, 0xa0  # 48 rows, 160 columns
-  var g/eax: grapheme <- copy 0x31  # '1'
-  process env, g
-  g <- copy 0x20  # space
-  process env, g
-  g <- copy 0x32  # '2'
-  process env, g
-  g <- copy 0x445b1b  # left-arrow
-  process env, g
-  g <- copy 0x445b1b  # left-arrow
-  process env, g
-  g <- copy 0x445b1b  # left-arrow
-  process env, g
-  g <- copy 5  # <ctrl-e>
+  var g/eax: grapheme <- copy 0x73  # 's'
   process env, g
+  render env
 }
 
 fn repl {