about summary refs log tree commit diff stats
path: root/subx/075array-equal.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-05-26 10:37:28 -0700
committerKartik Agaram <vc@akkartik.com>2019-05-26 10:37:28 -0700
commitcb3d96bc29d86fbf4c35bbff50894d11252d15f9 (patch)
tree2f629181dd181d25903ad91bf9d21bf407d1968f /subx/075array-equal.subx
parent561028444397d2722130ef3bbf4a403acf7964b4 (diff)
downloadmu-cb3d96bc29d86fbf4c35bbff50894d11252d15f9.tar.gz
new primitive: check-array-equal
Diffstat (limited to 'subx/075array-equal.subx')
-rw-r--r--subx/075array-equal.subx68
1 files changed, 68 insertions, 0 deletions
diff --git a/subx/075array-equal.subx b/subx/075array-equal.subx
index e2b973f8..57eb3934 100644
--- a/subx/075array-equal.subx
+++ b/subx/075array-equal.subx
@@ -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: