new primitive: check-array-equal

This commit is contained in:
Kartik Agaram 2019-05-26 10:37:28 -07:00
parent 5610284443
commit cb3d96bc29
8 changed files with 68 additions and 0 deletions

View File

@ -555,6 +555,74 @@ test-parse-array-of-ints-extra-whitespace:
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 : (address array int), expected : (address string), msg : (address string)
# . prolog
55/push-EBP
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
# . save registers
50/push-EAX
# var b/ECX = parse-array-of-ints(Heap, expected)
# . EAX = parse-array-of-ints(Heap, expected)
# . . push args
ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12)
68/push Heap/imm32
# . . call
e8/call parse-array-of-ints/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
# . b = EAX
89/copy 3/mod/direct 1/rm32/ECX . . . 0/r32/EAX . . # copy EAX to ECX
# EAX = array-equal?(a, b)
# . . push args
51/push-ECX
ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8)
# . . call
e8/call array-equal?/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
# check-ints-equal(EAX, 1, msg)
# . . push args
ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0x10/disp8 . # push *(EBP+16)
68/push 1/imm32
50/push-EAX
# . . call
e8/call check-ints-equal/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP
$check-array-equal:end:
# . restore registers
58/pop-to-EAX
# . epilog
89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP
5d/pop-to-EBP
c3/return
test-check-array-equal:
# . prolog
55/push-EBP
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
# var ECX = [1, 2, 3]
68/push 3/imm32
68/push 2/imm32
68/push 1/imm32
68/push 0xc/imm32/size
89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX
# check-array-equal(ECX, "1 2 3", "msg")
# . . push args
68/push "F - test-check-array-equal"/imm32
68/push "1 2 3"/imm32
51/push-ECX
# . . call
e8/call check-array-equal/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP
# . epilog
89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP
5d/pop-to-EBP
c3/return
== data
Heap:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.