about summary refs log tree commit diff stats
path: root/subx/apps
diff options
context:
space:
mode:
authornc <charles.saternos@gmail.com>2019-05-18 12:25:44 -0400
committernc <charles.saternos@gmail.com>2019-05-18 12:25:44 -0400
commit426e05542a76f22e0fe575d8f9e2081f9203f438 (patch)
tree8c7167a28d5c925b19becefe9a8a20aa46f081c0 /subx/apps
parentba9ed69c238d2049b8288a32dd5dfa5626db6d86 (diff)
downloadmu-426e05542a76f22e0fe575d8f9e2081f9203f438.tar.gz
implement skip-string-in-slice and reimplement skip-string in terms of skip-string-in-slice
Diffstat (limited to 'subx/apps')
-rw-r--r--subx/apps/dquotes.subx112
1 files changed, 75 insertions, 37 deletions
diff --git a/subx/apps/dquotes.subx b/subx/apps/dquotes.subx
index 058b4d58..513b5afb 100644
--- a/subx/apps/dquotes.subx
+++ b/subx/apps/dquotes.subx
@@ -2060,51 +2060,39 @@ skip-string:  # line : (address stream)
     50/push-EAX
     51/push-ECX
     52/push-EDX
-    53/push-EBX
 
-    # EDX = line
-    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         2/r32/EDX   8/disp8         .                 # copy *(EBP+8) to EDX
+    # ECX = line
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         1/r32/ECX   8/disp8         .                 # copy *(EBP+8) to ECX
 
-    # ECX = line->read
-    8b/copy                         1/mod/*+disp8   2/rm32/EDX    .           .                         1/r32/ECX   4/disp8         .                 # copy *(EDX+4) to ECX
+    # skip-string-in-slice(&line->data[line->read], &line->data[line->end])
+    # . push &line->data[line->end]
+    # . . EDX = line->end
+    8b/copy                         1/mod/*+disp8   1/rm32/ECX    .           .                         2/r32/EDX   8/disp8         .                 # copy *(ECX+8) to EDX
+    # . . EDX = &line->data[line->end]
+    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    1/base/ECX  2/index/EDX   .           2/r32/EDX   0xc/disp8       .                 # copy ECX+EDX+12 to EDX
+    # . . push EDX
+    52/push-EDX
 
-    # EAX = 0
-    31/xor                          3/mod/direct    0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # clear EAX
-    # loop:
-$skip-string:loop:
-    #   ECX++
-    41/increment-ECX                                                                                                                                  # ECX++
+    # . push &line->data[line->read]
+    # . . EDX = line->read
+    8b/copy                         1/mod/*+disp8   1/rm32/ECX    .           .                         2/r32/EDX   4/disp8         .                 # copy *(ECX+4) to EDX
+    # . . EDX = &line->data[line->read]
+    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    1/base/ECX  2/index/EDX   .           2/r32/EDX   0xc/disp8       .                 # copy ECX+EDX+12 to EDX
+    # . . push EDX
+    52/push-EDX
 
-    #   EAX = *((char*) line->data/EDX[line->read/ECX])
-    8a/copy-byte                    1/mod/*+disp8   4/rm32/sib    2/base/EDX  1/index/ECX   .           0/r32/EAX   0xc/disp8       .                 # copy *(EDX+ECX+12) to EBX
-    #   if EAX == '\':
-    #     goto escaped-char
-    3d/compare-EAX-and              0x5c/imm32/backslash
-    74/jump-if-equal  $skip-string:escaped-char/disp8
-    #   else if EAX == '"':
-    #     break
-    3d/compare-EAX-and              0x22/imm32/double-quote
-    74/jump-if-equal  $skip-string:loop-end/disp8
-    #   else:
-    #     continue loop
-    eb/jump  $skip-string:loop/disp8
+    e8/call skip-string-in-slice/disp32
+    # . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 
-$skip-string:escaped-char:
-    #   ECX++ (step over escaped charcter)
-    41/increment-ECX                                                                                                                                  # ECX++
-    #   continue loop
-    eb/jump  $skip-string:loop/disp8
-$skip-string:loop-end:
-    # step over last '"'
-    # . ECX++
-    41/increment-ECX                                                                                                                                  # ECX++
+    # EAX = new-&line->data[line->read]/EAX - &line->data[line->read]/EDX
+    2b/subtract                     3/mod/direct    2/rm32/EDX    .           .             .           0/r32/EAX   .               .                 # EAX = EAX - EDX
 
-    # line->read = ECX
-    89/copy                         1/mod/*+disp8   2/rm32/EDX    .           .             .           1/r32/ECX   4/disp8         .                 # copy ECX to *(EDX+4)
+    # line/ECX->read = EDX
+    89/copy                         1/mod/*+disp8   1/rm32/ECX    .           .                         0/r32/EAX   4/disp8         .                 # copy EAX to *(ECX+4)
 
 $skip-string:end:
     # . restore registers
-    5b/pop-to-EBX
     5a/pop-to-EDX
     59/pop-to-ECX
     58/pop-to-EAX
@@ -2277,9 +2265,59 @@ skip-string-in-slice:  # curr : (address byte), end : (address byte) -> new_curr
     # . prolog
     55/push-EBP
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+
     # . save registers
+    51/push-ECX
+    52/push-EDX
+    53/push-EBX
+
+    # ECX = curr
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         1/r32/ECX   8/disp8         .                 # copy *(EBP+8) to ECX
+
+    # EDX = end
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .                         2/r32/EDX   0xc/disp8         .               # copy *(EBP+12) to EDX
+
+    # EAX = 0
+    31/xor                          3/mod/direct    0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # clear EAX
+    # loop:
+$skip-string-in-slice:loop:
+    # . ECX++
+    41/increment-ECX                                                                                                                                  # ECX++
+
+    # . EAX = *((char*) ECX)
+    8a/copy-byte                    0/mod/indirect  1/rm32/ECX    .           .             .           0/r32/EAX   .               .                 # copy *ECX to EAX
+    # . if EAX == '\':
+    # . . goto escaped-char
+    3d/compare-EAX-and              0x5c/imm32/backslash
+    74/jump-if-equal  $skip-string-in-slice:escaped-char/disp8
+    # . else if EAX == '"':
+    # . . break
+    3d/compare-EAX-and              0x22/imm32/double-quote
+    74/jump-if-equal  $skip-string-in-slice:loop-end/disp8
+    # . else:
+    # . . continue loop
+    eb/jump  $skip-string-in-slice:loop/disp8
+
+$skip-string-in-slice:escaped-char:
+    # . ECX++ (step over escaped charcter)
+    41/increment-ECX                                                                                                                                  # ECX++
+    # . continue loop
+    eb/jump  $skip-string-in-slice:loop/disp8
+$skip-string-in-slice:loop-end:
+    # step over last '"'
+    # . ECX++
+    41/increment-ECX                                                                                                                                  # ECX++
+
+    # EAX = ECX for return
+    89/copy                         3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # copy ECX to EAX
+
+
 $skip-string-in-slice:end:
     # . restore registers
+    5b/pop-to-EBX
+    5a/pop-to-EDX
+    59/pop-to-ECX
+
     # . epilog
     89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
     5d/pop-to-EBP
@@ -2323,7 +2361,7 @@ test-skip-string-in-slice-ignores-spaces:
     55/push-EBP
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
     # setup: (EAX..ECX) = "\"a b\"/yz"
-    b8/copy-to-EAX  "\"abc\" def"/imm32
+    b8/copy-to-EAX  "\"a b\"/yz"/imm32
     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