about summary refs log tree commit diff stats
path: root/subx/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-16 23:34:33 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-16 23:40:25 -0700
commitc2a74205d690862d4df31682aa5bbe992227fda1 (patch)
treeb570f38927e21af0ab05d4864cfd3676bb2b0880 /subx/apps
parent70a999aaebbd05873be56b0460e0d4182397cfea (diff)
downloadmu-c2a74205d690862d4df31682aa5bbe992227fda1.tar.gz
5408
Bugfix ten: type error in `convert`. I was calling `rewind-stream` on a
`buffered-file`.

examples/ex1 is now just one nibble off the canonical.

I *have* found one missing feature in the self-hosted translator,
though: dquotes doesn't support newlines in strings, even though the C++
version does. dquotes parses them right, but the value initialized in
the data segment is wrong.
Diffstat (limited to 'subx/apps')
-rwxr-xr-xsubx/apps/assortbin33376 -> 34142 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bin23839 -> 24605 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bbin24398 -> 25164 bytes
-rwxr-xr-xsubx/apps/dquotesbin39729 -> 40495 bytes
-rwxr-xr-xsubx/apps/factorialbin22755 -> 23521 bytes
-rwxr-xr-xsubx/apps/handlebin23614 -> 24380 bytes
-rwxr-xr-xsubx/apps/hexbin26848 -> 27614 bytes
-rwxr-xr-xsubx/apps/packbin45742 -> 46508 bytes
-rwxr-xr-xsubx/apps/surveybin40474 -> 41172 bytes
-rw-r--r--subx/apps/survey.subx144
10 files changed, 81 insertions, 63 deletions
diff --git a/subx/apps/assort b/subx/apps/assort
index c903ec47..b8cfbe5c 100755
--- a/subx/apps/assort
+++ b/subx/apps/assort
Binary files differdiff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index e5e6560c..cf275a97 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 eebd667a..f26acdb6 100755
--- a/subx/apps/crenshaw2-1b
+++ b/subx/apps/crenshaw2-1b
Binary files differdiff --git a/subx/apps/dquotes b/subx/apps/dquotes
index 5e277311..68dac8fc 100755
--- a/subx/apps/dquotes
+++ b/subx/apps/dquotes
Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial
index 55a59123..7364a397 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle
index 3ea729c6..7861645c 100755
--- a/subx/apps/handle
+++ b/subx/apps/handle
Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex
index 315e855c..bc838186 100755
--- a/subx/apps/hex
+++ b/subx/apps/hex
Binary files differdiff --git a/subx/apps/pack b/subx/apps/pack
index 9c3ed916..705006e5 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/survey b/subx/apps/survey
index c413a9f4..ea50364a 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differdiff --git a/subx/apps/survey.subx b/subx/apps/survey.subx
index b7ce08dd..da01407b 100644
--- a/subx/apps/survey.subx
+++ b/subx/apps/survey.subx
@@ -79,22 +79,14 @@ Entry:
     eb/jump  $main:end/disp8
 $run-main:
     # - otherwise convert stdin
-    # var ed/EAX : exit-descriptor
-    81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # subtract from ESP
-    89/copy                         3/mod/direct    0/rm32/EAX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EAX
-    # configure ed to really exit()
-    # . ed->target = 0
-    c7          0/subop/copy        0/mod/direct    0/rm32/EAX    .           .             .           .           .               0/imm32           # copy to *EAX
-    # return convert(Stdin, 1/stdout, 2/stderr, ed)
-    # . . push args
-    50/push-EAX/ed
-    68/push  Stderr/imm32
+    # return convert(Stdin, Stdout)
+    # . . push args
     68/push  Stdout/imm32
     68/push  Stdin/imm32
     # . . call
     e8/call  convert/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # . syscall(exit, 0)
     bb/copy-to-EBX  0/imm32
 $main:end:
@@ -108,8 +100,10 @@ $main:end:
 #   labels: (address stream {string, label-info})         (16 bytes per row)
 # these are all inefficient; use sequential scans for lookups
 
-convert:  # in : (address buffered-file), out : (address buffered-file) -> <void>
+convert:  # infile : (address buffered-file), out : (address buffered-file) -> <void>
     # pseudocode
+    #   var in : (address stream byte) = stream(4096)
+    #   slurp(infile, in)
     #   var segments = new-stream(10 rows, 16 bytes each)
     #   var labels = new-stream(512 rows, 16 bytes each)
     #   compute-offsets(in, segments, labels)
@@ -123,6 +117,7 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     # . save registers
     51/push-ECX
     52/push-EDX
+    56/push-ESI
     # var segments/ECX = stream(10 * 16)
     81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xa0/imm32        # subtract from ESP
     68/push  0xa0/imm32/length
@@ -135,6 +130,62 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     68/push  0/imm32/read
     68/push  0/imm32/write
     89/copy                         3/mod/direct    2/rm32/EDX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EDX
+    # var in/ESI = stream(4096 * 1)
+    81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x1000/imm32      # subtract from ESP
+    68/push  0x1000/imm32/length
+    68/push  0/imm32/read
+    68/push  0/imm32/write
+    89/copy                         3/mod/direct    6/rm32/ESI    .           .             .           4/r32/ESP   .               .                 # copy ESP to ESI
+#?     # write(2/stderr, "slurp in\n") {{{
+#?     # . . push args
+#?     68/push  "compute-offsets\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
+#?     # }}}
+    # slurp(infile, in)
+    # . . push args
+    56/push-ESI
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
+    # . . call
+    e8/call  slurp/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+#?     # dump in {{{
+#?     # . write(2/stderr, "in: ")
+#?     # . . push args
+#?     68/push  "in: "/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, in)
+#?     # . . push args
+#?     56/push-ESI
+#?     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(in)
+#?     # . . push args
+#?     56/push-ESI
+#?     # . . call
+#?     e8/call  rewind-stream/disp32
+#?     # . . discard args
+#?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+#?     # }}}
 #?     # write(2/stderr, "compute-offsets\n") {{{
 #?     # . . push args
 #?     68/push  "compute-offsets\n"/imm32
@@ -148,7 +199,7 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     # . . push args
     52/push-EDX
     51/push-ECX
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
+    56/push-ESI
     # . . call
     e8/call  compute-offsets/disp32
     # . . discard args
@@ -172,7 +223,7 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x8/imm32         # add to ESP
     # rewind-stream(in)
     # . . push args
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
+    56/push-ESI
     # . . call
     e8/call  rewind-stream/disp32
     # . . discard args
@@ -263,7 +314,7 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     52/push-EDX
     51/push-ECX
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
+    56/push-ESI
     # . . call
     e8/call  emit-output/disp32
     # . . discard args
@@ -277,8 +328,9 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     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
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x30a0/imm32      # add to ESP
     # . restore registers
+    5e/pop-to-ESI
     5a/pop-to-EDX
     59/pop-to-ECX
     # . epilog
@@ -474,7 +526,7 @@ compute-offsets:segment-tmp:  # slice
 
 == code
 
-compute-offsets:  # in : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
+compute-offsets:  # in : (address stream), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
     # skeleton:
     #   for lines in 'in'
     #     for words in line
@@ -489,7 +541,7 @@ compute-offsets:  # in : (address buffered-file), segments : (address stream {st
     #   var line = new-stream(512, 1)
     #   while true                                  # line loop
     #     clear-stream(line)
-    #     read-line-buffered(in, line)
+    #     read-line(in, line)
     #     if (line->write == 0) break               # end of file
     #     while true                                # word loop
     #       word-slice = next-word(line)
@@ -562,10 +614,10 @@ $compute-offsets:line-loop:
     e8/call  clear-stream/disp32
     # . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # read-line-buffered(in, line/ECX)
+    # read-line(in, line/ECX)
     51/push-ECX
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
-    e8/call  read-line-buffered/disp32
+    e8/call  read-line/disp32
     # . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # if (line->write == 0) break
@@ -1093,31 +1145,6 @@ test-compute-offsets:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # . clear-stream(_test-input-buffered-file+4)
-    # . . push args
-    b8/copy-to-EAX  _test-input-buffered-file/imm32
-    05/add-to-EAX  4/imm32
-    50/push-EAX
-    # . . call
-    e8/call  clear-stream/disp32
-    # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # . clear-stream(_test-output-stream)
-    # . . push args
-    68/push  _test-output-stream/imm32
-    # . . call
-    e8/call  clear-stream/disp32
-    # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # . clear-stream(_test-output-buffered-file+4)
-    # . . push args
-    b8/copy-to-EAX  _test-output-buffered-file/imm32
-    05/add-to-EAX  4/imm32
-    50/push-EAX
-    # . . call
-    e8/call  clear-stream/disp32
-    # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
     # var segments/ECX = stream(2 * 16)
     81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x20/imm32        # subtract from ESP
     68/push  0x20/imm32/length
@@ -1179,11 +1206,11 @@ test-compute-offsets:
     e8/call  write/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
-    # compute-offsets(_test-input-buffered-file, segments, labels)
+    # compute-offsets(_test-input-stream, segments, labels)
     # . . push args
     52/push-EDX
     51/push-ECX
-    68/push  _test-input-buffered-file/imm32
+    68/push  _test-input-stream/imm32
     # . . call
     e8/call  compute-offsets/disp32
     # . . discard args
@@ -1671,7 +1698,7 @@ test-compute-addresses:
     5d/pop-to-EBP
     c3/return
 
-emit-output:  # in : (address buffered-file), out : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
+emit-output:  # in : (address stream), out : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
     # pseudocode:
     #   emit-headers(out, segments, labels)
     #   emit-segments(in, out, segments, labels)
@@ -1722,14 +1749,14 @@ $emit-output:end:
     5d/pop-to-EBP
     c3/return
 
-emit-segments:  # in : (address buffered-file), out : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
+emit-segments:  # in : (address stream), out : (address buffered-file), segments : (address stream {string, segment-info}), labels : (address stream {string, label-info})
     # pseudocode:
     #   var offset-of-next-instruction = 0
     #   var line = new-stream(512, 1)
     #   line-loop:
     #   while true
     #     clear-stream(line)
-    #     read-line-buffered(in, line)
+    #     read-line(in, line)
     #     if (line->write == 0) break               # end of file
     #     offset-of-next-instruction += num-bytes(line)
     #     while true
@@ -1804,12 +1831,12 @@ $emit-segments:line-loop:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # read-line-buffered(in, line)
+    # read-line(in, line)
     # . . push args
     51/push-ECX
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
     # . . call
-    e8/call  read-line-buffered/disp32
+    e8/call  read-line/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # dump line {{{
@@ -2259,15 +2286,6 @@ test-emit-segments:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
-    # . clear-stream(_test-input-buffered-file+4)
-    # . . push args
-    b8/copy-to-EAX  _test-input-buffered-file/imm32
-    05/add-to-EAX  4/imm32
-    50/push-EAX
-    # . . call
-    e8/call  clear-stream/disp32
-    # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
     # . clear-stream(_test-output-stream)
     # . . push args
     68/push  _test-output-stream/imm32
@@ -2394,12 +2412,12 @@ test-emit-segments:
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
     # component under test
-    # . emit-segments(_test-input-buffered-file, _test-output-buffered-file, segments, labels)
+    # . emit-segments(_test-input-stream, _test-output-buffered-file, segments, labels)
     # . . push args
     52/push-EDX
     51/push-ECX
     68/push  _test-output-buffered-file/imm32
-    68/push  _test-input-buffered-file/imm32
+    68/push  _test-input-stream/imm32
     # . . call
     e8/call  emit-segments/disp32
     # . . discard args