about summary refs log tree commit diff stats
path: root/subx/071next-token.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-01-20 23:19:40 -0800
committerKartik Agaram <vc@akkartik.com>2019-01-20 23:20:34 -0800
commitc65dee2d99a7d1a5f0fbc8826b616683713ebef6 (patch)
treeeacba0491629847d25aafd64f57ece2b8a5cc54b /subx/071next-token.subx
parent332cbba31f60c3915ba109a14105d4e8f7369a7a (diff)
downloadmu-c65dee2d99a7d1a5f0fbc8826b616683713ebef6.tar.gz
4938
Diffstat (limited to 'subx/071next-token.subx')
-rw-r--r--subx/071next-token.subx67
1 files changed, 31 insertions, 36 deletions
diff --git a/subx/071next-token.subx b/subx/071next-token.subx
index a3cd6035..41dd94f3 100644
--- a/subx/071next-token.subx
+++ b/subx/071next-token.subx
@@ -4,7 +4,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
 
 # main:
-#? e8/call test-skip-chars-matching-in-slice/disp32
+#? e8/call test-next-token-from-slice/disp32
     e8/call  run-tests/disp32  # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.
     # syscall(exit, Num-test-failures)
     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
@@ -166,33 +166,36 @@ test-next-token-eof:
 
 # extract the next run of characters that are different from a given 'delimiter' (skipping multiple delimiters if necessary)
 # on eof return an empty interval
-next-token-from-slice:  # in : (address slice), delimiter : byte, out : (address slice)
+next-token-from-slice:  # start : (address byte), end : (address byte), delimiter : byte, out : (address slice) -> <void>
     # . prolog
     55/push-EBP
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
     # . save registers
     50/push-EAX
-    56/push-ESI
+    51/push-ECX
+    52/push-EDX
     57/push-EDI
-    # ESI = in
-    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   8/disp8         .                 # copy *(EBP+8) to ESI
+    # ECX = end
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           1/r32/ECX   0xc/disp8       .                 # copy *(EBP+12) to ECX
+    # EDX = delimiter
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           2/r32/EDX   0x10/disp8      .                 # copy *(EBP+16) to EDX
     # EDI = out
-    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           7/r32/EDI   0x10/disp8      .                 # copy *(EBP+16) to EDI
-    # EAX = skip-chars-matching-in-slice(in->start, in->end, delimiter)
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           7/r32/EDI   0x14/disp8      .                 # copy *(EBP+20) to EDI
+    # EAX = skip-chars-matching-in-slice(start, end, delimiter)
     # . . push args
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
-    ff          6/subop/push        1/mod/*+disp8   6/rm32/ESI    .           .             .           .           4/disp8         .                 # push *(ESI+4)
-    ff          6/subop/push        0/mod/indirect  6/rm32/ESI    .           .             .           .           .               .                 # push *ESI
+    52/push-EDX
+    51/push-ECX
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
     # . . call
     e8/call  skip-chars-matching-in-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # out->start = EAX
     89/copy                         0/mod/indirect  7/rm32/EDI    .           .             .           0/r32/EAX   .               .                 # copy EAX to *EDI
-    # EAX = skip-chars-not-matching-in-slice(EAX, in->end, delimiter)
+    # EAX = skip-chars-not-matching-in-slice(EAX, end, delimiter)
     # . . push args
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
-    ff          6/subop/push        1/mod/*+disp8   6/rm32/ESI    .           .             .           .           4/disp8         .                 # push *(ESI+4)
+    52/push-EDX
+    51/push-ECX
     50/push-EAX
     # . . call
     e8/call  skip-chars-not-matching-in-slice/disp32
@@ -202,7 +205,8 @@ next-token-from-slice:  # in : (address slice), delimiter : byte, out : (address
     89/copy                         1/mod/*+disp8   7/rm32/EDI    .           .             .           0/r32/EAX   4/disp8         .                 # copy EAX to *(EDI+4)
     # . restore registers
     5f/pop-to-EDI
-    5e/pop-to-ESI
+    5a/pop-to-EDX
+    59/pop-to-ECX
     58/pop-to-EAX
     # . epilog
     89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
@@ -218,23 +222,20 @@ test-next-token-from-slice:
     8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy *EAX to ECX
     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/EAX  1/index/ECX   .           1/r32/ECX   4/disp8         .                 # copy EAX+ECX+4 to ECX
     05/add-to-EAX  4/imm32
-    # var in/ESI : (address slice) = {EAX, ECX}
-    51/push-ECX
-    50/push-EAX
-    89/copy                         3/mod/direct    6/rm32/ESI    .           .             .           4/r32/ESP   .               .                 # copy ESP to ESI
     # var out/EDI : (address slice) = {0, 0}
     68/push  0/imm32/end
     68/push  0/imm32/start
     89/copy                         3/mod/direct    7/rm32/EDI    .           .             .           4/r32/ESP   .               .                 # copy ESP to EDI
-    # next-token-from-slice(in, 0x20/space, out)
+    # next-token-from-slice(EAX, ECX, 0x20/space, out)
     # . . push args
     57/push-EDI
     68/push  0x20/imm32
-    56/push-ESI
+    51/push-ECX
+    50/push-EAX
     # . . call
     e8/call  next-token-from-slice/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # out->start should be at the 'a'
     # . check-ints-equal(out->start - in->start, 2, msg)
     # . . push args
@@ -242,7 +243,7 @@ test-next-token-from-slice:
     68/push  2/imm32
     # . . push out->start - in->start
     8b/copy                         0/mod/indirect  7/rm32/EDI    .           .             .           1/r32/ECX   .               .                 # copy *EDI to ECX
-    2b/subtract                     0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # subtract *ESI from ECX
+    2b/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract EAX from ECX
     51/push-ECX
     # . . call
     e8/call  check-ints-equal/disp32
@@ -255,7 +256,7 @@ test-next-token-from-slice:
     68/push  4/imm32
     # . . push out->end - in->start
     8b/copy                         1/mod/*+disp8   7/rm32/EDI    .           .             .           1/r32/ECX   4/disp8         .                 # copy *(EDI+4) to ECX
-    2b/subtract                     0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # subtract *ESI from ECX
+    2b/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract EAX from ECX
     51/push-ECX
     # . . call
     e8/call  check-ints-equal/disp32
@@ -270,23 +271,20 @@ test-next-token-from-slice-eof:
     # . prolog
     55/push-EBP
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
-    # var in/ESI : (address slice) = {0, 0}
-    51/push-ECX
-    50/push-EAX
-    89/copy                         3/mod/direct    6/rm32/ESI    .           .             .           4/r32/ESP   .               .                 # copy ESP to ESI
     # var out/EDI : (address slice) = {0, 0}
     68/push  0/imm32/end
     68/push  0/imm32/start
     89/copy                         3/mod/direct    7/rm32/EDI    .           .             .           4/r32/ESP   .               .                 # copy ESP to EDI
-    # next-token-from-slice(in, 0x20/space, out)
+    # next-token-from-slice(0, 0, 0x20/space, out)
     # . . push args
     57/push-EDI
     68/push  0x20/imm32
-    56/push-ESI
+    68/push  0/imm32
+    68/push  0/imm32
     # . . call
     e8/call  next-token-from-slice/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # out should be empty
     # . check-ints-equal(out->end - out->start, 0, msg)
     # . . push args
@@ -314,10 +312,6 @@ test-next-token-from-slice-nothing:
     8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy *EAX to ECX
     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/EAX  1/index/ECX   .           1/r32/ECX   4/disp8         .                 # copy EAX+ECX+4 to ECX
     05/add-to-EAX  4/imm32
-    # var in/ESI : (address slice) = {EAX, ECX}
-    51/push-ECX
-    50/push-EAX
-    89/copy                         3/mod/direct    6/rm32/ESI    .           .             .           4/r32/ESP   .               .                 # copy ESP to ESI
     # var out/EDI : (address slice) = {0, 0}
     68/push  0/imm32/end
     68/push  0/imm32/start
@@ -326,11 +320,12 @@ test-next-token-from-slice-nothing:
     # . . push args
     57/push-EDI
     68/push  0x20/imm32
-    56/push-ESI
+    51/push-ECX
+    50/push-EAX
     # . . call
     e8/call  next-token-from-slice/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # out should be empty
     # . check-ints-equal(out->end - out->start, 0, msg)
     # . . push args