diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-12-08 13:56:46 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-12-08 23:31:05 -0800 |
commit | 2a2a5b1e43b6aa650a41ab1ec68d9778c14cb649 (patch) | |
tree | 734619639755cf5b95490bdc4362bbef0a504881 /058stream-equal.subx | |
parent | a93cd189c95fc82a8f1db4e42e5f278bc642bb0c (diff) | |
download | mu-2a2a5b1e43b6aa650a41ab1ec68d9778c14cb649.tar.gz |
5804
Try to make the comments consistent with the type system we'll eventually have.
Diffstat (limited to '058stream-equal.subx')
-rw-r--r-- | 058stream-equal.subx | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/058stream-equal.subx b/058stream-equal.subx index 25330a52..bc3bc4d0 100644 --- a/058stream-equal.subx +++ b/058stream-equal.subx @@ -6,7 +6,7 @@ # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes # compare all the data in a stream (ignoring the read pointer) -stream-data-equal?: # f : (address stream), s : (address string) -> eax : boolean +stream-data-equal?: # f : (address stream byte), s : (address array byte) -> eax : boolean # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp @@ -19,20 +19,21 @@ stream-data-equal?: # f : (address stream), s : (address string) -> eax : boole 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # eax = f->write 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . . # copy *esi to eax - # maxf/edx = f->data + f->write + # var maxf/edx : (address byte) = &f->data[f->write] 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 2/r32/edx 0xc/disp8 . # copy esi+eax+12 to edx - # currf/esi = f->data + # var currf/esi : (address byte) = f->data 81 0/subop/add 3/mod/direct 6/rm32/esi . . . . . 0xc/imm32 # add to esi # edi = s 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 . # copy *(ebp+12) to edi - # if (f->write != s->length) return false $stream-data-equal?:compare-lengths: + # if (f->write != s->length) return false 39/compare 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # compare *edi and eax 75/jump-if-not-equal $stream-data-equal?:false/disp8 - # currs/edi = s->data + # var currs/edi : (address byte) = s->data 81 0/subop/add 3/mod/direct 7/rm32/edi . . . . . 4/imm32 # add to edi - # eax = ecx = 0 + # var eax : byte = 0 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax + # var ecx : byte = 0 31/xor 3/mod/direct 1/rm32/ecx . . . 1/r32/ecx . . # clear ecx $stream-data-equal?:loop: # if (currf >= maxf) return true @@ -190,7 +191,7 @@ test-stream-data-equal-length-check: c3/return # helper for later tests -check-stream-equal: # f : (address stream), s : (address string), msg : (address string) +check-stream-equal: # f : (address stream byte), s : (address array byte), msg : (address array byte) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp @@ -226,7 +227,7 @@ $check-stream-equal:end: # on success, set f->read to after the next newline # on failure, leave f->read unmodified # this function is usually used only in tests, so we repeatedly write f->read -next-stream-line-equal?: # f : (address stream), s : (address string) -> eax : boolean +next-stream-line-equal?: # f : (address stream byte), s : (address array byte) -> eax : boolean # pseudocode: # currf = f->read # bound: f->write # currs = 0 # bound : s->length @@ -273,30 +274,31 @@ next-stream-line-equal?: # f : (address stream), s : (address string) -> eax : 57/push-edi # esi = f 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi - # currf/ecx = f->read + # var currf/ecx : int = f->read 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx # edi = s 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 . # copy *(ebp+12) to edi - # currs/edx = 0 + # var currs/edx : int = 0 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . . # clear edx - # eax = ebx = 0 + # var c1/eax : byte = 0 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax + # var c2/ebx : byte = 0 31/xor 3/mod/direct 3/rm32/ebx . . . 3/r32/ebx . . # clear ebx $next-stream-line-equal?:loop: # if (currf >= f->write) break 3b/compare 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . . # compare ecx with *esi 7d/jump-if-greater-or-equal $next-stream-line-equal?:break/disp8 - # AL = *(f->data + f->read) + # c1 = f->data[f->read] 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0xc/disp8 . # copy byte at *(esi+ecx+12) to AL - # if (eax == '\n') break + # if (c1 == '\n') break 3d/compare-eax-and 0xa/imm32/newline 74/jump-if-equal $next-stream-line-equal?:break/disp8 # if (currs >= s->length) return false 3b/compare 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . . # compare edx with *edi 7d/jump-if-greater-or-equal $next-stream-line-equal?:false/disp8 - # BL = *(s->data + currs) + # c2 = s->data[currs] 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/edi 2/index/edx . 3/r32/BL 4/disp8 . # copy byte at *(edi+edx+4) to BL - # if (eax != ebx) return false + # if (c1 != c2) return false 39/compare 3/mod/direct 0/rm32/eax . . . 3/r32/ebx . . # compare eax and ebx 75/jump-if-not-equal $next-stream-line-equal?:false/disp8 # ++currf |