about summary refs log tree commit diff stats
path: root/subx/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-05-15 23:47:12 -0700
committerKartik Agaram <vc@akkartik.com>2019-05-15 23:47:12 -0700
commit438e5a0db04d7a6e1a7199771cca16720c0b4b8d (patch)
treeffed8f360daa0cb4e8b272ff1c02317aef4a94fa /subx/apps
parent50581f2a0e439f2bb8386406e3a493f17d387ab1 (diff)
downloadmu-438e5a0db04d7a6e1a7199771cca16720c0b4b8d.tar.gz
complete the skeleton of dquotes.subx
Still some failing tests:
  - emit-string-literal-data doesn't ignore metadata when computing the
    length of literal strings
  - emit-string-literal-data doesn't handle escape sequences

One issue doesn't have a failing test:
  - emit-metadata doesn't handle string literals containing '/'

All these open issues involve a common design question: how to parse a
'word' that includes a string literal that may include spaces.

For everything else I know words can't contain spaces and datums can't
contain slashes. But for string literals things are tougher.
Diffstat (limited to 'subx/apps')
-rwxr-xr-xsubx/apps/assortbin22287 -> 22516 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bin19446 -> 19675 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bbin20005 -> 20234 bytes
-rwxr-xr-xsubx/apps/dquotesbin24502 -> 25014 bytes
-rw-r--r--subx/apps/dquotes.subx140
-rwxr-xr-xsubx/apps/factorialbin18362 -> 18591 bytes
-rwxr-xr-xsubx/apps/handlebin19189 -> 19418 bytes
-rwxr-xr-xsubx/apps/hexbin22455 -> 22684 bytes
-rwxr-xr-xsubx/apps/packbin37047 -> 37276 bytes
9 files changed, 98 insertions, 42 deletions
diff --git a/subx/apps/assort b/subx/apps/assort
index 1cd0b6cf..227bf4e7 100755
--- a/subx/apps/assort
+++ b/subx/apps/assort
Binary files differdiff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index 03d3d0c3..8414e3ce 100755
--- a/subx/apps/crenshaw2-1
+++ b/subx/apps/crenshaw2-1
Binary files differdiff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b
index 60521cb0..5dddec43 100755
--- a/subx/apps/crenshaw2-1b
+++ b/subx/apps/crenshaw2-1b
Binary files differdiff --git a/subx/apps/dquotes b/subx/apps/dquotes
index 03e591f6..02102f04 100755
--- a/subx/apps/dquotes
+++ b/subx/apps/dquotes
Binary files differdiff --git a/subx/apps/dquotes.subx b/subx/apps/dquotes.subx
index 6cd8d6ea..4810bcad 100644
--- a/subx/apps/dquotes.subx
+++ b/subx/apps/dquotes.subx
@@ -31,7 +31,7 @@ Entry:  # run tests if necessary, convert stdin if not
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # . test()
-#?     e8/call  test-convert-is-idempotent-by-default/disp32
+#?     e8/call  test-convert-processes-string-literals/disp32
 #?     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
 #?     eb/jump  $main:end/disp8
 
@@ -256,6 +256,21 @@ $convert:next-line:
     # loop
     e9/jump  $convert:line-loop/disp32
 $convert:break:
+    # write-stream-data(out, new-data-segment)
+    # . . push args
+    57/push-EDI
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
+    # . . call
+    e8/call  write-stream-data/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # flush(out)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
+    # . . call
+    e8/call  flush/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
 $convert:end:
     # . reclaim locals
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x214/imm32       # add to ESP
@@ -318,6 +333,13 @@ process-string-literal:  # string-literal : (address slice), out : (address buff
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # emit-string-literal-data(out-segment, string-literal)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x8/disp8       .                 # push *(EBP+8)
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x10/disp8      .                 # push *(EBP+16)
+    # . . call
+    e8/call  emit-string-literal-data/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # write(out-segment, "\n")
     # . . push args
     68/push  Newline/imm32
@@ -722,32 +744,39 @@ test-convert-processes-string-literals:
     # called. We just want to make sure instructions using string literals
     # switch to a string variable with the right value.
     # (Modifying string literals completely off the radar for now.)
-#?     # dump output {{{
-#?     # . write(2/stderr, "result: ^")
-#?     # . . push args
-#?     68/push  "result: ^"/imm32
-#?     68/push  2/imm32/stderr
-#?     # . . call
-#?     e8/call  write/disp32
-#?     # . . discard args
-#?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-#?     # . write-stream(2/stderr, _test-output-stream)
-#?     # . . push args
-#?     68/push  _test-output-stream/imm32
-#?     68/push  2/imm32/stderr
-#?     # . . call
-#?     e8/call  write-stream/disp32
-#?     # . . discard args
-#?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-#?     # . write(2/stderr, "$\n")
-#?     # . . push args
-#?     68/push  "$\n"/imm32
-#?     68/push  2/imm32/stderr
-#?     # . . call
-#?     e8/call  write/disp32
-#?     # . . discard args
-#?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-#?     # }}}
+    # dump output {{{
+    # . write(2/stderr, "result: ^")
+    # . . push args
+    68/push  "result: ^"/imm32
+    68/push  2/imm32/stderr
+    # . . call
+    e8/call  write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . write-stream(2/stderr, _test-output-stream)
+    # . . push args
+    68/push  _test-output-stream/imm32
+    68/push  2/imm32/stderr
+    # . . call
+    e8/call  write-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . write(2/stderr, "$\n")
+    # . . push args
+    68/push  "$\n"/imm32
+    68/push  2/imm32/stderr
+    # . . call
+    e8/call  write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . rewind-stream(_test-output-stream)
+    # . . push args
+    68/push  _test-output-stream/imm32
+    # . . call
+    e8/call  rewind-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # }}}
     # . check-next-stream-line-equal(_test-output-stream, "== code ", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/0"/imm32
@@ -769,16 +798,16 @@ test-convert-processes-string-literals:
     # . check-next-stream-line-equal(_test-output-stream, "2 _string2/y ", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/2"/imm32
-    68/push  "2 3 "/imm32
+    68/push  "2 _string2/y "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-next-stream-line-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
-    # . check-next-stream-line-equal(_test-output-stream, "== data ", msg)
+    # . check-next-stream-line-equal(_test-output-stream, "== data", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/3"/imm32
-    68/push  "== data "/imm32
+    68/push  "== data"/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-next-stream-line-equal/disp32
@@ -787,7 +816,7 @@ test-convert-processes-string-literals:
     # . check-next-stream-line-equal(_test-output-stream, "_string1: ", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/4"/imm32
-    68/push  "_string1: "/imm32
+    68/push  "_string1:"/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-next-stream-line-equal/disp32
@@ -796,7 +825,7 @@ test-convert-processes-string-literals:
     # . check-next-stream-line-equal(_test-output-stream, "1/imm32 61/a ", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/5"/imm32
-    68/push  "1/imm32 61/a "/imm32
+    68/push  "0x00000001/imm32 61/a "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-next-stream-line-equal/disp32
@@ -805,7 +834,7 @@ test-convert-processes-string-literals:
     # . check-next-stream-line-equal(_test-output-stream, "_string2: ", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/6"/imm32
-    68/push  "_string2: "/imm32
+    68/push  "_string2:"/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-next-stream-line-equal/disp32
@@ -814,7 +843,7 @@ test-convert-processes-string-literals:
     # . check-next-stream-line-equal(_test-output-stream, "2/imm32 62/b 63/c ", msg)
     # . . push args
     68/push  "F - test-convert-processes-string-literals/7"/imm32
-    68/push  "2/imm32 62/b 63/c "/imm32
+    68/push  "0x00000002/imm32 62/b 63/c "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-next-stream-line-equal/disp32
@@ -828,6 +857,9 @@ test-convert-processes-string-literals:
 # generate the data segment contents byte by byte for a given slice
 emit-string-literal-data:  # out : (address stream), word : (address slice)
     # pseudocode
+    #   var len = word->end - word->start - 2  # ignore the double-quotes
+    #   append-int32-hex(out, len)
+    #   write(out, "/imm32")
     #   curr = word->start
     #   ++curr  # skip '"'
     #   while true
@@ -853,6 +885,30 @@ emit-string-literal-data:  # out : (address stream), word : (address slice)
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   0xc/disp8       .                 # copy *(EBP+12) to ESI
     # curr/EDX = word->start
     8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           2/r32/EDX   .               .                 # copy *ESI to EDX
+$emit-string-literal-data:emit-length:
+    # TODO: handle metadata here
+    # print(out, "#{len}/imm32 ")
+    # . len/ECX = word->end - word->start - 2
+    8b/copy                         1/mod/*+disp8   6/rm32/ESI    .           .             .           1/r32/ECX   4/disp8         .                 # copy *(ESI+4) to ECX
+    29/subtract                     3/mod/direct    1/rm32/ECX    .           .             .           2/r32/EDX   .               .                 # subtract EDX from ECX
+    81          5/subop/subtract    3/mod/direct    1/rm32/ECX    .           .             .           .           .               2/imm32           # subtract from ECX
+    # . print-int32(out, len)
+    # . . push args
+    51/push-ECX
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
+    # . . call
+    e8/call  print-int32/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . write(out, "/imm32 ")
+    # . . push args
+    68/push  "/imm32 "/imm32
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
+    # . . call
+    e8/call  write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+$emit-string-literal-data:loop-init:
     # ++curr  # skip initial '"'
     42/increment-EDX
     # max/ESI = word->end
@@ -1012,10 +1068,10 @@ test-emit-string-literal-data:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # . check-stream-equal(_test-output-stream, "61/a 62/b 63/c ", msg)
+    # . check-stream-equal(_test-output-stream, "3/imm32 61/a 62/b 63/c ", msg)
     # . . push args
     68/push  "F - test-emit-string-literal-data"/imm32
-    68/push  "61/a 62/b 63/c "/imm32
+    68/push  "0x00000003/imm32 61/a 62/b 63/c "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-stream-equal/disp32
@@ -1076,10 +1132,10 @@ test-emit-string-literal-data-empty:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # . check-stream-equal(_test-output-stream, "", msg)
+    # . check-stream-equal(_test-output-stream, "0/imm32 ", msg)
     # . . push args
     68/push  "F - test-emit-string-literal-data-empty"/imm32
-    68/push  ""/imm32
+    68/push  "0x00000000/imm32 "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-stream-equal/disp32
@@ -1141,10 +1197,10 @@ test-emit-string-literal-data-no-metadata-for-non-alphanumerics:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # . check-stream-equal(_test-output-stream, "61/a 20 62/b ", msg)  # ideally we'd like to say '20/space' but that requires managing names for codepoints
+    # . check-stream-equal(_test-output-stream, "3/imm32 61/a 20 62/b ", msg)  # ideally we'd like to say '20/space' but that requires managing names for codepoints
     # . . push args
     68/push  "F - test-emit-string-literal-data-no-metadata-for-non-alphanumerics"/imm32
-    68/push  "61/a 20 62/b "/imm32
+    68/push  "0x00000003/imm32 61/a 20 62/b "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-stream-equal/disp32
@@ -1205,10 +1261,10 @@ test-emit-string-literal-data-handles-escape-sequences:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # . check-stream-equal(_test-output-stream, "61/a 22 62/b ", msg)
+    # . check-stream-equal(_test-output-stream, "3/imm32 61/a 22 62/b ", msg)
     # . . push args
     68/push  "F - test-emit-string-literal-data-handles-escape-sequences"/imm32
-    68/push  "61/a 22 62/b "/imm32
+    68/push  "3/imm32 61/a 22 62/b "/imm32
     68/push  _test-output-stream/imm32
     # . . call
     e8/call  check-stream-equal/disp32
diff --git a/subx/apps/factorial b/subx/apps/factorial
index c18b8bcc..ab71d3b2 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle
index 4fe1e044..4d4bea1f 100755
--- a/subx/apps/handle
+++ b/subx/apps/handle
Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex
index 59170942..f69e7bb3 100755
--- a/subx/apps/hex
+++ b/subx/apps/hex
Binary files differdiff --git a/subx/apps/pack b/subx/apps/pack
index f2149b59..1c76d927 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differ