From 2d7960d493c11ba6286193ec01b7f6771cd0b695 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 25 Oct 2020 21:15:43 -0700 Subject: 7106 - tile: arrays of ints --- 301array-equal.subx | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to '301array-equal.subx') diff --git a/301array-equal.subx b/301array-equal.subx index c799f814..d020f5aa 100644 --- a/301array-equal.subx +++ b/301array-equal.subx @@ -171,7 +171,7 @@ test-compare-inequal-arrays-equal-sizes: 5d/pop-to-ebp c3/return -parse-array-of-ints: # ad: (addr allocation-descriptor), s: (addr string), out: (addr handle array int) +_parse-array-of-ints: # ad: (addr allocation-descriptor), s: (addr array byte), out: (addr handle array int) # pseudocode # end = &s->data[s->size] # curr = s->data @@ -216,25 +216,25 @@ parse-array-of-ints: # ad: (addr allocation-descriptor), s: (addr string), out: 01/add-to %edx 1/r32/ecx # var size/ebx: int = 0 31/xor-with %ebx 3/r32/ebx -$parse-array-of-ints:loop1: +$_parse-array-of-ints:loop1: # if (curr >= end) break 39/compare %ecx 2/r32/edx - 73/jump-if-addr>= $parse-array-of-ints:break1/disp8 + 73/jump-if-addr>= $_parse-array-of-ints:break1/disp8 # curr = skip-chars-matching-in-slice(curr, end, ' ') (skip-chars-matching-in-slice %ecx %edx 0x20) # => eax 89/<- %ecx 0/r32/eax # if (curr >= end) break 39/compare %ecx 2/r32/edx - 73/jump-if-addr>= $parse-array-of-ints:break1/disp8 + 73/jump-if-addr>= $_parse-array-of-ints:break1/disp8 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') (skip-chars-not-matching-in-slice %ecx %edx 0x20) # => eax 89/<- %ecx 0/r32/eax # size += 4 81 0/subop/add %ebx 4/imm32 - eb/jump $parse-array-of-ints:loop1/disp8 -$parse-array-of-ints:break1: + eb/jump $_parse-array-of-ints:loop1/disp8 +$_parse-array-of-ints:break1: (allocate-array *(ebp+8) %ebx *(ebp+0x10)) -$parse-array-of-ints:pass2: +$_parse-array-of-ints:pass2: # var slice/edi: slice = {s->data, 0} 68/push 0/imm32/end 8d/copy-address *(esi+4) 7/r32/edi @@ -244,16 +244,16 @@ $parse-array-of-ints:pass2: 8b/-> *(ebp+0x10) 0/r32/eax (lookup *eax *(eax+4)) # => eax 8d/copy-address *(eax+4) 1/r32/ecx -$parse-array-of-ints:loop2: +$_parse-array-of-ints:loop2: # if (slice->start >= end) break 39/compare *edi 2/r32/edx - 73/jump-if-addr>= $parse-array-of-ints:end/disp8 + 73/jump-if-addr>= $_parse-array-of-ints:end/disp8 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') (skip-chars-matching-in-slice *edi %edx 0x20) # => eax 89/<- *edi 0/r32/eax # if (slice->start >= end) break 39/compare *edi 2/r32/edx - 73/jump-if-addr>= $parse-array-of-ints:end/disp8 + 73/jump-if-addr>= $_parse-array-of-ints:end/disp8 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') (skip-chars-not-matching-in-slice *edi %edx 0x20) # => eax 89/<- *(edi+4) 0/r32/eax @@ -265,8 +265,8 @@ $parse-array-of-ints:loop2: # slice->start = slice->end 8b/-> *(edi+4) 0/r32/eax 89/<- *edi 0/r32/eax - eb/jump $parse-array-of-ints:loop2/disp8 -$parse-array-of-ints:end: + eb/jump $_parse-array-of-ints:loop2/disp8 +$_parse-array-of-ints:end: # . reclaim locals 81 0/subop/add %esp 8/imm32 # . restore registers @@ -296,7 +296,7 @@ test-parse-array-of-ints: 68/push 0xc/imm32/size 89/<- %ecx 4/r32/esp # - (parse-array-of-ints Heap "1 2 3" %esi) + (_parse-array-of-ints Heap "1 2 3" %esi) (lookup *esi *(esi+4)) # => eax (array-equal? %ecx %eax) # => eax (check-ints-equal %eax 1 "F - test-parse-array-of-ints") @@ -315,7 +315,7 @@ test-parse-array-of-ints-empty: 68/push 0/imm32 89/<- %esi 4/r32/esp # - (parse-array-of-ints Heap "" %esi) + (_parse-array-of-ints Heap "" %esi) (lookup *esi *(esi+4)) # => eax (check-ints-equal *eax 0 "F - test-parse-array-of-ints-empty") # . epilogue @@ -333,7 +333,7 @@ test-parse-array-of-ints-just-whitespace: 68/push 0/imm32 89/<- %esi 4/r32/esp # - (parse-array-of-ints Heap Space %esi) + (_parse-array-of-ints Heap Space %esi) (lookup *esi *(esi+4)) # => eax (check-ints-equal *eax 0 "F - test-parse-array-of-ints-just-whitespace") # . epilogue @@ -356,7 +356,7 @@ test-parse-array-of-ints-extra-whitespace: 68/push 0xc/imm32/size 89/<- %ecx 4/r32/esp # - (parse-array-of-ints Heap " 1 2 3 " %esi) + (_parse-array-of-ints Heap " 1 2 3 " %esi) (lookup *esi *(esi+4)) # => eax (array-equal? %ecx %eax) # => eax (check-ints-equal %eax 1 "F - test-parse-array-of-ints-extra-whitespace") @@ -365,6 +365,18 @@ test-parse-array-of-ints-extra-whitespace: 5d/pop-to-ebp c3/return +parse-array-of-ints: # s: (addr array byte), out: (addr handle array int) + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # + (_parse-array-of-ints Heap *(ebp+8) *(ebp+0xc)) +$parse-array-of-ints:end: + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + # helper for later tests # compare an array with a string representation of an array literal check-array-equal: # a: (addr array int), expected: (addr string), msg: (addr string) @@ -379,7 +391,7 @@ check-array-equal: # a: (addr array int), expected: (addr string), msg: (addr s 68/push 0/imm32 89/<- %esi 4/r32/esp # var b/eax: (addr array int) = parse-array-of-ints(Heap, expected) - (parse-array-of-ints Heap *(ebp+0xc) %esi) + (parse-array-of-ints *(ebp+0xc) %esi) (lookup *esi *(esi+4)) # => eax # (array-equal? *(ebp+8) %eax) -- cgit 1.4.1-2-gfad0