diff options
Diffstat (limited to 'apps/mu.subx')
-rw-r--r-- | apps/mu.subx | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/apps/mu.subx b/apps/mu.subx index 34e51462..f5c11137 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -2922,6 +2922,7 @@ parse-mu-block: # in: (addr buffered-file), vars: (addr stack (handle var)), fn # break # else if slice-ends-with?(word-slice, ":") # # TODO: error-check the rest of 'line' + # --word-slice->end to skip ':' # named-block = parse-mu-named-block(word-slice, in, vars, fn) # append-to-block(result, named-block) # else if slice-equal?(word-slice, "var") @@ -3020,8 +3021,11 @@ $parse-mu-block:check-for-named-block: # . if (eax != ':') break 3d/compare-eax-and 0x3a/imm32/colon 0f 85/jump-if-!= break/disp32 - # # TODO: error-check the rest of 'line' + # + # skip ':' + ff 1/subop/decrement *(edx+4) # Slice-end + # (parse-mu-named-block %edx *(ebp+8) *(ebp+0xc) *(ebp+0x10)) # => eax (append-to-block Heap %edi %eax) e9/jump $parse-mu-block:line-loop/disp32 @@ -3080,11 +3084,11 @@ new-block-name: # fn: (handle function) -> result/eax: (handle array byte) # . save registers 51/push-ecx 52/push-edx - # var n/ecx: int = len(fn->name) + 10 for an int + 3 for '$::' + # var n/ecx: int = len(fn->name) + 10 for an int + 2 for '$:' 8b/-> *(ebp+8) 0/r32/eax 8b/-> *eax 0/r32/eax # Function-name 8b/-> *eax 0/r32/eax # String-length - 05/add-to-eax 0xd/imm32 # 10 + 3 for '$::' + 05/add-to-eax 0xd/imm32 # 10 + 2 for '$:' 89/<- %ecx 0/r32/eax # var name/edx: (stream byte n) 29/subtract %esp 1/r32/ecx @@ -3101,7 +3105,6 @@ new-block-name: # fn: (handle function) -> result/eax: (handle array byte) (write %edx %eax) (write %edx ":") (print-int32 %edx *Next-block-index) - (write %edx ":") ff 0/subop/increment *Next-block-index # var s/eax: slice = {name->data, name->data + name->write} (clobbering edx) # . eax = name->write @@ -3178,12 +3181,13 @@ $check-no-tokens-left:end: parse-mu-named-block: # name: (addr slice), in: (addr buffered-file), vars: (addr stack (handle var)), fn: (handle function) -> result/eax: (handle stmt) # pseudocode: - # var v: (handle var) = new-var(name except trailing ':', 0) + # var s: (addr array byte) = slice-to-string(name) + # var v: (handle var) = new-var(s, 0) # v->block-depth = *Curr-block-depth # containing block depth # push(vars, v) # result = parse-mu-block(in, vars, fn) # pop(vars) - # result->name = slice-to-string(name) + # result->name = s # return result # # . prologue @@ -3191,43 +3195,29 @@ parse-mu-named-block: # name: (addr slice), in: (addr buffered-file), vars: (ad 89/<- %ebp 4/r32/esp # . save registers 51/push-ecx - 57/push-edi - # push a var for the label on to 'vars' - { - # ecx = name - 8b/-> *(ebp+8) 1/r32/ecx - # var s/ecx: slice = {name->start, name->end} - ff 6/subop/push *(ecx+4) # Slice-end - ff 6/subop/push *ecx # Slice-start - 89/<- %ecx 4/r32/esp - # strip the trailing ':' from s - ff 1/subop/decrement *(ecx+4) - # var s/ecx: (address array byte) - (slice-to-string Heap %ecx) # => eax - 89/<- %ecx 0/r32/eax - # var type/eax: (handle tree type-id) = literal - (allocate Heap *Tree-size) # => eax - (zero-out %eax *Tree-size) # default type is 'literal' - # var v: (handle var) = new-var(s) - (new-var Heap %ecx %eax *Curr-block-depth 0 0) # => eax - # push(vars, v) - (push *(ebp+0x10) %eax) - # reclaim s - 81 0/subop/add %esp 8/imm32 - } - # edi = result + # var s/ecx: (addr array byte) = slice-to-string(name) + (slice-to-string Heap *(ebp+8)) # => eax + 89/<- %ecx 0/r32/eax + # push a var for s on to 'vars' + # . var type/eax: (handle tree type-id) = literal + (allocate Heap *Tree-size) # => eax + (zero-out %eax *Tree-size) # default type is 'literal' + # . var v: (handle var) = new-var(s) + (new-var Heap %ecx %eax *Curr-block-depth 0 0) # => eax + # . push(vars, v) + (push *(ebp+0x10) %eax) + # eax = result (parse-mu-block *(ebp+0xc) *(ebp+0x10) *(ebp+0x14)) # => eax - 89/<- %edi 0/r32/eax + # pop the var + 50/push-eax (pop *(ebp+0x10)) # => eax + 58/pop-to-eax # result->tag = named-block - c7 0/subop/copy *edi 4/imm32/named-block # Stmt-tag - # result->name = slice-to-string(name) - (slice-to-string Heap *(ebp+8)) # => eax - 89/<- *(edi+8) 0/r32/eax # Named-block-name + c7 0/subop/copy *eax 4/imm32/named-block # Stmt-tag + # result->name = s + 89/<- *(eax+8) 1/r32/ecx # Named-block-name $parse-mu-named-block:end: - 89/<- %eax 7/r32/edi # . restore registers - 5f/pop-to-edi 59/pop-to-ecx # . epilogue 89/<- %esp 5/r32/ebp @@ -4684,14 +4674,14 @@ $emit-subx-named-block:check-empty: (emit-indent *(ebp+8) *Curr-block-depth) (write-buffered *(ebp+8) "{\n") (write-buffered *(ebp+8) *(esi+8)) # Named-block-name - (write-buffered *(ebp+8) "loop:\n") + (write-buffered *(ebp+8) ":loop:\n") ff 0/subop/increment *Curr-block-depth (emit-subx-stmt-list *(ebp+8) %eax *(ebp+0x10)) ff 1/subop/decrement *Curr-block-depth (emit-indent *(ebp+8) *Curr-block-depth) (write-buffered *(ebp+8) "}\n") (write-buffered *(ebp+8) *(esi+8)) # Named-block-name - (write-buffered *(ebp+8) "break:\n") + (write-buffered *(ebp+8) ":break:\n") } $emit-subx-named-block:end: # . restore registers |