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 # var out/ecx: (handle array byte)
110 (stream-to-array _test-input-stream %ecx)
111 (lookup *ecx *(ecx+4)) # => eax
112 (check-strings-equal %eax "bc")
118 # like stream-to-array but ignore surrounding quotes
119 # we might do other stuff here later
120 unquote-stream-to-array: # in: (addr stream _), out: (addr handle array _)
130 8b/-> *(ebp+8) 6/r32/esi
131 # var len/ecx: int = s->write - s->read - 2
133 2b/subtract *(esi+4) 1/r32/ecx
134 81 7/subop/compare %ecx 2/imm32
135 7c/jump-if-< $unquote-stream-to-array:end/disp8
136 81 5/subop/subtract %ecx 2/imm32
138 (allocate-array Heap %ecx *(ebp+0xc))
139 # var in/edx: (addr byte) = s->data + s->read + 1
140 8b/-> *(esi+4) 2/r32/edx
141 8d/copy-address *(esi+edx+0xd) 2/r32/edx # Stream-data + 1
142 # var dest/eax: (addr byte) = data for out
143 8b/-> *(ebp+0xc) 0/r32/eax
144 (lookup *eax *(eax+4)) # => eax
145 8d/copy-address *(eax+4) 0/r32/eax
147 (copy-bytes %edx %eax %ecx)
148 $unquote-stream-to-array:end:
149 # . restore registers