From d0ae490d042cc7258fdf331955c0b5b1ca8b32ec Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 10 May 2020 16:30:59 -0700 Subject: mu.subx: done with function header parsing --- apps/mu.subx | 153 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 97 insertions(+), 56 deletions(-) (limited to 'apps/mu.subx') diff --git a/apps/mu.subx b/apps/mu.subx index 1ea1ee51..49be4484 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -3411,7 +3411,9 @@ $populate-mu-function-header:check-for-inout: # v = parse-var-with-type(word-slice, first-line) (parse-var-with-type %ecx *(ebp+8) %ebx) # assert(v->register == null) - 81 7/subop/compare *(ebx+0x10) 0/imm32 # Var-register + # . eax: (addr var) = lookup(v) + (lookup *ebx *(ebx+4)) # => eax + 81 7/subop/compare *(eax+0x18) 0/imm32 # Var-register 0f 85/jump-if-!= $populate-mu-function-header:error2/disp32 # v->block-depth is implicitly 0 # @@ -3442,12 +3444,13 @@ $populate-mu-function-header:check-for-out: 0f 85/jump-if-!= $populate-mu-function-header:error1/disp32 # v = parse-var-with-type(word-slice, first-line) (parse-var-with-type %ecx *(ebp+8) %ebx) - 89/<- %ebx 0/r32/eax # assert(var->register != null) - 81 7/subop/compare *(ebx+0x10) 0/imm32 # Var-register + # . eax: (addr var) = lookup(v) + (lookup *ebx *(ebx+4)) # => eax + 81 7/subop/compare *(eax+0x18) 0/imm32 # Var-register 0f 84/jump-if-= $populate-mu-function-header:error3/disp32 # out->outputs = append(v, out->outputs) - 89/copy-address *(edi+0x10) 0/r32/eax # Function-outputs + 8d/copy-address *(edi+0x10) 0/r32/eax # Function-outputs (append-list Heap *ebx *(ebx+4) *(edi+0x10) *(edi+0x14) %eax) # Function-outputs, Function-outputs # e9/jump loop/disp32 @@ -3497,8 +3500,10 @@ $populate-mu-function-header:error2: $populate-mu-function-header:error3: # error("function input '" var "' must be in a register") (write-buffered Stderr "function input '") - (write-buffered Stderr *eax) # Var-name - (write-buffered Stderr " must be in a register'") + (lookup *ebx *(ebx+4)) # => eax + (lookup *eax *(eax+4)) # Var-name Var-name => eax + (write-buffered Stderr %eax) + (write-buffered Stderr "' must be in a register, in instruction '") (flush Stderr) (rewind-stream *(ebp+8)) (write-stream 2 *(ebp+8)) @@ -3619,7 +3624,7 @@ $test-function-header-with-multiple-args:inout2: 5d/pop-to-ebp c3/return -test-function-with-multiple-args-and-outputs: +test-function-header-with-multiple-args-and-outputs: # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp @@ -3637,55 +3642,90 @@ test-function-with-multiple-args-and-outputs: 89/<- %ebx 4/r32/esp # convert (populate-mu-function-header _test-input-stream %ecx %ebx) - # check result - (check-strings-equal *ecx "foo") # Function-name - # edx: (handle list var) = result->inouts - 8b/-> *(ecx+8) 2/r32/edx # Function-inouts - # ebx: (handle var) = result->inouts->value - 8b/-> *edx 3/r32/ebx # List-value - (check-strings-equal *ebx "a" "F - test-function-header-with-multiple-args-and-outputs/inout:0") # Var-name - 8b/-> *(ebx+4) 3/r32/ebx # Var-type - (check-ints-equal *ebx 1 "F - test-function-header-with-multiple-args-and-outputs/inout:0/type:0") # Tree-is-atom - (check-ints-equal *(ebx+4) 1 "F - test-function-header-with-multiple-args-and-outputs/inout:0/type:1") # Tree-value - (check-ints-equal *(ebx+8) 0 "F - test-function-header-with-multiple-args-and-outputs/inout:0/type:2") # Tree-right - # edx = result->inouts->next - 8b/-> *(edx+4) 2/r32/edx # List-next - # ebx = result->inouts->next->value - 8b/-> *edx 3/r32/ebx # List-value - (check-strings-equal *ebx "b" "F - test-function-header-with-multiple-args-and-outputs/inout:1") # Var-name - 8b/-> *(ebx+4) 3/r32/ebx # Var-type - (check-ints-equal *ebx 1 "F - test-function-header-with-multiple-args-and-outputs/inout:1/type:0") # Tree-is-atom - (check-ints-equal *(ebx+4) 1 "F - test-function-header-with-multiple-args-and-outputs/inout:1/type:1") # Tree-value - (check-ints-equal *(ebx+8) 0 "F - test-function-header-with-multiple-args-and-outputs/inout:1/type:2") # Tree-right - # edx = result->inouts->next->next - 8b/-> *(edx+4) 2/r32/edx # List-next - # ebx = result->inouts->next->next->value - 8b/-> *edx 3/r32/ebx # List-value - (check-strings-equal *ebx "c" "F - test-function-header-with-multiple-args-and-outputs/inout:2") # Var-name - 8b/-> *(ebx+4) 3/r32/ebx # Var-type - (check-ints-equal *ebx 1 "F - test-function-header-with-multiple-args-and-outputs/inout:2/type:0") # Tree-is-atom - (check-ints-equal *(ebx+4) 1 "F - test-function-header-with-multiple-args-and-outputs/inout:2/type:1") # Tree-value - (check-ints-equal *(ebx+8) 0 "F - test-function-header-with-multiple-args-and-outputs/inout:2/type:2") # Tree-right - # edx: (handle list var) = result->outputs - 8b/-> *(ecx+0xc) 2/r32/edx # Function-outputs - # ebx: (handle var) = result->outputs->value - 8b/-> *edx 3/r32/ebx # List-value - (check-strings-equal *ebx "x" "F - test-function-header-with-multiple-args-and-outputs/output:0") # Var-name - (check-strings-equal *(ebx+0x10) "ecx" "F - test-function-header-with-multiple-args-and-outputs/output:0/register") # Var-register - 8b/-> *(ebx+4) 3/r32/ebx # Var-type - (check-ints-equal *ebx 1 "F - test-function-header-with-multiple-args-and-outputs/output:0/type:0") # Tree-is-atom - (check-ints-equal *(ebx+4) 1 "F - test-function-header-with-multiple-args-and-outputs/output:0/type:1") # Tree-value - (check-ints-equal *(ebx+8) 0 "F - test-function-header-with-multiple-args-and-outputs/output:0/type:2") # Tree-right - # edx = result->outputs->next - 8b/-> *(edx+4) 2/r32/edx # List-next - # ebx = result->outputs->next->value - 8b/-> *edx 3/r32/ebx # List-value - (check-strings-equal *ebx "y" "F - test-function-header-with-multiple-args-and-outputs/output:1") # Var-name - (check-strings-equal *(ebx+0x10) "edx" "F - test-function-header-with-multiple-args-and-outputs/output:0/register") # Var-register - 8b/-> *(ebx+4) 3/r32/ebx # Var-type - (check-ints-equal *ebx 1 "F - test-function-header-with-multiple-args-and-outputs/output:1/type:0") # Tree-is-atom - (check-ints-equal *(ebx+4) 1 "F - test-function-header-with-multiple-args-and-outputs/output:1/type:1") # Tree-value - (check-ints-equal *(ebx+8) 0 "F - test-function-header-with-multiple-args-and-outputs/output:1/type:2") # Tree-right + # check result->name + (lookup *ecx *(ecx+4)) # Function-name Function-name => eax + (check-strings-equal %eax "foo" "F - test-function-header-with-multiple-args-and-outputs/name") + # var inouts/edx: (addr list var) = lookup(result->inouts) + (lookup *(ecx+8) *(ecx+0xc)) # Function-inouts Function-inouts => eax + 89/<- %edx 0/r32/eax +$test-function-header-with-multiple-args-and-outputs:inout0: + # var v/ebx: (addr var) = lookup(inouts->value) + (lookup *edx *(edx+4)) # List-value List-value => eax + 89/<- %ebx 0/r32/eax + # check v->name + (lookup *ebx *(ebx+4)) # Var-name Var-name => eax + (check-strings-equal %eax "a" "F - test-function-header-with-multiple-args-and-outputs/inout:0") + # check v->type + (lookup *(ebx+8) *(ebx+0xc)) # Var-type Var-type => eax + (check-ints-equal *eax 1 "F - test-function-header-with-multiple-args-and-outputs/inout:0/type:0") # Tree-is-atom + (check-ints-equal *(eax+4) 1 "F - test-function-header-with-multiple-args-and-outputs/inout:0/type:1") # Tree-value + (check-ints-equal *(eax+0xc) 0 "F - test-function-header-with-multiple-args-and-outputs/inout:0/type:2") # Tree-right +$test-function-header-with-multiple-args-and-outputs:inout1: + # inouts = lookup(inouts->next) + (lookup *(edx+8) *(edx+0xc)) # List-next List-next => eax + 89/<- %edx 0/r32/eax + # v = lookup(inouts->value) + (lookup *edx *(edx+4)) # List-value List-value => eax + 89/<- %ebx 0/r32/eax + # check v->name + (lookup *ebx *(ebx+4)) # Var-name Var-name => eax + (check-strings-equal %eax "b" "F - test-function-header-with-multiple-args-and-outputs/inout:1") + # check v->type + (lookup *(ebx+8) *(ebx+0xc)) # Var-type Var-type => eax + (check-ints-equal *eax 1 "F - test-function-header-with-multiple-args-and-outputs/inout:1/type:0") # Tree-is-atom + (check-ints-equal *(eax+4) 1 "F - test-function-header-with-multiple-args-and-outputs/inout:1/type:1") # Tree-value + (check-ints-equal *(eax+0xc) 0 "F - test-function-header-with-multiple-args-and-outputs/inout:1/type:2") # Tree-right +$test-function-header-with-multiple-args-and-outputs:inout2: + # inouts = lookup(inouts->next) + (lookup *(edx+8) *(edx+0xc)) # List-next List-next => eax + 89/<- %edx 0/r32/eax + # v = lookup(inouts->value) + (lookup *edx *(edx+4)) # List-value List-value => eax + 89/<- %ebx 0/r32/eax + # check v->name + (lookup *ebx *(ebx+4)) # Var-name Var-name => eax + (check-strings-equal %eax "c" "F - test-function-header-with-multiple-args-and-outputs/inout:2") + # check v->type + (lookup *(ebx+8) *(ebx+0xc)) # Var-type Var-type => eax + (check-ints-equal *eax 1 "F - test-function-header-with-multiple-args-and-outputs/inout:2/type:0") # Tree-is-atom + (check-ints-equal *(eax+4) 1 "F - test-function-header-with-multiple-args-and-outputs/inout:2/type:1") # Tree-value + (check-ints-equal *(eax+0xc) 0 "F - test-function-header-with-multiple-args-and-outputs/inout:2/type:2") # Tree-right +$test-function-header-with-multiple-args-and-outputs:out0: + # var outputs/edx: (addr list var) = lookup(result->outputs) + (lookup *(ecx+0x10) *(ecx+0x14)) # Function-outputs Function-outputs => eax + 89/<- %edx 0/r32/eax + # v = lookup(outputs->value) + (lookup *edx *(edx+4)) # List-value List-value => eax + 89/<- %ebx 0/r32/eax + # check v->name + (lookup *ebx *(ebx+4)) # Var-name Var-name => eax + (check-strings-equal %eax "x" "F - test-function-header-with-multiple-args-and-outputs/output:0") + # check v->register + (lookup *(ebx+0x18) *(ebx+0x1c)) # Var-register Var-register => eax + (check-strings-equal %eax "ecx" "F - test-function-header-with-multiple-args-and-outputs/output:0/register") + # check v->type + (lookup *(ebx+8) *(ebx+0xc)) # Var-type Var-type => eax + (check-ints-equal *eax 1 "F - test-function-header-with-multiple-args-and-outputs/output:0/type:0") # Tree-is-atom + (check-ints-equal *(eax+4) 1 "F - test-function-header-with-multiple-args-and-outputs/output:0/type:1") # Tree-value + (check-ints-equal *(eax+0xc) 0 "F - test-function-header-with-multiple-args-and-outputs/output:0/type:2") # Tree-right +$test-function-header-with-multiple-args-and-outputs:out1: + # outputs = lookup(outputs->next) + (lookup *(edx+8) *(edx+0xc)) # List-next List-next => eax + 89/<- %edx 0/r32/eax + # v = lookup(inouts->value) + (lookup *edx *(edx+4)) # List-value List-value => eax + 89/<- %ebx 0/r32/eax + # check v->name + (lookup *ebx *(ebx+4)) # Var-name Var-name => eax + (check-strings-equal %eax "y" "F - test-function-header-with-multiple-args-and-outputs/output:1") + # check v->register + (lookup *(ebx+0x18) *(ebx+0x1c)) # Var-register Var-register => eax + (check-strings-equal %eax "edx" "F - test-function-header-with-multiple-args-and-outputs/output:1/register") + # check v->type + (lookup *(ebx+8) *(ebx+0xc)) # Var-type Var-type => eax + (check-ints-equal *eax 1 "F - test-function-header-with-multiple-args-and-outputs/output:1/type:0") # Tree-is-atom + (check-ints-equal *(eax+4) 1 "F - test-function-header-with-multiple-args-and-outputs/output:1/type:1") # Tree-value + (check-ints-equal *(eax+0c) 0 "F - test-function-header-with-multiple-args-and-outputs/output:1/type:2") # Tree-right # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp @@ -6099,6 +6139,7 @@ append-list: # ad: (addr allocation-descriptor), value: (handle _type), list: ( 81 7/subop/compare *(ebp+0x14) 0/imm32 74/jump-if-= $append-list:end/disp8 # otherwise append +$append-list:non-empty-list: # var curr/eax: (addr list _type) = lookup(list) (lookup *(ebp+0x14) *(ebp+0x18)) # => eax # while (curr->next != null) curr = curr->next -- cgit 1.4.1-2-gfad0