diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-02-10 00:57:31 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-02-14 01:46:37 -0800 |
commit | 1f029c3b5733540aec775117dfa1d03447d563db (patch) | |
tree | 304ae5e42986869743a8f9210be5a5d37322801a /apps | |
parent | 0be8e8007299be1eaaf778e3539b2eafcb637c8b (diff) | |
download | mu-1f029c3b5733540aec775117dfa1d03447d563db.tar.gz |
6005
Support calling SubX code from Mu. I have _zero_ idea how to make this safe. Now we can start writing tests. We can't use commandline args yet. That requires support for kernel strings.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/factorial.mu | 7 | ||||
-rwxr-xr-x | apps/mu | bin | 133432 -> 133613 bytes | |||
-rw-r--r-- | apps/mu.subx | 44 |
3 files changed, 47 insertions, 4 deletions
diff --git a/apps/factorial.mu b/apps/factorial.mu index f306de25..5177daeb 100644 --- a/apps/factorial.mu +++ b/apps/factorial.mu @@ -1,4 +1,6 @@ fn main -> result/ebx: int { +#? run-tests +#? result <- copy 0 var tmp/eax: int <- factorial 5 result <- copy tmp } @@ -17,3 +19,8 @@ fn factorial n: int -> result/eax: int { result <- multiply n } } + +fn test-factorial { + var result/eax: int <- factorial 5 + check-ints-equal result 0x78 "F - test-factorial" +} diff --git a/apps/mu b/apps/mu index 6c7533d7..e4a40dcc 100755 --- a/apps/mu +++ b/apps/mu Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx index 67a99418..c54cfdd6 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -5139,8 +5139,8 @@ $emit-subx-statement:call: (emit-subx-call *(ebp+8) *(ebp+0xc) %eax) # out, stmt, curr e9/jump $emit-subx-statement:end/disp32 } - # else abort - e9/jump $emit-subx-statement:abort/disp32 + # else assume it's a SubX function (TODO: how to type-check?!) + (emit-hailmary-call *(ebp+8) *(ebp+0xc)) $emit-subx-statement:end: # . restore registers 59/pop-to-ecx @@ -6757,7 +6757,6 @@ emit-subx-call: # out: (addr buffered-file), stmt: (handle statement), callee: 55/push-ebp 89/<- %ebp 4/r32/esp # . save registers - 50/push-eax 51/push-ecx # (emit-indent *(ebp+8) *Curr-block-depth) @@ -6784,7 +6783,44 @@ emit-subx-call: # out: (addr buffered-file), stmt: (handle statement), callee: $emit-subx-call:end: # . restore registers 59/pop-to-ecx - 58/pop-to-eax + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +# like a function call, except we have no idea what function it is +# we hope it's defined in SubX and that the types are ok +emit-hailmary-call: # out: (addr buffered-file), stmt: (handle statement) + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # . save registers + 51/push-ecx + # + (emit-indent *(ebp+8) *Curr-block-depth) + (write-buffered *(ebp+8) "(") + # ecx = stmt + 8b/-> *(ebp+0xc) 1/r32/ecx + # - emit function name + (write-buffered *(ebp+8) *(ecx+4)) # Stmt1-operation + # - emit arguments + # var curr/ecx: (handle list var) = stmt->inouts + 8b/-> *(ecx+8) 1/r32/ecx # Stmt1-inouts + { + # if (curr == null) break + 81 7/subop/compare %ecx 0/imm32 + 74/jump-if-= break/disp8 + # + (emit-subx-call-operand *(ebp+8) *ecx) + # curr = curr->next + 8b/-> *(ecx+4) 1/r32/ecx + eb/jump loop/disp8 + } + # + (write-buffered *(ebp+8) ")\n") +$emit-hailmary-call:end: + # . restore registers + 59/pop-to-ecx # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp |