diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-02-10 16:54:20 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-02-10 16:54:20 -0800 |
commit | 38ef68b269fb18097e2d62ba6a8a1a5853d5d16d (patch) | |
tree | 38256e7a75cf0e546048d6fedc1272163ec6576e | |
parent | 6e181e7fd998a0d542cb531c929c905a243ea2f6 (diff) | |
download | mu-38ef68b269fb18097e2d62ba6a8a1a5853d5d16d.tar.gz |
4954
-rw-r--r-- | subx/060read.subx | 42 | ||||
-rw-r--r-- | subx/071read-line.subx | 36 | ||||
-rw-r--r-- | subx/072slice.subx | 102 | ||||
-rwxr-xr-x | subx/apps/crenshaw2-1 | bin | 17370 -> 17596 bytes | |||
-rwxr-xr-x | subx/apps/crenshaw2-1b | bin | 17929 -> 18155 bytes | |||
-rwxr-xr-x | subx/apps/factorial | bin | 16288 -> 16514 bytes | |||
-rwxr-xr-x | subx/apps/handle | bin | 17081 -> 17307 bytes | |||
-rwxr-xr-x | subx/apps/hex | bin | 20349 -> 20575 bytes | |||
-rwxr-xr-x | subx/apps/pack | bin | 19264 -> 19490 bytes |
9 files changed, 141 insertions, 39 deletions
diff --git a/subx/060read.subx b/subx/060read.subx index c56b8788..a54b3f02 100644 --- a/subx/060read.subx +++ b/subx/060read.subx @@ -188,9 +188,9 @@ test-read-single: 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-stream-buffer) + # clear-stream(_test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args @@ -203,9 +203,9 @@ test-read-single: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read(_test-stream, _test-stream-buffer) + # read(_test-stream, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-stream/imm32 # . . call e8/call read/disp32 @@ -220,11 +220,11 @@ test-read-single: e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP - # check-stream-equal(_test-stream-buffer, "Ab", msg) + # check-stream-equal(_test-tmp-stream, "Ab", msg) # . . push args 68/push "F - test-read-single"/imm32 68/push "Ab"/imm32 - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call check-stream-equal/disp32 # . . discard args @@ -241,9 +241,9 @@ test-read-is-stateful: 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-stream-buffer) + # clear-stream(_test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args @@ -256,9 +256,9 @@ test-read-is-stateful: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read(_test-stream, _test-stream-buffer) + # read(_test-stream, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-stream/imm32 # . . call e8/call read/disp32 @@ -272,19 +272,19 @@ test-read-is-stateful: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read(_test-stream, _test-stream-buffer) + # read(_test-stream, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-stream/imm32 # . . call e8/call read/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-stream-equal(_test-stream-buffer, "CD", msg) + # check-stream-equal(_test-tmp-stream, "CD", msg) # . . push args 68/push "F - test-read-is-stateful"/imm32 68/push "CD"/imm32 - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call check-stream-equal/disp32 # . . discard args @@ -302,9 +302,9 @@ test-read-returns-0-on-end-of-file: 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-stream-buffer) + # . clear-stream(_test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args @@ -318,18 +318,18 @@ test-read-returns-0-on-end-of-file: # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # first read gets to end-of-file - # . read(_test-stream, _test-stream-buffer) + # . read(_test-stream, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-stream/imm32 # . . call e8/call read/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # second read - # . read(_test-stream, _test-stream-buffer) + # . read(_test-stream, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-stream/imm32 # . . call e8/call read/disp32 @@ -349,7 +349,7 @@ test-read-returns-0-on-end-of-file: == data -_test-stream-buffer: +_test-tmp-stream: # current write index 00 00 00 00 # current read index diff --git a/subx/071read-line.subx b/subx/071read-line.subx index 5eba31c1..3efa96e0 100644 --- a/subx/071read-line.subx +++ b/subx/071read-line.subx @@ -134,9 +134,9 @@ test-read-line: 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-stream-buffer) + # . clear-stream(_test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args @@ -166,10 +166,10 @@ test-read-line: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read a line from _test-stream (buffered by _test-buffered-file) into _test-stream-buffer - # . EAX = read-line(_test-buffered-file, _test-stream-buffer) + # read a line from _test-stream (buffered by _test-buffered-file) into _test-tmp-stream + # . EAX = read-line(_test-buffered-file, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-buffered-file/imm32 # . . call e8/call read-line/disp32 @@ -184,11 +184,11 @@ test-read-line: e8/call check-ints-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-stream-buffer, "ab", msg) + # check-next-stream-line-equal(_test-tmp-stream, "ab", msg) # . . push args 68/push "F - test-read-line"/imm32 68/push "ab"/imm32 - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call check-next-stream-line-equal/disp32 # . . discard args @@ -214,17 +214,17 @@ test-read-line-returns-true-on-eof: 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-stream-buffer) + # . clear-stream(_test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-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 # write nothing - # EAX = read-line(_test-buffered-file, _test-stream-buffer) + # EAX = read-line(_test-buffered-file, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-buffered-file/imm32 # . . call e8/call read-line/disp32 @@ -260,9 +260,9 @@ test-read-line-reads-final-line-until-eof: 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-stream-buffer) + # . clear-stream(_test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args @@ -275,10 +275,10 @@ test-read-line-reads-final-line-until-eof: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read a line from _test-stream (buffered by _test-buffered-file) into _test-stream-buffer - # . EAX = read-line(_test-buffered-file, _test-stream-buffer) + # read a line from _test-stream (buffered by _test-buffered-file) into _test-tmp-stream + # . EAX = read-line(_test-buffered-file, _test-tmp-stream) # . . push args - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 68/push _test-buffered-file/imm32 # . . call e8/call read-line/disp32 @@ -293,11 +293,11 @@ test-read-line-reads-final-line-until-eof: e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP - # check-stream-equal(_test-stream-buffer, "cd", msg) + # check-stream-equal(_test-tmp-stream, "cd", msg) # . . push args 68/push "F - test-read-line-reads-final-line-until-eof"/imm32 68/push "cd"/imm32 - 68/push _test-stream-buffer/imm32 + 68/push _test-tmp-stream/imm32 # . . call e8/call check-stream-equal/disp32 # . . discard args diff --git a/subx/072slice.subx b/subx/072slice.subx index 36bdfdd4..3b948d60 100644 --- a/subx/072slice.subx +++ b/subx/072slice.subx @@ -503,6 +503,108 @@ test-write-slice: 5d/pop-to-EBP c3/return +# write an entire stream's contents to a buffered-file +# ways to do this: +# - construct a 'maximal slice' and pass it to write-slice +# - flush the buffered-file and pass the stream directly to its fd (disabling buffering) +# we'll go with the first way for now +write-stream-buffered: # f : (address buffered-file), s : (address stream) + # . 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 + # ESI = s + 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 0xc/disp8 . # copy *(EBP+12) to ESI + # var slice/ECX = {s->data, s->data + s->write} + # . push s->data + s->write + 8b/copy 0/mod/indirect 6/rm32/ESI . . . 0/r32/EAX . . # copy *ESI to EAX + 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX . 0/r32/EAX 0xc/disp8 . # copy ESI+EAX+12 to EAX + 50/push-EAX + # . push s->data + 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 0xc/disp8 . # copy ESI+12 to EAX + 50/push-EAX + # . ECX = ESP + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # write-slice(f, slice) + # . . push args + 51/push-ECX + ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) + # . . call + e8/call write-slice/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +$write-stream-buffered:end: + # . restore registers + 5e/pop-to-ESI + 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-write-stream-buffered: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # setup + # . clear-stream(_test-stream) + # . . push args + 68/push _test-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-buffered-file+4) + # . . push args + b8/copy-to-EAX _test-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 + # initialize input + # . write(_test-tmp-stream, "abcd") + # . . push args + 68/push "abcd"/imm32 + 68/push _test-tmp-stream/imm32 + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # perform the write-stream-buffered + # . write-stream-buffered(_test-buffered-file, _test-tmp-stream) + # . . push args + 68/push _test-tmp-stream/imm32 + 68/push _test-buffered-file/imm32 + # . . call + e8/call write-stream-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # check that the write happened as expected + # . flush(_test-buffered-file) + # . . push args + 68/push _test-buffered-file/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . check-stream-equal(_test-stream, "abcd", msg) + # . . push args + 68/push "F - test-write-stream-buffered"/imm32 + 68/push "abcd"/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call check-stream-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/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 _test-slice-data-0: diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1 index 98976436..ab780991 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 8bc663fb..9deb1c43 100755 --- a/subx/apps/crenshaw2-1b +++ b/subx/apps/crenshaw2-1b Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial index 82c8f2d1..63abe708 100755 --- a/subx/apps/factorial +++ b/subx/apps/factorial Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle index bb57c457..d5deb64e 100755 --- a/subx/apps/handle +++ b/subx/apps/handle Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex index a75b3832..e90d80ed 100755 --- a/subx/apps/hex +++ b/subx/apps/hex Binary files differdiff --git a/subx/apps/pack b/subx/apps/pack index 6437b888..01e55e6c 100755 --- a/subx/apps/pack +++ b/subx/apps/pack Binary files differ |