about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-11-03 18:10:32 -0800
committerKartik Agaram <vc@akkartik.com>2020-11-03 18:10:32 -0800
commitf7cd97c197cff662064198d03cd813d862bdd53c (patch)
tree6b0b38be9c999f0fee87fef7d3ba8d2ac57791c0 /apps
parentf21c96203eb3fbca5c389435f5ec927b4f621725 (diff)
downloadmu-f7cd97c197cff662064198d03cd813d862bdd53c.tar.gz
7167
Diffstat (limited to 'apps')
-rwxr-xr-xapps/mubin484082 -> 484985 bytes
-rw-r--r--apps/mu.subx75
2 files changed, 74 insertions, 1 deletions
diff --git a/apps/mu b/apps/mu
index 9fe37bb9..07b19492 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index 86f9afd2..4aa9b70a 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -1014,6 +1014,51 @@ test-missing-return:
     5d/pop-to-ebp
     c3/return
 
+test-early-exit-without-return:
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # setup
+    (clear-stream _test-input-stream)
+    (clear-stream $_test-input-buffered-file->buffer)
+    (clear-stream _test-output-stream)
+    (clear-stream $_test-output-buffered-file->buffer)
+    (clear-stream _test-error-stream)
+    (clear-stream $_test-error-buffered-file->buffer)
+    # var ed/edx: exit-descriptor = tailor-exit-descriptor(16)
+    68/push 0/imm32
+    68/push 0/imm32
+    89/<- %edx 4/r32/esp
+    (tailor-exit-descriptor %edx 0x10)
+    #
+    (write _test-input-stream "fn foo -> _/eax: int {\n")
+    (write _test-input-stream "  break\n")
+    (write _test-input-stream "  return 0\n")
+    (write _test-input-stream "}\n")
+    # convert
+    (convert-mu _test-input-buffered-file _test-output-buffered-file _test-error-buffered-file %edx)
+    # registers except esp clobbered at this point
+    # restore ed
+    89/<- %edx 4/r32/esp
+    (flush _test-output-buffered-file)
+    (flush _test-error-buffered-file)
+#?     # dump _test-error-stream {{{
+#?     (write 2 "^")
+#?     (write-stream 2 _test-error-stream)
+#?     (write 2 "$\n")
+#?     (rewind-stream _test-error-stream)
+#?     # }}}
+    # check output
+    (check-stream-equal _test-output-stream  ""  "F - test-early-exit-without-return: output should be empty")
+    (check-next-stream-line-equal _test-error-stream  "fn foo has outputs, so you cannot 'break' out of the outermost block. Use 'return'."  "F - test-early-exit-without-return: error message")
+    # check that stop(1) was called
+    (check-ints-equal *(edx+4) 2 "F - test-early-exit-without-return: exit status")
+    # don't restore from ebp
+    81 0/subop/add %esp 8/imm32
+    # . epilogue
+    5d/pop-to-ebp
+    c3/return
+
 test-return-with-too-few-inouts:
     # . prologue
     55/push-ebp
@@ -16299,8 +16344,36 @@ check-no-breaks:  # block: (addr block), fn: (addr function), err: (addr buffere
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
+    50/push-eax
+    51/push-ecx
+    # var curr/ecx: (addr list stmt) = block->stmts
+    8b/-> *(ebp+8) 0/r32/eax
+    (lookup *(eax+4) *(eax+8))  # Block-stmts Block-stmts => eax
+    89/<- %ecx 0/r32/eax
+    {
+      # if curr->next == 0, break
+      (lookup *(ecx+8) *(ecx+0xc))  # List-next List-next => eax
+      3d/compare-eax-and 0/imm32
+      74/jump-if-= break/disp8
+      # if curr->value->tag != Stmt1, continue
+      (lookup *ecx *(ecx+4))  # List-value List-value => eax
+      81 7/subop/compare *eax 1/imm32/stmt1  # Stmt-tag
+      75/jump-if-!= $check-no-breaks:continue/disp8
+      # if curr->value->operation starts with "break", abort
+      (lookup *(eax+4) *(eax+8))  # Stmt1-operation Stmt1-operation => eax
+      (string-starts-with? %eax "break")  # => eax
+      3d/compare-eax-and 0/imm32/false
+      75/jump-if-!= $check-no-breaks:error/disp8
+$check-no-breaks:continue:
+      # curr = curr->next
+      (lookup *(ecx+8) *(ecx+0xc))  # List-next List-next => eax
+      89/<- %ecx 0/r32/eax
+      e9/jump loop/disp32
+    }
 $check-no-breaks:end:
     # . restore registers
+    59/pop-to-ecx
+    58/pop-to-eax
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
@@ -16311,7 +16384,7 @@ $check-no-breaks:error:
     8b/-> *(ebp+0xc) 0/r32/eax
     (lookup *eax *(eax+4))  # Function-name Function-name => eax
     (write-buffered *(ebp+0x10) %eax)
-    (write-buffered *(ebp+0x10) ": final statement should be a 'return'\n")
+    (write-buffered *(ebp+0x10) " has outputs, so you cannot 'break' out of the outermost block. Use 'return'.\n")
     (flush *(ebp+0x10))
     (stop *(ebp+0x14) 1)
     # never gets here