From 0102aa377a39f9d5e53b7c95571058cac7c7f7ad Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Wed, 4 Nov 2020 17:46:07 -0800 Subject: 7176 - type checks for 'copy' instruction --- apps/factorial.mu | 2 +- apps/mu | Bin 493268 -> 497992 bytes apps/mu.subx | 575 ++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 473 insertions(+), 104 deletions(-) diff --git a/apps/factorial.mu b/apps/factorial.mu index bb335b0a..15ac8cf4 100644 --- a/apps/factorial.mu +++ b/apps/factorial.mu @@ -36,7 +36,7 @@ fn test-factorial { check-ints-equal result, 0x78, "F - test-factorial" } -fn main args-on-stack: (addr array (addr array byte)) -> _/ebx: int { +fn main args-on-stack: (addr array addr array byte) -> _/ebx: int { var args/eax: (addr array addr array byte) <- copy args-on-stack # len = length(args) var len/ecx: int <- length args diff --git a/apps/mu b/apps/mu index 1800d2cc..6ff5b313 100755 Binary files a/apps/mu and b/apps/mu differ diff --git a/apps/mu.subx b/apps/mu.subx index 1816220f..26985875 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -6106,8 +6106,7 @@ test-convert-function-call-with-arg-of-user-defined-type-by-reference: (write _test-input-stream " foo b\n") (write _test-input-stream "}\n") (write _test-input-stream "fn foo x: (addr t) {\n") - (write _test-input-stream " var x/ecx: (addr int) <- copy x\n") - (write _test-input-stream " increment *x\n") + (write _test-input-stream " var x/ecx: (addr t) <- copy x\n") (write _test-input-stream "}\n") (write _test-input-stream "type t {\n") (write _test-input-stream " x: int\n") @@ -6154,14 +6153,13 @@ test-convert-function-call-with-arg-of-user-defined-type-by-reference: (check-next-stream-line-equal _test-output-stream "$foo:0x00000002:loop:" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/24") (check-next-stream-line-equal _test-output-stream " ff 6/subop/push %ecx" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/25") (check-next-stream-line-equal _test-output-stream " 8b/-> *(ebp+0x00000008) 0x00000001/r32" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/26") - (check-next-stream-line-equal _test-output-stream " ff 0/subop/increment *ecx" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/27") - (check-next-stream-line-equal _test-output-stream " 8f 0/subop/pop %ecx" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/28") - (check-next-stream-line-equal _test-output-stream " }" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/29") - (check-next-stream-line-equal _test-output-stream "$foo:0x00000002:break:" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/30") - (check-next-stream-line-equal _test-output-stream " # . epilogue" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/31") - (check-next-stream-line-equal _test-output-stream " 89/<- %esp 5/r32/ebp" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/32") - (check-next-stream-line-equal _test-output-stream " 5d/pop-to-ebp" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/33") - (check-next-stream-line-equal _test-output-stream " c3/return" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/34") + (check-next-stream-line-equal _test-output-stream " 8f 0/subop/pop %ecx" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/27") + (check-next-stream-line-equal _test-output-stream " }" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/28") + (check-next-stream-line-equal _test-output-stream "$foo:0x00000002:break:" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/29") + (check-next-stream-line-equal _test-output-stream " # . epilogue" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/30") + (check-next-stream-line-equal _test-output-stream " 89/<- %esp 5/r32/ebp" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/31") + (check-next-stream-line-equal _test-output-stream " 5d/pop-to-ebp" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/32") + (check-next-stream-line-equal _test-output-stream " c3/return" "F - test-convert-function-call-with-arg-of-user-defined-type-by-reference/33") # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp @@ -6496,7 +6494,7 @@ test-add-with-non-number: #? # }}} # check output (check-stream-equal _test-output-stream "" "F - test-add-with-non-number: output should be empty") - (check-next-stream-line-equal _test-error-stream "fn foo: stmt add: only non-addr scalar args permitted" "F - test-add-with-non-number: error message") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt add: output must be a non-addr scalar" "F - test-add-with-non-number: error message") # check that stop(1) was called (check-ints-equal *(edx+4) 2 "F - test-add-with-non-number: exit status") # don't restore from ebp @@ -6528,6 +6526,321 @@ test-add-with-addr-dereferenced: 5d/pop-to-ebp c3/return +test-copy-with-no-inout: + # . 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 {\n") + (write _test-input-stream " var x/eax: boolean <- copy\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-copy-with-no-inout: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt 'copy' expects an inout" "F - test-copy-with-no-inout: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-with-no-inout: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + +test-copy-with-multiple-inouts: + # . 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 {\n") + (write _test-input-stream " var x/eax: boolean <- copy 0, 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-copy-with-no-inout: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt 'copy' must have just one inout" "F - test-copy-with-no-inout: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-with-no-inout: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + +test-copy-with-no-output: + # . 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 {\n") + (write _test-input-stream " copy 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-copy-with-no-output: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt 'copy' expects an output" "F - test-copy-with-no-output: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-with-no-output: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + +test-copy-with-multiple-outputs: + # . 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 " var x/eax: boolean <- copy 0\n") + (write _test-input-stream " var y/ecx: boolean <- copy 0\n") + (write _test-input-stream " x, y <- copy 0\n") + (write _test-input-stream " return x\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-copy-with-multiple-outputs: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt 'copy' must have just one output" "F - test-copy-with-multiple-outputs: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-with-multiple-outputs: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + +test-copy-invalid-value-to-address: + # . 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 " var x/eax: int <- copy 0\n") + (write _test-input-stream " var y/ecx: (addr int) <- copy x\n") + (write _test-input-stream " return x\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-copy-invalid-value-to-address: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt copy: output must be a non-addr scalar" "F - test-copy-invalid-value-to-address: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-invalid-value-to-address: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + +test-copy-to-non-register: + # . 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 {\n") + (write _test-input-stream " var x: int\n") + (write _test-input-stream " x <- copy 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-copy-to-non-register: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt copy: output 'x' not in a register" "F - test-copy-to-non-register: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-to-non-register: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + +test-copy-non-scalar: + # . 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 {\n") + (write _test-input-stream " var x: (handle int)\n") + (write _test-input-stream " var y/eax: int <- copy x\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-copy-non-scalar: output should be empty") + (check-next-stream-line-equal _test-error-stream "fn foo: stmt copy: 'y' is too large to fit in a register" "F - test-copy-non-scalar: error message") + # check that stop(1) was called + (check-ints-equal *(edx+4) 2 "F - test-copy-non-scalar: exit status") + # don't restore from ebp + 81 0/subop/add %esp 8/imm32 + # . epilogue + 5d/pop-to-ebp + c3/return + test-get-with-wrong-field: # . prologue 55/push-ebp @@ -7664,51 +7977,6 @@ test-index-with-addr-base-on-stack: 5d/pop-to-ebp c3/return -test-index-with-array-base-in-register: - # . 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 {\n") - (write _test-input-stream " var a/eax: (array int 3) <- copy 0\n") - (write _test-input-stream " var c/ecx: (addr int) <- index a, 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-index-with-array-base-in-register: output should be empty") - (check-next-stream-line-equal _test-error-stream "fn foo: stmt index: var 'a' is an array, and so must live on the stack" "F - test-index-with-array-base-in-register: error message") - # check that stop(1) was called - (check-ints-equal *(edx+4) 2 "F - test-index-with-array-base-in-register: exit status") - # don't restore from ebp - 81 0/subop/add %esp 8/imm32 - # . epilogue - 5d/pop-to-ebp - c3/return - test-index-with-wrong-index-type: # . prologue 55/push-ebp @@ -8908,7 +9176,7 @@ test-compute-offset-with-too-many-outputs: # (write _test-input-stream "fn foo {\n") (write _test-input-stream " var a: (array int 3)\n") - (write _test-input-stream " var b/eax: (offset int) <- copy 0\n") + (write _test-input-stream " var b/eax: (offset int) <- compute-offset a, 0\n") (write _test-input-stream " var c/ecx: (addr int) <- copy 0\n") (write _test-input-stream " b, c <- compute-offset a, 0\n") (write _test-input-stream "}\n") @@ -10187,51 +10455,6 @@ test-length-with-addr-base-on-stack: 5d/pop-to-ebp c3/return -test-length-with-array-base-in-register: - # . 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 {\n") - (write _test-input-stream " var a/eax: (array int 3) <- copy 0\n") - (write _test-input-stream " var c/ecx: (addr int) <- length a\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-length-with-array-base-in-register: output should be empty") - (check-next-stream-line-equal _test-error-stream "fn foo: stmt length: var 'a' is an array, and so must live on the stack" "F - test-length-with-array-base-in-register: error message") - # check that stop(1) was called - (check-ints-equal *(edx+4) 2 "F - test-length-with-array-base-in-register: exit status") - # don't restore from ebp - 81 0/subop/add %esp 8/imm32 - # . epilogue - 5d/pop-to-ebp - c3/return - test-length-with-wrong-output-type: # . prologue 55/push-ebp @@ -16395,7 +16618,7 @@ $check-mu-numberlike-output:fail: 8b/-> *(ebp+0xc) 0/r32/eax (lookup *(eax+4) *(eax+8)) # Stmt1-operation Stmt1-operation => eax (write-buffered *(ebp+0x14) %eax) - (write-buffered *(ebp+0x14) ": only non-addr scalar args permitted\n") + (write-buffered *(ebp+0x14) ": output must be a non-addr scalar\n") (flush *(ebp+0x14)) (stop *(ebp+0x18) 1) # never gets here @@ -16405,13 +16628,159 @@ check-mu-copy-stmt: # stmt: (addr stmt), fn: (addr function), err: (addr buffer 55/push-ebp 89/<- %ebp 4/r32/esp # . save registers + 50/push-eax + 51/push-ecx + 52/push-edx + 56/push-esi + # var type-parameters/edx: (addr table (handle array byte) (addr type-tree) 8) + 81 5/subop/subtract %esp 0x60/imm32 + 68/push 0x60/imm32/size + 68/push 0/imm32/read + 68/push 0/imm32/write + 89/<- %edx 4/r32/esp +$check-mu-copy-stmt:get-output: + # esi = stmt + 8b/-> *(ebp+8) 6/r32/esi + # var output/edi: (addr stmt-var) = stmt->outputs + (lookup *(esi+0x14) *(esi+0x18)) # Stmt1-outputs Stmt1-outputs => eax + 89/<- %edi 0/r32/eax + # zero outputs + 3d/compare-eax-and 0/imm32 + 0f 84/jump-if-= $check-mu-copy-stmt:error-no-output/disp32 + # > 1 output + (lookup *(edi+8) *(edi+0xc)) # Stmt-var-next Stmt-var-next => eax + 3d/compare-eax-and 0/imm32 + 0f 85/jump-if-!= $check-mu-copy-stmt:error-too-many-outputs/disp32 +$check-mu-copy-stmt:get-inout: + # var inout/esi: (addr stmt-var) = stmt->inouts + (lookup *(esi+0xc) *(esi+0x10)) # Stmt1-inouts Stmt1-inouts => eax + 89/<- %esi 0/r32/eax + # zero inouts + 3d/compare-eax-and 0/imm32 + 0f 84/jump-if-= $check-mu-copy-stmt:error-no-inout/disp32 + # > 1 inout + (lookup *(esi+8) *(esi+0xc)) # Stmt-var-next Stmt-var-next => eax + 3d/compare-eax-and 0/imm32 + 0f 85/jump-if-!= $check-mu-copy-stmt:error-too-many-inouts/disp32 +$check-mu-copy-stmt:types: + # var inout-type/ecx: (addr type-tree) = inout->value->type + (lookup *esi *(esi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *(eax+8) *(eax+0xc)) # Var-type Var-type => eax + 89/<- %ecx 0/r32/eax + # if output not in register, abort + (lookup *edi *(edi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *(eax+0x18) *(eax+0x1c)) # Var-register Var-register => eax + 3d/compare-eax-and 0/imm32 + 0f 84/jump-if-= $check-mu-copy-stmt:error-output-not-in-register/disp32 + # if inout is not a scalar, abort + (lookup *esi *(esi+4)) # Stmt-var-value Stmt-var-value => eax + (size-of %eax) # => eax + 3d/compare-eax-and 4/imm32 + 0f 8f/jump-if-> $check-mu-copy-stmt:error-inout-too-large/disp32 + # var output-type/eax: (addr type-tree) = output->value->type + (lookup *edi *(edi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *(eax+8) *(eax+0xc)) # Var-type Var-type => eax + # if (inout-type == output-type) return + (type-match? %eax %ecx %edx) # => eax + 3d/compare-eax-and 0/imm32 + 0f 85/jump-if-!= $check-mu-copy-stmt:end/disp32 + # if output is an addr and inout is 0, return + { + (lookup *edi *(edi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *(eax+8) *(eax+0xc)) # Var-type Var-type => eax + (is-mu-addr-type? %eax) # => eax + 3d/compare-eax-and 0/imm32/false + 74/jump-if-= break/disp8 + (lookup *esi *(esi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *eax *(eax+4)) # Var-name Var-name => eax + (string-equal? %eax "0") # => eax + 3d/compare-eax-and 0/imm32/false + 74/jump-if-= break/disp8 + eb/jump $check-mu-copy-stmt:end/disp8 + } + # if output is not number-like, abort + (check-mu-numberlike-output %edi *(ebp+8) *(ebp+0xc) *(ebp+0x10) *(ebp+0x14)) $check-mu-copy-stmt:end: + # . reclaim locals + 81 0/subop/add %esp 0x6c/imm32 # . 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 +$check-mu-copy-stmt:error-no-inout: + (write-buffered *(ebp+0x10) "fn ") + 8b/-> *(ebp+0xc) 0/r32/eax + (lookup *eax *(eax+4)) # Function-name Function-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) ": stmt 'copy' expects an inout\n") + (flush *(ebp+0x10)) + (stop *(ebp+0x14) 1) + # never gets here + +$check-mu-copy-stmt:error-too-many-inouts: + (write-buffered *(ebp+0x10) "fn ") + 8b/-> *(ebp+0xc) 0/r32/eax + (lookup *eax *(eax+4)) # Function-name Function-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) ": stmt 'copy' must have just one inout\n") + (flush *(ebp+0x10)) + (stop *(ebp+0x14) 1) + # never gets here + +$check-mu-copy-stmt:error-no-output: + (write-buffered *(ebp+0x10) "fn ") + 8b/-> *(ebp+0xc) 0/r32/eax + (lookup *eax *(eax+4)) # Function-name Function-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) ": stmt 'copy' expects an output\n") + (flush *(ebp+0x10)) + (stop *(ebp+0x14) 1) + # never gets here + +$check-mu-copy-stmt:error-output-not-in-register: + (write-buffered *(ebp+0x10) "fn ") + 8b/-> *(ebp+0xc) 0/r32/eax + (lookup *eax *(eax+4)) # Function-name Function-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) ": stmt copy: output '") + (lookup *edi *(edi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *eax *(eax+4)) # Var-name Var-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) "' not in a register\n") + (flush *(ebp+0x10)) + (stop *(ebp+0x14) 1) + # never gets here + +$check-mu-copy-stmt:error-too-many-outputs: + (write-buffered *(ebp+0x10) "fn ") + 8b/-> *(ebp+0xc) 0/r32/eax + (lookup *eax *(eax+4)) # Function-name Function-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) ": stmt 'copy' must have just one output\n") + (flush *(ebp+0x10)) + (stop *(ebp+0x14) 1) + # never gets here + +$check-mu-copy-stmt:error-inout-too-large: + (write-buffered *(ebp+0x10) "fn ") + 8b/-> *(ebp+0xc) 0/r32/eax + (lookup *eax *(eax+4)) # Function-name Function-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) ": stmt copy: '") + (lookup *edi *(edi+4)) # Stmt-var-value Stmt-var-value => eax + (lookup *eax *(eax+4)) # Var-name Var-name => eax + (write-buffered *(ebp+0x10) %eax) + (write-buffered *(ebp+0x10) "' is too large to fit in a register\n") + (flush *(ebp+0x10)) + (stop *(ebp+0x14) 1) + # never gets here + check-mu-copy-to-stmt: # stmt: (addr stmt), fn: (addr function), err: (addr buffered-file), ed: (addr exit-descriptor) # . prologue 55/push-ebp -- cgit 1.4.1-2-gfad0