From 9a77780158842db6e4aa098f5027e030fc3bd878 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 22 May 2020 23:08:09 -0700 Subject: 6384 --- html/100array-equal.subx.html | 840 ++++++++++++++++-------------------------- 1 file changed, 327 insertions(+), 513 deletions(-) (limited to 'html/100array-equal.subx.html') diff --git a/html/100array-equal.subx.html b/html/100array-equal.subx.html index 452840cb..425e0879 100644 --- a/html/100array-equal.subx.html +++ b/html/100array-equal.subx.html @@ -16,12 +16,12 @@ a { color:inherit; } * { font-size:12pt; font-size: 1em; } .subxComment { color: #005faf; } .subxS2Comment { color: #8a8a8a; } +.subxTest { color: #5f8700; } +.subxFunction { color: #af5f00; text-decoration: underline; } .LineNr { } -.SpecialChar { color: #d70000; } .subxS1Comment { color: #0000af; } -.subxFunction { color: #af5f00; text-decoration: underline; } +.SpecialChar { color: #d70000; } .Constant { color: #008787; } -.subxTest { color: #5f8700; } .subxH1Comment { color: #005faf; text-decoration: underline; } --> @@ -64,12 +64,12 @@ if ('onhashchange' in window) { 4 5 array-equal?: # a: (addr array int), b: (addr array int) -> eax: boolean 6 # pseudocode: - 7 # lena = a->length - 8 # if (lena != b->length) return false + 7 # asize = a->size + 8 # if (asize != b->size) return false 9 # i = 0 10 # curra = a->data 11 # currb = b->data - 12 # while i < lena + 12 # while i < asize 13 # i1 = *curra 14 # i2 = *currb 15 # if (c1 != c2) return false @@ -78,7 +78,7 @@ if ('onhashchange' in window) { 18 # 19 # registers: 20 # i: ecx - 21 # lena: edx + 21 # asize: edx 22 # curra: esi 23 # currb: edi 24 # i1: eax @@ -97,10 +97,10 @@ if ('onhashchange' in window) { 37 8b/-> *(ebp+8) 6/r32/esi 38 # edi = b 39 8b/-> *(ebp+0xc) 7/r32/edi - 40 # var lena/edx: int = a->length + 40 # var asize/edx: int = a->size 41 8b/-> *esi 2/r32/edx - 42 $array-equal?:lengths: - 43 # if (lena != b->length) return false + 42 $array-equal?:sizes: + 43 # if (asize != b->size) return false 44 39/compare *edi 2/r32/edx 45 75/jump-if-!= $array-equal?:false/disp8 46 # var curra/esi: (addr byte) = a->data @@ -108,11 +108,11 @@ if ('onhashchange' in window) { 48 # var currb/edi: (addr byte) = b->data 49 81 0/subop/add %edi 4/imm32 50 # var i/ecx: int = 0 - 51 31/xor %ecx 1/r32/ecx + 51 31/xor-with %ecx 1/r32/ecx 52 # var vala/eax: int 53 # var valb/ebx: int 54 $array-equal?:loop: - 55 # if (i >= lena) return true + 55 # if (i >= asize) return true 56 39/compare %ecx 2/r32/edx 57 7d/jump-if->= $array-equal?:true/disp8 58 # var vala/eax: int = *curra @@ -156,507 +156,321 @@ if ('onhashchange' in window) { 96 # var edx: (array _) = [] 97 68/push 0/imm32/size 98 89/<- %edx 4/r32/esp - 99 # eax = array-equal?(ecx, edx) -100 # . . push args -101 52/push-edx -102 51/push-ecx -103 # . . call -104 e8/call array-equal?/disp32 -105 # . . discard args -106 81 0/subop/add %esp 8/imm32 -107 # check-ints-equal(eax, 1, msg) -108 # . . push args -109 68/push "F - test-compare-empty-with-empty-array"/imm32 -110 68/push 1/imm32/true -111 50/push-eax -112 # . . call -113 e8/call check-ints-equal/disp32 -114 # . . discard args -115 81 0/subop/add %esp 0xc/imm32 -116 # . epilogue -117 89/<- %esp 5/r32/ebp -118 5d/pop-to-ebp -119 c3/return -120 -121 test-compare-empty-with-non-empty-array: # also checks length-mismatch code path -122 # . prologue -123 55/push-ebp -124 89/<- %ebp 4/r32/esp -125 # var ecx: (array int) = [1] -126 68/push 1/imm32 -127 68/push 4/imm32/size -128 89/<- %ecx 4/r32/esp -129 # var edx: (array int) = [] -130 68/push 0/imm32/size -131 89/<- %edx 4/r32/esp -132 # eax = array-equal?(ecx, edx) -133 # . . push args -134 52/push-edx -135 51/push-ecx -136 # . . call -137 e8/call array-equal?/disp32 -138 # . . discard args -139 81 0/subop/add %esp 8/imm32 -140 # check-ints-equal(eax, 0, msg) -141 # . . push args -142 68/push "F - test-compare-empty-with-non-empty-array"/imm32 -143 68/push 0/imm32/false -144 50/push-eax -145 # . . call -146 e8/call check-ints-equal/disp32 -147 # . . discard args -148 81 0/subop/add %esp 0xc/imm32 -149 # . epilogue -150 89/<- %esp 5/r32/ebp -151 5d/pop-to-ebp -152 c3/return -153 -154 test-compare-equal-arrays: -155 # . prologue -156 55/push-ebp -157 89/<- %ebp 4/r32/esp -158 # var ecx: (array int) = [1, 2, 3] -159 68/push 3/imm32 -160 68/push 2/imm32 -161 68/push 1/imm32 -162 68/push 0xc/imm32/size -163 89/<- %ecx 4/r32/esp -164 # var edx: (array int) = [1, 2, 3] -165 68/push 3/imm32 -166 68/push 2/imm32 -167 68/push 1/imm32 -168 68/push 0xc/imm32/size -169 89/<- %edx 4/r32/esp -170 # eax = array-equal?(ecx, edx) -171 # . . push args -172 52/push-edx -173 51/push-ecx -174 # . . call -175 e8/call array-equal?/disp32 -176 # . . discard args -177 81 0/subop/add %esp 8/imm32 -178 # check-ints-equal(eax, 1, msg) -179 # . . push args -180 68/push "F - test-compare-equal-arrays"/imm32 -181 68/push 1/imm32/true -182 50/push-eax -183 # . . call -184 e8/call check-ints-equal/disp32 -185 # . . discard args -186 81 0/subop/add %esp 0xc/imm32 -187 # . epilogue -188 89/<- %esp 5/r32/ebp -189 5d/pop-to-ebp -190 c3/return -191 -192 test-compare-inequal-arrays-equal-lengths: -193 # . prologue -194 55/push-ebp -195 89/<- %ebp 4/r32/esp -196 # var ecx: (array int) = [1, 4, 3] -197 68/push 3/imm32 -198 68/push 4/imm32 -199 68/push 1/imm32 -200 68/push 0xc/imm32/size -201 89/<- %ecx 4/r32/esp -202 # var edx: (array int) = [1, 2, 3] -203 68/push 3/imm32 -204 68/push 2/imm32 -205 68/push 1/imm32 -206 68/push 0xc/imm32/size -207 89/<- %edx 4/r32/esp -208 # eax = array-equal?(ecx, edx) -209 # . . push args -210 52/push-edx -211 51/push-ecx -212 # . . call -213 e8/call array-equal?/disp32 -214 # . . discard args -215 81 0/subop/add %esp 8/imm32 -216 # check-ints-equal(eax, 0, msg) -217 # . . push args -218 68/push "F - test-compare-inequal-arrays-equal-lengths"/imm32 -219 68/push 0/imm32/false -220 50/push-eax -221 # . . call -222 e8/call check-ints-equal/disp32 -223 # . . discard args -224 81 0/subop/add %esp 0xc/imm32 -225 # . epilogue -226 89/<- %esp 5/r32/ebp -227 5d/pop-to-ebp -228 c3/return -229 -230 parse-array-of-ints: # ad: (addr allocation-descriptor), s: (addr string) -> result/eax: (handle array int) -231 # pseudocode -232 # end = &s->data[s->length] -233 # curr = s->data -234 # size = 0 -235 # while true -236 # if (curr >= end) break -237 # curr = skip-chars-matching-in-slice(curr, end, ' ') -238 # if (curr >= end) break -239 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') -240 # ++size -241 # result = allocate(ad, (size+1)*4) -242 # result->size = (size+1)*4 -243 # var slice: slice = {s->data, 0} -244 # out = result->data -245 # while true -246 # if (slice->start >= end) break -247 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') -248 # if (slice->start >= end) break -249 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') -250 # *out = parse-hex-int-from-slice(slice) -251 # out += 4 -252 # slice->start = slice->end -253 # return result -254 # -255 # . prologue -256 55/push-ebp -257 89/<- %ebp 4/r32/esp -258 # . save registers -259 51/push-ecx -260 52/push-edx -261 53/push-ebx -262 56/push-esi -263 57/push-edi -264 # esi = s -265 8b/-> *(ebp+0xc) 6/r32/esi -266 # var curr/ecx: (addr byte) = s->data -267 8d/copy-address *(esi+4) 1/r32/ecx -268 # var end/edx: (addr byte) = &s->data[s->length] -269 # . edx = s->length -270 8b/-> *esi 2/r32/edx -271 # . edx += curr -272 01/add %edx 1/r32/ecx -273 # var size/ebx: int = 0 -274 31/xor %ebx 3/r32/ebx -275 $parse-array-of-ints:loop1: -276 # if (curr >= end) break -277 39/compare %ecx 2/r32/edx -278 73/jump-if-addr>= $parse-array-of-ints:break1/disp8 -279 # curr = skip-chars-matching-in-slice(curr, end, ' ') -280 # . eax = skip-chars-matching-in-slice(curr, end, ' ') -281 # . . push args -282 68/push 0x20/imm32/space -283 52/push-edx -284 51/push-ecx -285 # . . call -286 e8/call skip-chars-matching-in-slice/disp32 -287 # . . discard args -288 81 0/subop/add %esp 0xc/imm32 -289 # . ecx = eax -290 89/<- %ecx 0/r32/eax -291 # if (curr >= end) break -292 39/compare %ecx 2/r32/edx -293 73/jump-if-addr>= $parse-array-of-ints:break1/disp8 -294 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') -295 # . eax = skip-chars-not-matching-in-slice(curr, end, ' ') -296 # . . push args -297 68/push 0x20/imm32/space -298 52/push-edx -299 51/push-ecx -300 # . . call -301 e8/call skip-chars-not-matching-in-slice/disp32 -302 # . . discard args -303 81 0/subop/add %esp 0xc/imm32 -304 # . ecx = eax -305 89/<- %ecx 0/r32/eax -306 # size += 4 -307 81 0/subop/add %ebx 4/imm32 -308 eb/jump $parse-array-of-ints:loop1/disp8 -309 $parse-array-of-ints:break1: -310 # var result/edi: (handle array int) = allocate(ad, size+4) -311 # . eax = allocate(ad, size+4) -312 # . . push args -313 89/<- %eax 3/r32/ebx -314 05/add-to-eax 4/imm32 -315 50/push-eax -316 ff 6/subop/push *(ebp+8) -317 # . . call -318 e8/call allocate/disp32 -319 # . . discard args -320 81 0/subop/add %esp 8/imm32 -321 # . edi = eax -322 89/<- %edi 0/r32/eax -323 # result->size = size -324 89/<- *eax 3/r32/ebx -325 $parse-array-of-ints:pass2: -326 # var slice/ecx: slice = {s->data, 0} -327 68/push 0/imm32/end -328 8d/copy-address *(esi+4) 1/r32/ecx -329 51/push-ecx -330 89/<- %ecx 4/r32/esp -331 # var out/ebx: (addr byte) = result->data -332 8d/copy-address *(eax+4) 3/r32/ebx -333 $parse-array-of-ints:loop2: -334 # if (slice->start >= end) break -335 39/compare *ecx 2/r32/edx -336 73/jump-if-addr>= $parse-array-of-ints:end/disp8 -337 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') -338 # . eax = skip-chars-matching-in-slice(slice->start, end, ' ') -339 # . . push args -340 68/push 0x20/imm32/space -341 52/push-edx -342 ff 6/subop/push *ecx -343 # . . call -344 e8/call skip-chars-matching-in-slice/disp32 -345 # . . discard args -346 81 0/subop/add %esp 0xc/imm32 -347 # . slice->start = eax -348 89/<- *ecx 0/r32/eax -349 # if (slice->start >= end) break -350 39/compare *ecx 2/r32/edx -351 73/jump-if-addr>= $parse-array-of-ints:end/disp8 -352 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') -353 # . eax = skip-chars-not-matching-in-slice(curr, end, ' ') -354 # . . push args -355 68/push 0x20/imm32/space -356 52/push-edx -357 50/push-eax -358 # . . call -359 e8/call skip-chars-not-matching-in-slice/disp32 -360 # . . discard args -361 81 0/subop/add %esp 0xc/imm32 -362 # . slice->end = eax -363 89/<- *(ecx+4) 0/r32/eax -364 # *out = parse-hex-int-from-slice(slice) -365 # . eax = parse-hex-int-from-slice(slice) -366 # . . push args -367 51/push-ecx -368 # . . call -369 e8/call parse-hex-int-from-slice/disp32 -370 # . . discard args -371 81 0/subop/add %esp 4/imm32 -372 # . *out = eax -373 89/<- *ebx 0/r32/eax -374 # out += 4 -375 81 0/subop/add %ebx 4/imm32 -376 # slice->start = slice->end -377 8b/-> *(ecx+4) 0/r32/eax -378 89/<- *ecx 0/r32/eax -379 81 0/subop/add %ecx 4/imm32 -380 eb/jump $parse-array-of-ints:loop2/disp8 -381 $parse-array-of-ints:end: -382 # return edi -383 89/<- %eax 7/r32/edi -384 # . reclaim locals -385 81 0/subop/add %esp 8/imm32 -386 # . restore registers -387 5f/pop-to-edi -388 5e/pop-to-esi -389 5b/pop-to-ebx -390 5a/pop-to-edx -391 59/pop-to-ecx -392 # . epilogue -393 89/<- %esp 5/r32/ebp -394 5d/pop-to-ebp -395 c3/return -396 -397 test-parse-array-of-ints: -398 # . prologue -399 55/push-ebp -400 89/<- %ebp 4/r32/esp -401 # var ecx: (array int) = [1, 2, 3] -402 68/push 3/imm32 -403 68/push 2/imm32 -404 68/push 1/imm32 -405 68/push 0xc/imm32/size -406 89/<- %ecx 4/r32/esp -407 # eax = parse-array-of-ints(Heap, "1 2 3") -408 # . . push args -409 68/push "1 2 3"/imm32 -410 68/push Heap/imm32 -411 # . . call -412 e8/call parse-array-of-ints/disp32 -413 # . . discard args -414 81 0/subop/add %esp 8/imm32 -415 # eax = array-equal?(ecx, eax) -416 # . . push args -417 50/push-eax -418 51/push-ecx -419 # . . call -420 e8/call array-equal?/disp32 -421 # . . discard args -422 81 0/subop/add %esp 8/imm32 -423 # check-ints-equal(eax, 1, msg) -424 # . . push args -425 68/push "F - test-parse-array-of-ints"/imm32 -426 68/push 1/imm32/true -427 50/push-eax -428 # . . call -429 e8/call check-ints-equal/disp32 -430 # . . discard args -431 81 0/subop/add %esp 0xc/imm32 -432 # . epilogue -433 89/<- %esp 5/r32/ebp -434 5d/pop-to-ebp -435 c3/return -436 -437 test-parse-array-of-ints-empty: -438 # - empty string = empty array -439 # . prologue -440 55/push-ebp -441 89/<- %ebp 4/r32/esp -442 # eax = parse-array-of-ints(Heap, "") -443 # . . push args -444 68/push ""/imm32 -445 68/push Heap/imm32 -446 # . . call -447 e8/call parse-array-of-ints/disp32 -448 # . . discard args -449 81 0/subop/add %esp 8/imm32 -450 # check-ints-equal(*eax, 0, msg) -451 # . . push args -452 68/push "F - test-parse-array-of-ints-empty"/imm32 -453 68/push 0/imm32/size -454 ff 6/subop/push *eax -455 # . . call -456 e8/call check-ints-equal/disp32 -457 # . . discard args -458 81 0/subop/add %esp 0xc/imm32 -459 # . epilogue -460 89/<- %esp 5/r32/ebp -461 5d/pop-to-ebp -462 c3/return -463 -464 test-parse-array-of-ints-just-whitespace: -465 # - just whitespace = empty array -466 # . prologue -467 55/push-ebp -468 89/<- %ebp 4/r32/esp -469 # eax = parse-array-of-ints(Heap, " ") -470 # . . push args -471 68/push Space/imm32 -472 68/push Heap/imm32 -473 # . . call -474 e8/call parse-array-of-ints/disp32 -475 # . . discard args -476 81 0/subop/add %esp 8/imm32 -477 # check-ints-equal(*eax, 0, msg) -478 # . . push args -479 68/push "F - test-parse-array-of-ints-empty"/imm32 -480 68/push 0/imm32/size -481 ff 6/subop/push *eax -482 # . . call -483 e8/call check-ints-equal/disp32 -484 # . . discard args -485 81 0/subop/add %esp 0xc/imm32 -486 # . epilogue -487 89/<- %esp 5/r32/ebp -488 5d/pop-to-ebp -489 c3/return -490 -491 test-parse-array-of-ints-extra-whitespace: -492 # . prologue -493 55/push-ebp -494 89/<- %ebp 4/r32/esp -495 # var ecx: (array int) = [1, 2, 3] -496 68/push 3/imm32 -497 68/push 2/imm32 -498 68/push 1/imm32 -499 68/push 0xc/imm32/size -500 89/<- %ecx 4/r32/esp -501 # eax = parse-array-of-ints(Heap, " 1 2 3 ") -502 # . . push args -503 68/push " 1 2 3 "/imm32 -504 68/push Heap/imm32 -505 # . . call -506 e8/call parse-array-of-ints/disp32 -507 # . . discard args -508 81 0/subop/add %esp 8/imm32 -509 # eax = array-equal?(ecx, eax) -510 # . . push args -511 50/push-eax -512 51/push-ecx -513 # . . call -514 e8/call array-equal?/disp32 -515 # . . discard args -516 81 0/subop/add %esp 8/imm32 -517 # check-ints-equal(eax, 1, msg) -518 # . . push args -519 68/push "F - test-parse-array-of-ints-extra-whitespace"/imm32 -520 68/push 1/imm32/true -521 50/push-eax -522 # . . call -523 e8/call check-ints-equal/disp32 -524 # . . discard args -525 81 0/subop/add %esp 0xc/imm32 -526 # . epilogue -527 89/<- %esp 5/r32/ebp -528 5d/pop-to-ebp -529 c3/return -530 -531 # helper for later tests -532 # compare an array with a string representation of an array literal -533 check-array-equal: # a: (addr array int), expected: (addr string), msg: (addr string) -534 # . prologue -535 55/push-ebp -536 89/<- %ebp 4/r32/esp -537 # . save registers -538 50/push-eax -539 # var b/ecx: (handle array int) = parse-array-of-ints(Heap, expected) -540 # . eax = parse-array-of-ints(Heap, expected) -541 # . . push args -542 ff 6/subop/push *(ebp+0xc) -543 68/push Heap/imm32 -544 # . . call -545 e8/call parse-array-of-ints/disp32 -546 # . . discard args -547 81 0/subop/add %esp 8/imm32 -548 # . b = eax -549 89/<- %ecx 0/r32/eax -550 # eax = array-equal?(a, b) -551 # . . push args -552 51/push-ecx -553 ff 6/subop/push *(ebp+8) -554 # . . call -555 e8/call array-equal?/disp32 -556 # . . discard args -557 81 0/subop/add %esp 8/imm32 -558 # check-ints-equal(eax, 1, msg) -559 # . . push args -560 ff 6/subop/push *(ebp+0x10) -561 68/push 1/imm32 -562 50/push-eax -563 # . . call -564 e8/call check-ints-equal/disp32 -565 # . . discard args -566 81 0/subop/add %esp 0xc/imm32 -567 $check-array-equal:end: -568 # . restore registers -569 58/pop-to-eax -570 # . epilogue -571 89/<- %esp 5/r32/ebp -572 5d/pop-to-ebp -573 c3/return -574 -575 test-check-array-equal: -576 # . prologue -577 55/push-ebp -578 89/<- %ebp 4/r32/esp -579 # var ecx: (array int) = [1, 2, 3] -580 68/push 3/imm32 -581 68/push 2/imm32 -582 68/push 1/imm32 -583 68/push 0xc/imm32/size -584 89/<- %ecx 4/r32/esp -585 # check-array-equal(ecx, "1 2 3", "msg") -586 # . . push args -587 68/push "F - test-check-array-equal"/imm32 -588 68/push "1 2 3"/imm32 -589 51/push-ecx -590 # . . call -591 e8/call check-array-equal/disp32 -592 # . . discard args -593 81 0/subop/add %esp 8/imm32 -594 # . epilogue -595 89/<- %esp 5/r32/ebp -596 5d/pop-to-ebp -597 c3/return -598 -599 # . . vim:nowrap:textwidth=0 + 99 # +100 (array-equal? %ecx %edx) # => eax +101 (check-ints-equal %eax 1 "F - test-compare-empty-with-empty-array") +102 # . epilogue +103 89/<- %esp 5/r32/ebp +104 5d/pop-to-ebp +105 c3/return +106 +107 test-compare-empty-with-non-empty-array: # also checks size-mismatch code path +108 # . prologue +109 55/push-ebp +110 89/<- %ebp 4/r32/esp +111 # var ecx: (array int) = [1] +112 68/push 1/imm32 +113 68/push 4/imm32/size +114 89/<- %ecx 4/r32/esp +115 # var edx: (array int) = [] +116 68/push 0/imm32/size +117 89/<- %edx 4/r32/esp +118 # +119 (array-equal? %ecx %edx) # => eax +120 (check-ints-equal %eax 0 "F - test-compare-empty-with-non-empty-array") +121 # . epilogue +122 89/<- %esp 5/r32/ebp +123 5d/pop-to-ebp +124 c3/return +125 +126 test-compare-equal-arrays: +127 # . prologue +128 55/push-ebp +129 89/<- %ebp 4/r32/esp +130 # var ecx: (array int) = [1, 2, 3] +131 68/push 3/imm32 +132 68/push 2/imm32 +133 68/push 1/imm32 +134 68/push 0xc/imm32/size +135 89/<- %ecx 4/r32/esp +136 # var edx: (array int) = [1, 2, 3] +137 68/push 3/imm32 +138 68/push 2/imm32 +139 68/push 1/imm32 +140 68/push 0xc/imm32/size +141 89/<- %edx 4/r32/esp +142 # +143 (array-equal? %ecx %edx) # => eax +144 (check-ints-equal %eax 1 "F - test-compare-equal-arrays") +145 # . epilogue +146 89/<- %esp 5/r32/ebp +147 5d/pop-to-ebp +148 c3/return +149 +150 test-compare-inequal-arrays-equal-sizes: +151 # . prologue +152 55/push-ebp +153 89/<- %ebp 4/r32/esp +154 # var ecx: (array int) = [1, 4, 3] +155 68/push 3/imm32 +156 68/push 4/imm32 +157 68/push 1/imm32 +158 68/push 0xc/imm32/size +159 89/<- %ecx 4/r32/esp +160 # var edx: (array int) = [1, 2, 3] +161 68/push 3/imm32 +162 68/push 2/imm32 +163 68/push 1/imm32 +164 68/push 0xc/imm32/size +165 89/<- %edx 4/r32/esp +166 # +167 (array-equal? %ecx %edx) # => eax +168 (check-ints-equal %eax 0 "F - test-compare-inequal-arrays-equal-sizes") +169 # . epilogue +170 89/<- %esp 5/r32/ebp +171 5d/pop-to-ebp +172 c3/return +173 +174 parse-array-of-ints: # ad: (addr allocation-descriptor), s: (addr string), out: (addr handle array int) +175 # pseudocode +176 # end = &s->data[s->size] +177 # curr = s->data +178 # size = 0 +179 # while true +180 # if (curr >= end) break +181 # curr = skip-chars-matching-in-slice(curr, end, ' ') +182 # if (curr >= end) break +183 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') +184 # ++size +185 # allocate-array(ad, size*4, out) +186 # var slice: slice = {s->data, 0} +187 # curr = lookup(out)->data +188 # while true +189 # if (slice->start >= end) break +190 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') +191 # if (slice->start >= end) break +192 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') +193 # *curr = parse-hex-int-from-slice(slice) +194 # curr += 4 +195 # slice->start = slice->end +196 # return result +197 # +198 # . prologue +199 55/push-ebp +200 89/<- %ebp 4/r32/esp +201 # . save registers +202 50/push-eax +203 51/push-ecx +204 52/push-edx +205 53/push-ebx +206 56/push-esi +207 57/push-edi +208 # esi = s +209 8b/-> *(ebp+0xc) 6/r32/esi +210 # var curr/ecx: (addr byte) = s->data +211 8d/copy-address *(esi+4) 1/r32/ecx +212 # var end/edx: (addr byte) = &s->data[s->size] +213 # . edx = s->size +214 8b/-> *esi 2/r32/edx +215 # . edx += curr +216 01/add-to %edx 1/r32/ecx +217 # var size/ebx: int = 0 +218 31/xor-with %ebx 3/r32/ebx +219 $parse-array-of-ints:loop1: +220 # if (curr >= end) break +221 39/compare %ecx 2/r32/edx +222 73/jump-if-addr>= $parse-array-of-ints:break1/disp8 +223 # curr = skip-chars-matching-in-slice(curr, end, ' ') +224 (skip-chars-matching-in-slice %ecx %edx 0x20) # => eax +225 89/<- %ecx 0/r32/eax +226 # if (curr >= end) break +227 39/compare %ecx 2/r32/edx +228 73/jump-if-addr>= $parse-array-of-ints:break1/disp8 +229 # curr = skip-chars-not-matching-in-slice(curr, end, ' ') +230 (skip-chars-not-matching-in-slice %ecx %edx 0x20) # => eax +231 89/<- %ecx 0/r32/eax +232 # size += 4 +233 81 0/subop/add %ebx 4/imm32 +234 eb/jump $parse-array-of-ints:loop1/disp8 +235 $parse-array-of-ints:break1: +236 (allocate-array *(ebp+8) %ebx *(ebp+0x10)) +237 $parse-array-of-ints:pass2: +238 # var slice/edi: slice = {s->data, 0} +239 68/push 0/imm32/end +240 8d/copy-address *(esi+4) 7/r32/edi +241 57/push-edi +242 89/<- %edi 4/r32/esp +243 # curr = lookup(out)->data +244 8b/-> *(ebp+0x10) 0/r32/eax +245 (lookup *eax *(eax+4)) # => eax +246 8d/copy-address *(eax+4) 1/r32/ecx +247 $parse-array-of-ints:loop2: +248 # if (slice->start >= end) break +249 39/compare *edi 2/r32/edx +250 73/jump-if-addr>= $parse-array-of-ints:end/disp8 +251 # slice->start = skip-chars-matching-in-slice(slice->start, end, ' ') +252 (skip-chars-matching-in-slice *edi %edx 0x20) # => eax +253 89/<- *edi 0/r32/eax +254 # if (slice->start >= end) break +255 39/compare *edi 2/r32/edx +256 73/jump-if-addr>= $parse-array-of-ints:end/disp8 +257 # slice->end = skip-chars-not-matching-in-slice(slice->start, end, ' ') +258 (skip-chars-not-matching-in-slice *edi %edx 0x20) # => eax +259 89/<- *(edi+4) 0/r32/eax +260 # *curr = parse-hex-int-from-slice(slice) +261 (parse-hex-int-from-slice %edi) +262 89/<- *ecx 0/r32/eax +263 # curr += 4 +264 81 0/subop/add %ecx 4/imm32 +265 # slice->start = slice->end +266 8b/-> *(edi+4) 0/r32/eax +267 89/<- *edi 0/r32/eax +268 eb/jump $parse-array-of-ints:loop2/disp8 +269 $parse-array-of-ints:end: +270 # . reclaim locals +271 81 0/subop/add %esp 8/imm32 +272 # . restore registers +273 5f/pop-to-edi +274 5e/pop-to-esi +275 5b/pop-to-ebx +276 5a/pop-to-edx +277 59/pop-to-ecx +278 58/pop-to-eax +279 # . epilogue +280 89/<- %esp 5/r32/ebp +281 5d/pop-to-ebp +282 c3/return +283 +284 test-parse-array-of-ints: +285 # . prologue +286 55/push-ebp +287 89/<- %ebp 4/r32/esp +288 # var h/esi: (handle array int) +289 68/push 0/imm32 +290 68/push 0/imm32 +291 89/<- %esi 4/r32/esp +292 # var ecx: (array int) = [1, 2, 3] +293 68/push 3/imm32 +294 68/push 2/imm32 +295 68/push 1/imm32 +296 68/push 0xc/imm32/size +297 89/<- %ecx 4/r32/esp +298 # +299 (parse-array-of-ints Heap "1 2 3" %esi) +300 (lookup *esi *(esi+4)) # => eax +301 (array-equal? %ecx %eax) # => eax +302 (check-ints-equal %eax 1 "F - test-parse-array-of-ints") +303 # . epilogue +304 89/<- %esp 5/r32/ebp +305 5d/pop-to-ebp +306 c3/return +307 +308 test-parse-array-of-ints-empty: +309 # - empty string = empty array +310 # . prologue +311 55/push-ebp +312 89/<- %ebp 4/r32/esp +313 # var h/esi: handle +314 68/push 0/imm32 +315 68/push 0/imm32 +316 89/<- %esi 4/r32/esp +317 # +318 (parse-array-of-ints Heap "" %esi) +319 (lookup *esi *(esi+4)) # => eax +320 (check-ints-equal *eax 0 "F - test-parse-array-of-ints-empty") +321 # . epilogue +322 89/<- %esp 5/r32/ebp +323 5d/pop-to-ebp +324 c3/return +325 +326 test-parse-array-of-ints-just-whitespace: +327 # - just whitespace = empty array +328 # . prologue +329 55/push-ebp +330 89/<- %ebp 4/r32/esp +331 # var h/esi: handle +332 68/push 0/imm32 +333 68/push 0/imm32 +334 89/<- %esi 4/r32/esp +335 # +336 (parse-array-of-ints Heap Space %esi) +337 (lookup *esi *(esi+4)) # => eax +338 (check-ints-equal *eax 0 "F - test-parse-array-of-ints-just-whitespace") +339 # . epilogue +340 89/<- %esp 5/r32/ebp +341 5d/pop-to-ebp +342 c3/return +343 +344 test-parse-array-of-ints-extra-whitespace: +345 # . prologue +346 55/push-ebp +347 89/<- %ebp 4/r32/esp +348 # var h/esi: handle +349 68/push 0/imm32 +350 68/push 0/imm32 +351 89/<- %esi 4/r32/esp +352 # var ecx: (array int) = [1, 2, 3] +353 68/push 3/imm32 +354 68/push 2/imm32 +355 68/push 1/imm32 +356 68/push 0xc/imm32/size +357 89/<- %ecx 4/r32/esp +358 # +359 (parse-array-of-ints Heap " 1 2 3 " %esi) +360 (lookup *esi *(esi+4)) # => eax +361 (array-equal? %ecx %eax) # => eax +362 (check-ints-equal %eax 1 "F - test-parse-array-of-ints-extra-whitespace") +363 # . epilogue +364 89/<- %esp 5/r32/ebp +365 5d/pop-to-ebp +366 c3/return +367 +368 # helper for later tests +369 # compare an array with a string representation of an array literal +370 check-array-equal: # a: (addr array int), expected: (addr string), msg: (addr string) +371 # . prologue +372 55/push-ebp +373 89/<- %ebp 4/r32/esp +374 # . save registers +375 50/push-eax +376 56/push-esi +377 # var h/esi: handle +378 68/push 0/imm32 +379 68/push 0/imm32 +380 89/<- %esi 4/r32/esp +381 # var b/eax: (addr array int) = parse-array-of-ints(Heap, expected) +382 (parse-array-of-ints Heap *(ebp+0xc) %esi) +383 (lookup *esi *(esi+4)) # => eax +384 # +385 (array-equal? *(ebp+8) %eax) +386 (check-ints-equal %eax 1 *(ebp+0x10)) +387 $check-array-equal:end: +388 # . restore registers +389 5e/pop-to-esi +390 58/pop-to-eax +391 # . epilogue +392 89/<- %esp 5/r32/ebp +393 5d/pop-to-ebp +394 c3/return +395 +396 test-check-array-equal: +397 # . prologue +398 55/push-ebp +399 89/<- %ebp 4/r32/esp +400 # var ecx: (array int) = [1, 2, 3] +401 68/push 3/imm32 +402 68/push 2/imm32 +403 68/push 1/imm32 +404 68/push 0xc/imm32/size +405 89/<- %ecx 4/r32/esp +406 # +407 (check-array-equal %ecx "1 2 3" "F - test-check-array-equal") +408 # . epilogue +409 89/<- %esp 5/r32/ebp +410 5d/pop-to-ebp +411 c3/return +412 +413 # . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0