diff options
Diffstat (limited to 'apps/mu.subx')
-rw-r--r-- | apps/mu.subx | 88 |
1 files changed, 55 insertions, 33 deletions
diff --git a/apps/mu.subx b/apps/mu.subx index 70480775..b82bd45a 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -3672,22 +3672,21 @@ test-function-with-multiple-args-and-outputs: # x/eax: int, # ignores at most one trailing comma # WARNING: modifies name -parse-var-with-type: # name: (addr slice), first-line: (addr stream byte) -> result/eax: (handle var) +parse-var-with-type: # name: (addr slice), first-line: (addr stream byte), out: (addr handle var) # pseudocode: # var s: slice # if (!slice-ends-with(name, ":")) # abort # --name->end to skip ':' # next-token-from-slice(name->start, name->end, '/', s) - # result = new-var-from-slice(s) + # new-var-from-slice(s, out) # ## register # next-token-from-slice(s->end, name->end, '/', s) # if (!slice-empty?(s)) - # v->register = slice-to-string(s) + # out->register = slice-to-string(s) # ## type # var type: (handle tree type-id) = parse-type(first-line) - # v->type = type - # return v + # out->type = type # # . prologue 55/push-ebp @@ -3716,14 +3715,13 @@ parse-var-with-type: # name: (addr slice), first-line: (addr stream byte) -> re $parse-var-with-type:parse-name: (next-token-from-slice *esi *(esi+4) 0x2f %ecx) # Slice-start, Slice-end, '/' $parse-var-with-type:create-var: - # edi = new-var-from-slice(s) - (new-var-from-slice Heap %ecx) # => eax - 89/<- %edi 0/r32/eax - # save v->register + # new-var-from-slice(s, out) + (new-var-from-slice Heap %ecx *(ebp+0x10)) + # save out->register $parse-var-with-type:save-register: # s = next-token(...) (next-token-from-slice *(ecx+4) *(esi+4) 0x2f %ecx) # s->end, name->end, '/' - # if (!slice-empty?(s)) v->register = slice-to-string(s) + # if (!slice-empty?(s)) out->register = slice-to-string(s) { $parse-var-with-type:write-register: (slice-empty? %ecx) # => eax @@ -5658,7 +5656,7 @@ test-parse-mu-stmt-with-comma: 5d/pop-to-ebp c3/return -new-var: # ad: (addr allocation-descriptor), name: (addr array byte), out: (addr handle var) +new-var: # ad: (addr allocation-descriptor), name: (handle array byte), out: (addr handle var) # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp @@ -5666,13 +5664,16 @@ new-var: # ad: (addr allocation-descriptor), name: (addr array byte), out: (add 50/push-eax 51/push-ecx # ecx = out - 8b/-> *(ebp+0x10) 1/r32/ecx + 8b/-> *(ebp+0x14) 1/r32/ecx # (allocate *(ebp+8) *Var-size %ecx) # var out-addr/eax: (addr var) (lookup *ecx *(ecx+4)) # => eax # out-addr->name = copy-array(name) - (copy-array *(ebp+8) *(ebp+0xc) %eax) # Var-name + 8b/-> *(ebp+0xc) 1/r32/ecx + 89/<- *eax 1/r32/ecx # Var-name + 8b/-> *(ebp+0x10) 1/r32/ecx + 89/<- *(eax+4) 1/r32/ecx # Var-name $new-var:end: # . restore registers 59/pop-to-ecx @@ -5719,44 +5720,57 @@ $new-literal-integer:abort: cd/syscall 0x80/imm8 # never gets here -new-literal: # ad: (addr allocation-descriptor), name: (addr slice) -> result/eax: (handle var) +new-literal: # ad: (addr allocation-descriptor), name: (addr slice), out: (addr handle var) # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp # . save registers + 50/push-eax 51/push-ecx - 52/push-edx - # var s/ecx: (addr array byte) - (slice-to-string Heap *(ebp+0xc)) # => eax + # var s/ecx: (handle array byte) + 68/push 0/imm32 + 68/push 0/imm32 89/<- %ecx 0/r32/eax - # type = new type() - (allocate *(ebp+8) *Tree-size) # => eax + # s = slice-to-string(name) + (slice-to-string Heap *(ebp+0xc) %ecx) + # allocate to out + (new-var *(ebp+8) *ecx *(ecx+4) *(ebp+0x10) + # ecx = out + 8b/-> *(ebp+0x10) 1/r32/ecx + # out->type = new type + 8d/copy-address *(ecx+8) 0/r32/eax # Var-type + (allocate *(ebp+8) *Tree-size %eax) + (lookup *(ecx+8) *(ecx+0xc)) # => eax # nothing else to do; default type is 'literal' c7 0/subop/copy *eax 1/imm32/true # Tree-is-atom - 89/<- %edx 0/r32/eax - # eax = result - (new-var *(ebp+8) %ecx) # => eax - # result->type = type - 89/<- *(eax+4) 2/r32/edx # Var-type $new-literal:end: + # . reclaim locals + 81 0/subop/add %esp 8/imm32 # . restore registers - 5a/pop-to-edx 59/pop-to-ecx + 58/pop-to-eax # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp c3/return -new-var-from-slice: # ad: (addr allocation-descriptor), name: (addr slice) -> result/eax: (handle var) +new-var-from-slice: # ad: (addr allocation-descriptor), name: (addr slice), out: (addr handle var) # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp # . save registers 51/push-ecx - # result = new-var(slice-to-string(name)) - (slice-to-string Heap *(ebp+0xc)) # => eax - (new-var *(ebp+8) %eax) + # var tmp/ecx: (handle array byte) + 68/push 0/imm32 + 68/push 0/imm32 + 89/<- %ecx 4/r32/esp + # tmp = slice-to-string(name) + (slice-to-string Heap *(ebp+0xc) %ecx) + # out = new-var(tmp) + (new-var *(ebp+8) *ecx *(ecx+4) *(ebp+0x10)) $new-var-from-slice:end: + # . reclaim locals + 81 0/subop/add %esp 8/imm32 # . restore registers 59/pop-to-ecx # . epilogue @@ -6109,10 +6123,18 @@ find-or-create-typeinfo-output-var: # T: (handle typeinfo), f: (addr slice), ou { 81 7/subop/compare *(edi+8) 0/imm32 # Typeinfo-entry-output-var 75/jump-if-!= break/disp8 - # out/edx = new var("dummy name", type, -1 offset) - 8b/-> *(ebp+0x10) 2/r32/edx - (new-var Heap "field" %edx) + # out/edx = new var(dummy name, type, -1 offset) + # . var name/eax: (handle array byte) = "field" + 68/push 0/imm32 + 68/push 0/imm32 + 89/<- %eax 4/r32/esp + (copy-array Heap "field" %eax) + # . new var + (new-var Heap *eax *(eax+4) *(ebp+0x10)) + # . reclaim name + 81 0/subop/add %esp 8/imm32 # save out in typeinfo + 8b/-> *(ebp+0x10) 2/r32/edx 8b/-> *edx 0/r32/eax 89/<- *(edi+0xc) 0/r32/eax # Typeinfo-entry-output-var 8b/-> *(edx+4) 0/r32/eax @@ -6122,7 +6144,7 @@ find-or-create-typeinfo-output-var: # T: (handle typeinfo), f: (addr slice), ou (lookup *edx *(edx+4)) # => eax 89/<- %edx 0/r32/eax # . out->type = new constant type - 8d/copy-address *(edx+8) 0/r32/eax + 8d/copy-address *(edx+8) 0/r32/eax # Var-type (allocate Heap *Tree-size %eax) (lookup *(edx+8) *(edx+0xc)) # => eax c7 0/subop/copy *eax 1/imm32/true # Tree-is-atom |