From f7cd97c197cff662064198d03cd813d862bdd53c Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 3 Nov 2020 18:10:32 -0800 Subject: 7167 --- apps/mu | Bin 484082 -> 484985 bytes apps/mu.subx | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/mu b/apps/mu index 9fe37bb9..07b19492 100755 Binary files a/apps/mu and b/apps/mu differ diff --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 -- cgit 1.4.1-2-gfad0