about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-25 18:45:11 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-25 18:45:11 -0700
commita148b23a22709a45647fd07ce95db9147217a061 (patch)
treedb95e96fbb4a1da518f25bcda5cf863b34ecb4a1
parent8a6ad45d8d26c60b62a2a7ac8d594b3c4d1dbc45 (diff)
downloadmu-a148b23a22709a45647fd07ce95db9147217a061.tar.gz
7101 - tile: remove quotes when evaluating strings
This found several bugs due to me not checking for null strings.
-rw-r--r--108write.subx3
-rw-r--r--310copy-bytes.subx41
-rw-r--r--400.mu1
-rwxr-xr-xapps/assortbin46532 -> 46541 bytes
-rwxr-xr-xapps/bracesbin48587 -> 48596 bytes
-rwxr-xr-xapps/callsbin53438 -> 53447 bytes
-rwxr-xr-xapps/crenshaw2-1bin45873 -> 45882 bytes
-rwxr-xr-xapps/crenshaw2-1bbin46420 -> 46429 bytes
-rwxr-xr-xapps/dquotesbin50154 -> 50163 bytes
-rwxr-xr-xapps/factorialbin44976 -> 44985 bytes
-rwxr-xr-xapps/hexbin48712 -> 48721 bytes
-rwxr-xr-xapps/mubin422010 -> 422150 bytes
-rwxr-xr-xapps/packbin59222 -> 59231 bytes
-rwxr-xr-xapps/sigilsbin60956 -> 60965 bytes
-rwxr-xr-xapps/surveybin56464 -> 56473 bytes
-rwxr-xr-xapps/testsbin45323 -> 45332 bytes
-rw-r--r--apps/tile/main.mu7
-rw-r--r--apps/tile/rpn.mu2
-rw-r--r--apps/tile/value-stack.mu2
19 files changed, 49 insertions, 7 deletions
diff --git a/108write.subx b/108write.subx
index 988e21db..84060c62 100644
--- a/108write.subx
+++ b/108write.subx
@@ -25,6 +25,9 @@ write:  # f: fd or (addr stream byte), s: (addr array byte)
     # . prologue
     55/push-ebp
     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+    # if (s == 0) return
+    81          7/subop/compare     1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       0/imm32           # compare *(ebp+12)
+    74/jump-if-=  $write:end/disp8
     # if (f < 0x08000000) _write(f, s) and return  # f can't be a user-mode address, so treat it as a kernel file descriptor
     81          7/subop/compare     1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         0x08000000/imm32  # compare *(ebp+8)
     73/jump-if-addr>=  $write:fake/disp8
diff --git a/310copy-bytes.subx b/310copy-bytes.subx
index 7a90495b..eed337c0 100644
--- a/310copy-bytes.subx
+++ b/310copy-bytes.subx
@@ -113,3 +113,44 @@ test-stream-to-string:
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
     c3/return
+
+# like stream-to-string but ignore surrounding quotes
+# we might do other stuff here later
+unquote-stream-to-string:  # in: (addr stream _), out: (addr handle array _)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    52/push-edx
+    56/push-esi
+    # esi = s
+    8b/-> *(ebp+8) 6/r32/esi
+    # var len/ecx: int = s->write - s->read - 2
+    8b/-> *esi 1/r32/ecx
+    2b/subtract *(esi+4) 1/r32/ecx
+    81 7/subop/compare %ecx 2/imm32
+    7c/jump-if-< $unquote-stream-to-string:end/disp8
+    81 5/subop/subtract %ecx 2/imm32
+    # allocate
+    (allocate-array Heap %ecx *(ebp+0xc))
+    # var in/edx: (addr byte) = s->data + s->read + 1
+    8b/-> *(esi+4) 2/r32/edx
+    8d/copy-address *(esi+edx+0xd) 2/r32/edx  # Stream-data + 1
+    # var dest/eax: (addr byte) = data for out
+    8b/-> *(ebp+0xc) 0/r32/eax
+    (lookup *eax *(eax+4))  # => eax
+    8d/copy-address *(eax+4) 0/r32/eax
+    #
+    (copy-bytes %edx %eax %ecx)
+$unquote-stream-to-string:end:
+    # . restore registers
+    5e/pop-to-esi
+    5a/pop-to-edx
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
diff --git a/400.mu b/400.mu
index fb686e17..35fc88f0 100644
--- a/400.mu
+++ b/400.mu
@@ -177,6 +177,7 @@ sig new-buffered-file out: (addr handle buffered-file)
 sig stream-empty? s: (addr stream _) -> result/eax: boolean
 sig stream-full? s: (addr stream _) -> result/eax: boolean
 sig stream-to-string in: (addr stream _), out: (addr handle array _)
+sig unquote-stream-to-string in: (addr stream _), out: (addr handle array _)
 sig stream-first s: (addr stream byte) -> result/eax: byte
 sig stream-final s: (addr stream byte) -> result/eax: byte
 
diff --git a/apps/assort b/apps/assort
index b96e8bce..91e7ff23 100755
--- a/apps/assort
+++ b/apps/assort
Binary files differdiff --git a/apps/braces b/apps/braces
index 658a2906..0a07736c 100755
--- a/apps/braces
+++ b/apps/braces
Binary files differdiff --git a/apps/calls b/apps/calls
index ca22ce03..d5637096 100755
--- a/apps/calls
+++ b/apps/calls
Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1
index 0b69e083..37f7b355 100755
--- a/apps/crenshaw2-1
+++ b/apps/crenshaw2-1
Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b
index 587b2655..75639828 100755
--- a/apps/crenshaw2-1b
+++ b/apps/crenshaw2-1b
Binary files differdiff --git a/apps/dquotes b/apps/dquotes
index 71aac388..30d28e67 100755
--- a/apps/dquotes
+++ b/apps/dquotes
Binary files differdiff --git a/apps/factorial b/apps/factorial
index c5676040..ebb0ba62 100755
--- a/apps/factorial
+++ b/apps/factorial
Binary files differdiff --git a/apps/hex b/apps/hex
index 501feb40..198276d7 100755
--- a/apps/hex
+++ b/apps/hex
Binary files differdiff --git a/apps/mu b/apps/mu
index d713a6eb..236b5d2a 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/pack b/apps/pack
index 79c773fb..070d0060 100755
--- a/apps/pack
+++ b/apps/pack
Binary files differdiff --git a/apps/sigils b/apps/sigils
index d464f947..b6220832 100755
--- a/apps/sigils
+++ b/apps/sigils
Binary files differdiff --git a/apps/survey b/apps/survey
index 24a7a699..893eb4f2 100755
--- a/apps/survey
+++ b/apps/survey
Binary files differdiff --git a/apps/tests b/apps/tests
index f49cff1a..f43185f8 100755
--- a/apps/tests
+++ b/apps/tests
Binary files differdiff --git a/apps/tile/main.mu b/apps/tile/main.mu
index d4f53535..08e6532b 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -77,12 +77,7 @@ fn test {
   initialize-environment-with-fake-screen env, 5, 0xa
   var g/eax: grapheme <- copy 0x22  # '"'
   process env, g
-  g <- copy 0x31  # '1'
-  process env, g
-  g <- copy 0x20  # space
-  process env, g
-  g <- copy 0x33  # '3'
-  process env, g
+  render env
 }
 
 fn repl {
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index 80ab47ae..cf0766b0 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -109,7 +109,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         break-if-!=
         var h: (handle array byte)
         var s/eax: (addr handle array byte) <- address h
-        stream-to-string curr-stream, s  # leak
+        unquote-stream-to-string curr-stream, s  # leak
         push-string-to-value-stack out, *s
         break $evaluate:process-word
       }
diff --git a/apps/tile/value-stack.mu b/apps/tile/value-stack.mu
index aae87c3d..7050442d 100644
--- a/apps/tile/value-stack.mu
+++ b/apps/tile/value-stack.mu
@@ -130,6 +130,8 @@ fn value-stack-max-width _self: (addr value-stack) -> result/eax: int {
       break-if-!=
       var s-ah/eax: (addr handle array byte) <- get g, text-data
       var s/eax: (addr array byte) <- lookup *s-ah
+      compare s, 0
+      break-if-=
       var w/eax: int <- length s
       compare w, out
       break-if-<=