1 # Some helpers for copying non-overlapping regions of memory.
2 # Really only intended to be called from code generated by mu.subx.
6 copy-bytes: # src: (addr byte), dest: (addr byte), size: int
12 # if (i >= size) break
13 # *curr-dest = *curr-src
28 8b/-> *(ebp+8) 6/r32/esi
29 # curr-dest/edi = dest
30 8b/-> *(ebp+0xc) 7/r32/edi
32 b9/copy-to-ecx 0/imm32
34 8b/-> *(ebp+0x10) 2/r32/edx
36 # if (i >= size) break
37 39/compare %ecx 2/r32/edx
38 7d/jump-if->= break/disp8
39 # *curr-dest = *curr-src
40 8a/byte-> *esi 0/r32/AL
41 88/byte<- *edi 0/r32/AL
60 stream-to-array: # in: (addr stream _), out: (addr handle array _)
70 8b/-> *(ebp+8) 6/r32/esi
71 # var len/ecx: int = s->write - s->read
73 2b/subtract *(esi+4) 1/r32/ecx
75 (allocate-array Heap %ecx *(ebp+0xc))
76 # var in/edx: (addr byte) = s->data + s->read
77 8b/-> *(esi+4) 2/r32/edx
78 8d/copy-address *(esi+edx+0xc) 2/r32/edx
79 # var dest/eax: (addr byte) = data for out
80 8b/-> *(ebp+0xc) 0/r32/eax
81 (lookup *eax *(eax+4)) # => eax
82 8d/copy-address *(eax+4) 0/r32/eax
84 (copy-bytes %edx %eax %ecx)
101 (clear-stream _test-input-stream)
102 (write _test-input-stream "abc")
104 (read-byte _test-input-stream) # => eax
105 8b/-> *$_test-input-stream->read 0/r32/eax
106 (check-ints-equal %eax 1 "F - test-stream-to-array/pre")
107 # var out/ecx: (handle array byte)
112 (stream-to-array _test-input-stream %ecx)
113 (lookup *ecx *(ecx+4)) # => eax
114 (check-strings-equal %eax "bc" "F - test-stream-to-array")
115 8b/-> *$_test-input-stream->read 0/r32/eax
116 (check-ints-equal %eax 1 "F - test-stream-to-array/read-pointer-not-perturbed")
122 # like stream-to-array but ignore surrounding quotes
123 # we might do other stuff here later
124 unquote-stream-to-array: # in: (addr stream _), out: (addr handle array _)
134 8b/-> *(ebp+8) 6/r32/esi
135 # var len/ecx: int = s->write - s->read - 2
137 2b/subtract *(esi+4) 1/r32/ecx
138 81 7/subop/compare %ecx 2/imm32
139 7c/jump-if-< $unquote-stream-to-array:end/disp8
140 81 5/subop/subtract %ecx 2/imm32
142 (allocate-array Heap %ecx *(ebp+0xc))
143 # var in/edx: (addr byte) = s->data + s->read + 1
144 8b/-> *(esi+4) 2/r32/edx
145 8d/copy-address *(esi+edx+0xd) 2/r32/edx # Stream-data + 1
146 # var dest/eax: (addr byte) = data for out
147 8b/-> *(ebp+0xc) 0/r32/eax
148 (lookup *eax *(eax+4)) # => eax
149 8d/copy-address *(eax+4) 0/r32/eax
151 (copy-bytes %edx %eax %ecx)
152 $unquote-stream-to-array:end:
153 # . restore registers