diff options
Diffstat (limited to 'subx')
-rw-r--r-- | subx/061read-byte.subx | 62 | ||||
-rw-r--r-- | subx/064write-byte.subx | 30 | ||||
-rw-r--r-- | subx/066print-byte.subx | 22 | ||||
-rw-r--r-- | subx/068error-byte.subx | 4 | ||||
-rw-r--r-- | subx/071read-line.subx | 40 | ||||
-rw-r--r-- | subx/072slice.subx | 24 | ||||
-rw-r--r-- | subx/Readme.md | 10 | ||||
-rwxr-xr-x | subx/apps/assort | bin | 21302 -> 21401 bytes | |||
-rw-r--r-- | subx/apps/assort.subx | 14 | ||||
-rwxr-xr-x | subx/apps/crenshaw2-1 | bin | 18490 -> 18589 bytes | |||
-rw-r--r-- | subx/apps/crenshaw2-1.subx | 4 | ||||
-rwxr-xr-x | subx/apps/crenshaw2-1b | bin | 19049 -> 19148 bytes | |||
-rw-r--r-- | subx/apps/crenshaw2-1b.subx | 7 | ||||
-rw-r--r-- | subx/apps/dquotes | bin | 21933 -> 22553 bytes | |||
-rw-r--r-- | subx/apps/dquotes.subx | 12 | ||||
-rwxr-xr-x | subx/apps/factorial | bin | 17406 -> 17505 bytes | |||
-rwxr-xr-x | subx/apps/handle | bin | 18180 -> 18279 bytes | |||
-rwxr-xr-x | subx/apps/hex | bin | 21499 -> 21598 bytes | |||
-rw-r--r-- | subx/apps/hex.subx | 18 | ||||
-rwxr-xr-x | subx/apps/pack | bin | 36091 -> 36190 bytes | |||
-rw-r--r-- | subx/apps/pack.subx | 72 | ||||
-rw-r--r-- | subx/apps/subx-common.subx | 6 |
22 files changed, 164 insertions, 161 deletions
diff --git a/subx/061read-byte.subx b/subx/061read-byte.subx index 7503818f..81080393 100644 --- a/subx/061read-byte.subx +++ b/subx/061read-byte.subx @@ -1,4 +1,4 @@ -# read-byte: one higher-level abstraction atop 'read'. +# read-byte-buffered: one higher-level abstraction atop 'read'. # # There are many situations where 'read' is a lot to manage, and we need # to abstract some details away. One of them is when we want to read a file @@ -32,8 +32,8 @@ Stdin: # . 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 #? Entry: # run a single test, while debugging -#? e8/call test-read-byte-multiple/disp32 -#? e8/call test-read-byte-refills-buffer/disp32 +#? e8/call test-read-byte-buffered-multiple/disp32 +#? e8/call test-read-byte-buffered-refills-buffer/disp32 #? # 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 #? b8/copy-to-EAX 1/imm32/exit @@ -41,7 +41,7 @@ Stdin: # return next byte value in EAX, with top 3 bytes cleared. # On reaching end of file, return 0xffffffff (Eof). -read-byte: # f : (address buffered-file) -> byte-or-Eof/EAX +read-byte-buffered: # f : (address buffered-file) -> byte-or-Eof/EAX # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -54,7 +54,7 @@ read-byte: # f : (address buffered-file) -> byte-or-Eof/EAX 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 . # copy *(ESI+8) to ECX # if (f->read >= f->write) populate stream from file 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 . # compare ECX with *(ESI+4) - 7c/jump-if-lesser $read-byte:from-stream/disp8 + 7c/jump-if-lesser $read-byte-buffered:from-stream/disp8 # . clear-stream(stream = f+4) # . . push args 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 . # copy ESI+4 to EAX @@ -75,17 +75,17 @@ read-byte: # f : (address buffered-file) -> byte-or-Eof/EAX 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # if (EAX == 0) return 0xffffffff 3d/compare-EAX-and 0/imm32 - 75/jump-if-not-equal $read-byte:from-stream/disp8 + 75/jump-if-not-equal $read-byte-buffered:from-stream/disp8 b8/copy-to-EAX 0xffffffff/imm32/Eof - eb/jump $read-byte:end/disp8 -$read-byte:from-stream: + eb/jump $read-byte-buffered:end/disp8 +$read-byte-buffered:from-stream: # read byte from stream # AL = f->data[f->read] 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0x10/disp8 . # copy byte at *(ESI+ECX+16) to AL # ++f->read ff 0/subop/increment 1/mod/*+disp8 6/rm32/ESI . . . . 8/disp8 . # increment *(ESI+8) -$read-byte:end: +$read-byte-buffered:end: # . restore registers 5e/pop-to-ESI 59/pop-to-ECX @@ -96,8 +96,8 @@ $read-byte:end: # - tests -test-read-byte-single: - # - check that read-byte returns first byte of 'file' +test-read-byte-buffered-single: + # - check that read-byte-buffered returns first byte of 'file' # setup # . clear-stream(_test-stream) # . . push args @@ -123,16 +123,16 @@ test-read-byte-single: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 'A', msg) # . . push args - 68/push "F - test-read-byte-single"/imm32 + 68/push "F - test-read-byte-buffered-single"/imm32 68/push 0x41/imm32 50/push-EAX # . . call @@ -142,8 +142,8 @@ test-read-byte-single: # . end c3/return -test-read-byte-multiple: - # - call read-byte twice, check that second call returns second byte +test-read-byte-buffered-multiple: + # - call read-byte-buffered twice, check that second call returns second byte # setup # . clear-stream(_test-stream) # . . push args @@ -169,23 +169,23 @@ test-read-byte-multiple: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 'b', msg) # . . push args - 68/push "F - test-read-byte-multiple"/imm32 + 68/push "F - test-read-byte-buffered-multiple"/imm32 68/push 0x62/imm32 50/push-EAX # . . call @@ -195,8 +195,8 @@ test-read-byte-multiple: # . end c3/return -test-read-byte-end-of-file: - # - call read-byte on an empty 'file', check that it returns Eof +test-read-byte-buffered-end-of-file: + # - call read-byte-buffered on an empty 'file', check that it returns Eof # setup # . clear-stream(_test-stream) # . . push args @@ -214,16 +214,16 @@ test-read-byte-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 - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 0xffffffff, msg) # . . push args - 68/push "F - test-read-byte-end-of-file"/imm32 + 68/push "F - test-read-byte-buffered-end-of-file"/imm32 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call @@ -233,8 +233,8 @@ test-read-byte-end-of-file: # . end c3/return -test-read-byte-refills-buffer: - # - consume buffered-file's buffer, check that next read-byte still works +test-read-byte-buffered-refills-buffer: + # - consume buffered-file's buffer, check that next read-byte-buffered still works # setup # . clear-stream(_test-stream) # . . push args @@ -264,16 +264,16 @@ test-read-byte-refills-buffer: # . _test-buffered-file->read = 6 # >= _test-buffered-file->length b8/copy-to-EAX _test-buffered-file/imm32 c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 6/imm32 # copy to *(EAX+8) - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 'A', msg) # . . push args - 68/push "F - test-read-byte-refills-buffer"/imm32 + 68/push "F - test-read-byte-buffered-refills-buffer"/imm32 68/push 0x41/imm32 50/push-EAX # . . call diff --git a/subx/064write-byte.subx b/subx/064write-byte.subx index 9f97c336..a432171d 100644 --- a/subx/064write-byte.subx +++ b/subx/064write-byte.subx @@ -1,4 +1,4 @@ -# write-byte: write a single byte to a buffered-file. The write may be buffered. +# write-byte-buffered: add a single byte to a buffered-file. # flush: write out any buffered writes to disk. # # TODO: Come up with a way to signal failure to write to disk. This is hard @@ -28,7 +28,7 @@ Stdout: # . 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 # Write lower byte of 'n' to 'f'. -write-byte: # f : (address buffered-file), n : int -> <void> +write-byte-buffered: # f : (address buffered-file), n : int -> <void> # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -41,7 +41,7 @@ write-byte: # f : (address buffered-file), n : int -> <void> 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 4/disp8 . # copy *(EDI+4) to ECX # if (f->write >= f->length) flush and clear f's stream 3b/compare 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 0xc/disp8 . # compare ECX with *(EDI+12) - 7c/jump-if-lesser $write-byte:to-stream/disp8 + 7c/jump-if-lesser $write-byte-buffered:to-stream/disp8 # . flush(f) # . . push args 57/push-EDI @@ -59,7 +59,7 @@ write-byte: # f : (address buffered-file), n : int -> <void> 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . f->write must now be 0; update its cache at ECX 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . . # clear ECX -$write-byte:to-stream: +$write-byte-buffered:to-stream: # write to stream # f->data[f->write] = LSB(n) 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX @@ -67,7 +67,7 @@ $write-byte:to-stream: 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX . 0/r32/AL 0x10/disp8 . # copy AL to *(EDI+ECX+16) # ++f->write ff 0/subop/increment 1/mod/*+disp8 7/rm32/EDI . . . . 4/disp8 . # increment *(EDI+4) -$write-byte:end: +$write-byte-buffered:end: # . restore registers 5f/pop-to-EDI 59/pop-to-ECX @@ -105,8 +105,8 @@ $flush:end: # - tests -test-write-byte-single: - # - check that write-byte writes to first byte of 'file' +test-write-byte-buffered-single: + # - check that write-byte-buffered writes to first byte of 'file' # setup # . clear-stream(_test-stream) # . . push args @@ -124,12 +124,12 @@ test-write-byte-single: e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # write-byte(_test-buffered-file, 'A') + # write-byte-buffered(_test-buffered-file, 'A') # . . push args 68/push 0x41/imm32 68/push _test-buffered-file/imm32 # . . call - e8/call write-byte/disp32 + e8/call write-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # flush(_test-buffered-file) @@ -141,7 +141,7 @@ test-write-byte-single: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-stream-equal(_test-stream, "A", msg) # . . push args - 68/push "F - test-write-byte-single"/imm32 + 68/push "F - test-write-byte-buffered-single"/imm32 68/push "A"/imm32 68/push _test-stream/imm32 # . . call @@ -151,8 +151,8 @@ test-write-byte-single: # . end c3/return -test-write-byte-multiple-flushes: - # - check that write-byte correctly flushes buffered data +test-write-byte-buffered-multiple-flushes: + # - check that write-byte-buffered correctly flushes buffered data # setup # . clear-stream(_test-stream) # . . push args @@ -181,12 +181,12 @@ test-write-byte-multiple-flushes: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # write-byte(_test-buffered-file, 'g') + # write-byte-buffered(_test-buffered-file, 'g') # . . push args 68/push 0x67/imm32 68/push _test-buffered-file/imm32 # . . call - e8/call write-byte/disp32 + e8/call write-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # flush(_test-buffered-file) @@ -198,7 +198,7 @@ test-write-byte-multiple-flushes: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-stream-equal(_test-stream, "abcdef", msg) # . . push args - 68/push "F - test-write-byte-multiple-flushes: 1"/imm32 + 68/push "F - test-write-byte-buffered-multiple-flushes: 1"/imm32 68/push "abcdefg"/imm32 68/push _test-stream/imm32 # . . call diff --git a/subx/066print-byte.subx b/subx/066print-byte.subx index 39d7793e..b8b1dd24 100644 --- a/subx/066print-byte.subx +++ b/subx/066print-byte.subx @@ -5,7 +5,7 @@ # . op subop mod rm32 base index scale r32 # . 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 -print-byte: # f : (address buffered-file), n : int -> <void> +print-byte-buffered: # f : (address buffered-file), n : int -> <void> # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -17,12 +17,12 @@ print-byte: # f : (address buffered-file), n : int -> <void> 25/and-EAX 0xf/imm32 # . AL = to-hex-char(AL) e8/call to-hex-char/disp32 - # write-byte(f, AL) + # write-byte-buffered(f, AL) # . . push args 50/push-EAX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call write-byte/disp32 + e8/call write-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # AL = convert lower nibble to hex @@ -30,15 +30,15 @@ print-byte: # f : (address buffered-file), n : int -> <void> 25/and-EAX 0xf/imm32 # . AL = to-hex-char(AL) e8/call to-hex-char/disp32 - # write-byte(f, AL) + # write-byte-buffered(f, AL) # . . push args 50/push-EAX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call write-byte/disp32 + e8/call write-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -$print-byte:end: +$print-byte-buffered:end: # . restore registers 58/pop-to-EAX # . epilog @@ -46,8 +46,8 @@ $print-byte:end: 5d/pop-to-EBP c3/return -test-print-byte: - # - check that print-byte prints the hex textual representation +test-print-byte-buffered: + # - check that print-byte-buffered prints the hex textual representation # setup # . clear-stream(_test-stream) # . . push args @@ -65,12 +65,12 @@ test-print-byte: e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # print-byte(_test-buffered-file, 0xa) # exercises digit, non-digit as well as leading zero + # print-byte-buffered(_test-buffered-file, 0xa) # exercises digit, non-digit as well as leading zero # . . push args 68/push 0xa/imm32 68/push _test-buffered-file/imm32 # . . call - e8/call print-byte/disp32 + e8/call print-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # flush(_test-buffered-file) @@ -82,7 +82,7 @@ test-print-byte: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-stream-equal(_test-stream, "0a", msg) # . . push args - 68/push "F - test-print-byte"/imm32 + 68/push "F - test-print-byte-buffered"/imm32 68/push "0a"/imm32 68/push _test-stream/imm32 # . . call diff --git a/subx/068error-byte.subx b/subx/068error-byte.subx index 252aff20..dcffd026 100644 --- a/subx/068error-byte.subx +++ b/subx/068error-byte.subx @@ -52,12 +52,12 @@ error-byte: # ed : (address exit-descriptor), out : (address buffered-file), ms e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # print-byte(out, byte) + # print-byte-buffered(out, byte) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0x14/disp8 . # push *(EBP+20) ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call print-byte/disp32 + e8/call print-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # write-buffered(out, Newline) diff --git a/subx/071read-line.subx b/subx/071read-line.subx index 39c5f576..f33fd035 100644 --- a/subx/071read-line.subx +++ b/subx/071read-line.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 #? Entry: # run a single test, while debugging -#? e8/call test-read-line/disp32 +#? e8/call test-read-line-buffered/disp32 #? # 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 #? b8/copy-to-EAX 1/imm32/exit @@ -13,7 +13,7 @@ # read bytes from 'f' until (and including) a newline and store them into 's' # 's' fails to grow if and only if no data found # just abort if 's' is too small -read-line: # f : (address buffered-file), s : (address stream byte) -> <void> +read-line-buffered: # f : (address buffered-file), s : (address stream byte) -> <void> # pseudocode: # while true # if (s->write >= s->length) abort @@ -41,13 +41,13 @@ read-line: # f : (address buffered-file), s : (address stream byte) -> <void> 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0xc/disp8 . # copy *(EBP+12) to EDI # EDX = s->write 8b/copy 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . . # copy *EDI to EDX -$read-line:loop: +$read-line-buffered:loop: # if (s->write >= s->length) abort 3b/compare 1/mod/*+disp8 7/rm32/EDI . . . 2/r32/EDX 8/disp8 . # compare EDX with *(EDI+8) - 7d/jump-if-greater-or-equal $read-line:abort/disp8 + 7d/jump-if-greater-or-equal $read-line-buffered:abort/disp8 # if (f->read >= f->write) populate stream from file 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 . # compare ECX with *(ESI+4) - 7c/jump-if-lesser $read-line:from-stream/disp8 + 7c/jump-if-lesser $read-line-buffered:from-stream/disp8 # . clear-stream(stream = f+4) # . . push args 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 . # copy ESI+4 to EAX @@ -70,8 +70,8 @@ $read-line:loop: # since f->read was initially 0, EAX is the same as f->write # . if (EAX == 0) return true 3d/compare-EAX-and 0/imm32 - 74/jump-if-equal $read-line:end/disp8 -$read-line:from-stream: + 74/jump-if-equal $read-line-buffered:end/disp8 +$read-line-buffered:from-stream: # AL = f->data[f->read] 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0x10/disp8 . # copy byte at *(ESI+ECX+16) to AL @@ -83,8 +83,8 @@ $read-line:from-stream: 42/increment-EDX # if (AL == '\n') return 3d/compare-EAX-and 0xa/imm32 - 75/jump-if-not-equal $read-line:loop/disp8 -$read-line:end: + 75/jump-if-not-equal $read-line-buffered:loop/disp8 +$read-line-buffered:end: # save f->read 89/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 . # copy ECX to *(ESI+8) # save s->write @@ -100,10 +100,10 @@ $read-line:end: 5d/pop-to-EBP c3/return -$read-line:abort: +$read-line-buffered:abort: # . _write(2/stderr, error) # . . push args - 68/push "read-line: line too long\n"/imm32 + 68/push "read-line-buffered: line too long\n"/imm32 68/push 2/imm32/stderr # . . call e8/call _write/disp32 @@ -115,8 +115,8 @@ $read-line:abort: cd/syscall 0x80/imm8 # never gets here -test-read-line: - # - check that read-line stops at a newline +test-read-line-buffered: + # - check that read-line-buffered stops at a newline # setup # . clear-stream(_test-stream) # . . push args @@ -150,17 +150,17 @@ test-read-line: # . . 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-tmp-stream - # . EAX = read-line(_test-buffered-file, _test-tmp-stream) + # . EAX = read-line-buffered(_test-buffered-file, _test-tmp-stream) # . . push args 68/push _test-tmp-stream/imm32 68/push _test-buffered-file/imm32 # . . call - e8/call read-line/disp32 + e8/call read-line-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # check-next-stream-line-equal(_test-tmp-stream, "ab", msg) # . . push args - 68/push "F - test-read-line"/imm32 + 68/push "F - test-read-line-buffered"/imm32 68/push "ab"/imm32 68/push _test-tmp-stream/imm32 # . . call @@ -170,7 +170,7 @@ test-read-line: # end c3/return -test-read-line-reads-final-line-until-Eof: +test-read-line-buffered-reads-final-line-until-Eof: # setup # . clear-stream(_test-stream) # . . push args @@ -204,17 +204,17 @@ test-read-line-reads-final-line-until-Eof: # . . 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-tmp-stream - # . EAX = read-line(_test-buffered-file, _test-tmp-stream) + # . EAX = read-line-buffered(_test-buffered-file, _test-tmp-stream) # . . push args 68/push _test-tmp-stream/imm32 68/push _test-buffered-file/imm32 # . . call - e8/call read-line/disp32 + e8/call read-line-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # check-stream-equal(_test-tmp-stream, "cd", msg) # . . push args - 68/push "F - test-read-line-reads-final-line-until-Eof"/imm32 + 68/push "F - test-read-line-buffered-reads-final-line-until-Eof"/imm32 68/push "cd"/imm32 68/push _test-tmp-stream/imm32 # . . call diff --git a/subx/072slice.subx b/subx/072slice.subx index 9c285097..9892f2a1 100644 --- a/subx/072slice.subx +++ b/subx/072slice.subx @@ -704,7 +704,7 @@ test-slice-starts-with-fails-2: 5d/pop-to-EBP c3/return -write-slice: # out : (address buffered-file), s : (address slice) +write-slice-buffered: # out : (address buffered-file), s : (address slice) # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -727,13 +727,13 @@ write-slice: # out : (address buffered-file), s : (address slice) 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 2/r32/EDX 0xc/disp8 . # copy *(EDI+12) to EDX # EBX = out->write 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 4/disp8 . # copy *(EDI+4) to EBX -$write-slice:loop: +$write-slice-buffered:loop: # if (curr >= max) break 39/compare 3/mod/direct 1/rm32/ECX . . . 6/r32/ESI . . # compare ECX with ESI - 7d/jump-if-greater-or-equal $write-slice:loop-end/disp8 + 7d/jump-if-greater-or-equal $write-slice-buffered:loop-end/disp8 # if (out->write >= out->length) flush and clear out's stream 39/compare 3/mod/direct 3/rm32/EBX . . . 2/r32/EDX . . # compare EBX with EDX - 7c/jump-if-lesser $write-slice:to-stream/disp8 + 7c/jump-if-lesser $write-slice-buffered:to-stream/disp8 # . persist out->write 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 4/disp8 . # copy EBX to *(EDI+4) # . flush(out) @@ -753,7 +753,7 @@ $write-slice:loop: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . out->write must now be 0; update its cache at EBX 31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . . # clear EBX -$write-slice:to-stream: +$write-slice-buffered:to-stream: # out->data[out->write] = *in # . AL = *in 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX @@ -764,11 +764,11 @@ $write-slice:to-stream: 43/increment-EBX # ++in 41/increment-ECX - eb/jump $write-slice:loop/disp8 -$write-slice:loop-end: + eb/jump $write-slice-buffered:loop/disp8 +$write-slice-buffered:loop-end: # persist necessary variables from registers 89/copy 1/mod/*+disp8 7/rm32/EDI . . . 3/r32/EBX 4/disp8 . # copy EBX to *(EDI+4) -$write-slice:end: +$write-slice-buffered:end: # . restore registers 5f/pop-to-EDI 5e/pop-to-ESI @@ -781,7 +781,7 @@ $write-slice:end: 5d/pop-to-EBP c3/return -test-write-slice: +test-write-slice-buffered: # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -806,12 +806,12 @@ test-write-slice: 68/push _test-slice-data-3/imm32/end 68/push _test-slice-data-0/imm32/start 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX - # write-slice(_test-buffered-file, slice) + # write-slice-buffered(_test-buffered-file, slice) # . . push args 51/push-ECX 68/push _test-buffered-file/imm32 # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # flush(_test-buffered-file) @@ -823,7 +823,7 @@ test-write-slice: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-stream-equal(_test-stream, "Abc", msg) # . . push args - 68/push "F - test-write-slice"/imm32 + 68/push "F - test-write-slice-buffered"/imm32 68/push "Abc"/imm32 68/push _test-stream/imm32 # . . call diff --git a/subx/Readme.md b/subx/Readme.md index e8e4ad6d..a27bf0f4 100644 --- a/subx/Readme.md +++ b/subx/Readme.md @@ -627,16 +627,18 @@ allocated memory for it.)_ - Can also be used to cat one stream into another. - Will abort the entire program if there isn't enough room. * `write-buffered`: string -> buffered-file -* `write-slice`: slice -> buffered-file +* `write-slice-buffered`: slice -> buffered-file * `flush`: buffered-file -* `print-byte`: buffered-file, int +* `write-byte-buffered`: int -> buffered-file +* `print-byte-buffered`: int -> buffered-file + - textual representation in hex #### reading from disk * `read`: file -> stream - Can also be used to cat one stream into another. - Will silently stop reading when destination runs out of space. -* `read-byte`: buffered-file -> byte -* `read-line`: buffered-file -> stream +* `read-byte-buffered`: buffered-file -> byte +* `read-line-buffered`: buffered-file -> stream - Will abort the entire program if there isn't enough room. #### non-IO operations on streams diff --git a/subx/apps/assort b/subx/apps/assort index 007ddaa7..ba20910f 100755 --- a/subx/apps/assort +++ b/subx/apps/assort Binary files differdiff --git a/subx/apps/assort.subx b/subx/apps/assort.subx index ecb1c213..20566806 100644 --- a/subx/apps/assort.subx +++ b/subx/apps/assort.subx @@ -428,7 +428,7 @@ read-segments: # in : (address buffered-file), table : (address stream row) # var line = new-stream(512, 1) # while true # clear-stream(line) - # read-line(in, line) + # read-line-buffered(in, line) # if (line->write == 0) break # end of file # var word-slice = next-word(line) # if slice-empty?(word-slice) # whitespace @@ -479,12 +479,12 @@ $read-segments: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(in, line) + # read-line-buffered(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/disp32 + e8/call read-line-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP $read-segments:check0: @@ -566,12 +566,12 @@ $read-segments:check-for-segment-header: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 52/push-EDX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -630,12 +630,12 @@ $read-segments:check-for-segment-header: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 52/push-EDX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1 index 51765a39..b5614efb 100755 --- a/subx/apps/crenshaw2-1 +++ b/subx/apps/crenshaw2-1 Binary files differdiff --git a/subx/apps/crenshaw2-1.subx b/subx/apps/crenshaw2-1.subx index 20560288..2f1fec9e 100644 --- a/subx/apps/crenshaw2-1.subx +++ b/subx/apps/crenshaw2-1.subx @@ -512,11 +512,11 @@ get-char: # f : (address buffered-file) -> <void> 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers 50/push-EAX - # read-byte(f) + # EAX = read-byte-buffered(f) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # save EAX to Look diff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b index 6f8a2228..0a7e2e13 100755 --- a/subx/apps/crenshaw2-1b +++ b/subx/apps/crenshaw2-1b Binary files differdiff --git a/subx/apps/crenshaw2-1b.subx b/subx/apps/crenshaw2-1b.subx index 2c396fb3..8dee0dbc 100644 --- a/subx/apps/crenshaw2-1b.subx +++ b/subx/apps/crenshaw2-1b.subx @@ -195,7 +195,8 @@ get-num: # in : (address buffered-file), out : (address stream), err : fd or (a # Look = get-char(in) # while is-digit?(Look) # This is complicated because I don't want to hard-code the error strategy in - # a general helper like write-byte. Maybe I should just create a local helper. + # a general helper like write-byte-buffered. Maybe I should just create a + # local helper. # # within the loop we'll try to keep things in registers: # in: ESI @@ -711,11 +712,11 @@ get-char: # f : (address buffered-file) -> <void> 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers 50/push-EAX - # read-byte(f) + # EAX = read-byte-buffered(f) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # save EAX to Look diff --git a/subx/apps/dquotes b/subx/apps/dquotes index 6537abcb..83fac224 100644 --- a/subx/apps/dquotes +++ b/subx/apps/dquotes Binary files differdiff --git a/subx/apps/dquotes.subx b/subx/apps/dquotes.subx index 67a215fa..749fc6aa 100644 --- a/subx/apps/dquotes.subx +++ b/subx/apps/dquotes.subx @@ -82,7 +82,7 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void # write-stream(new-data-segment, "== data\n") # while true # clear-stream(line) - # read-line(in, line) + # read-line-buffered(in, line) # if (line->write == 0) break # end of file # while true # var word-slice = next-word(line) @@ -93,7 +93,7 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void # if slice-starts-with?(word-slice, '"') # string literal <== what we're here for # process-string-literal(word-slice, out, new-data-segment) # else - # write-slice(out, word-slice) + # write-slice-buffered(out, word-slice) # write-stream-data(out, new-data-segment) # flush(out) # @@ -145,12 +145,12 @@ $convert: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(in, line) + # read-line-buffered(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/disp32 + e8/call read-line-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP $convert:check0: @@ -204,12 +204,12 @@ $convert:string-literal: # continue eb/jump $convert:next-word/disp8 $convert:regular-word: - # write-slice(out, word-slice) + # write-slice-buffered(out, word-slice) # . . push args 52/push-EDX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # fall through diff --git a/subx/apps/factorial b/subx/apps/factorial index 74d03c89..dbda72ae 100755 --- a/subx/apps/factorial +++ b/subx/apps/factorial Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle index 17ae017d..650cdd55 100755 --- a/subx/apps/handle +++ b/subx/apps/handle Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex index 1d455fbd..99ac5466 100755 --- a/subx/apps/hex +++ b/subx/apps/hex Binary files differdiff --git a/subx/apps/hex.subx b/subx/apps/hex.subx index c0627c77..3730351f 100644 --- a/subx/apps/hex.subx +++ b/subx/apps/hex.subx @@ -75,7 +75,7 @@ convert: # in : (address buffered-file), out : (address buffered-file), err : ( # while true # EAX = convert-next-octet(in, err, ed) # if (EAX == Eof) break - # write-byte(out, AL) + # write-byte-buffered(out, AL) # flush(out) # # . prolog @@ -96,12 +96,12 @@ $convert:loop: # if (EAX == Eof) break 3d/compare-EAX-and 0xffffffff/imm32/Eof 74/jump-if-equal $convert:loop-end/disp8 - # write-byte(out, AL) + # write-byte-buffered(out, AL) # . . push args 50/push-EAX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call write-byte/disp32 + e8/call write-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # loop @@ -489,7 +489,7 @@ $test-convert-next-octet-aborts-on-single-hex-byte:end: scan-next-byte: # in : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> byte-or-Eof/EAX # pseudocode: # while true - # EAX = read-byte(in) + # EAX = read-byte-buffered(in) # if (EAX == Eof) return EAX # if (is-hex-digit?(EAX)) return EAX # if (EAX == ' ' or '\t' or '\n') continue @@ -501,11 +501,11 @@ scan-next-byte: # in : (address buffered-file), err : (address buffered-file), 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers $scan-next-byte:loop: - # EAX = read-byte(in) + # EAX = read-byte-buffered(in) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # if (EAX == Eof) return EAX @@ -1389,7 +1389,7 @@ skip-until-newline: # in : (address buffered-file) -> <void> # pseudocode: # push EAX # while true - # EAX = read-byte(in) + # EAX = read-byte-buffered(in) # if (EAX == Eof) break # if (EAX == 0x0a) break # pop EAX @@ -1399,11 +1399,11 @@ skip-until-newline: # in : (address buffered-file) -> <void> # . save registers 50/push-EAX $skip-until-newline:loop: - # . EAX = read-byte(in) + # . EAX = read-byte-buffered(in) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # . if (EAX == Eof) break diff --git a/subx/apps/pack b/subx/apps/pack index 54c3f203..318dc3d4 100755 --- a/subx/apps/pack +++ b/subx/apps/pack Binary files differdiff --git a/subx/apps/pack.subx b/subx/apps/pack.subx index 6ac03fc4..88ed23b6 100644 --- a/subx/apps/pack.subx +++ b/subx/apps/pack.subx @@ -96,7 +96,7 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void # var in-code? = false # while true # clear-stream(line) - # read-line(in, line) + # read-line-buffered(in, line) # if (line->write == 0) break # end of file # var word-slice = next-word(line) # if slice-empty?(word-slice) # whitespace @@ -141,12 +141,12 @@ $convert: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(in, line) + # read-line-buffered(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/disp32 + e8/call read-line-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP $convert:check0: @@ -218,12 +218,12 @@ $convert:check2: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 52/push-EDX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -283,12 +283,12 @@ $convert:check2: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 52/push-EDX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -937,7 +937,7 @@ convert-data: # line : (address stream byte), out : (address buffered-file) -> # if slice-empty?(word-slice) # end of file (maybe including trailing whitespace) # break # skip emitting some whitespace # if slice-starts-with?(word-slice, "#") # comment - # write-slice(out, word-slice) + # write-slice-buffered(out, word-slice) # break # if slice-ends-with?(word-slice, ":") # label # write-stream-data(out, line) @@ -1012,12 +1012,12 @@ $convert-data:loop: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 51/push-ECX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -1059,12 +1059,12 @@ $convert-data:check-for-comment: 3d/compare-EAX-and 0x23/imm32/hash 75/jump-if-not-equal $convert-data:check-for-label/disp8 $convert-data:comment: - # write-slice(out, word-slice) + # write-slice-buffered(out, word-slice) # . . push args 51/push-ECX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # break @@ -1999,14 +1999,14 @@ emit-opcodes: # line : (address stream byte), out : (address buffered-file) -> # var op1 = next-word(line) # if (slice-empty?(op1) || slice-starts-with?(op1, "#")) return # op1 = next-token-from-slice(op1->start, op1->end, "/") - # write-slice(out, op1) + # write-slice-buffered(out, op1) # if !slice-equal?(op1, "0f") && !slice-equal?(op1, "f2") && !slice-equal?(op1, "f3") # return # # var op2 = next-word(line) # if (slice-empty?(op2) || slice-starts-with?(op2, "#")) return # op2 = next-token-from-slice(op2->start, op2->end, "/") - # write-slice(out, op2) + # write-slice-buffered(out, op2) # if slice-equal?(op1, "0f") # return # if !slice-equal?(op2, "0f") @@ -2015,7 +2015,7 @@ emit-opcodes: # line : (address stream byte), out : (address buffered-file) -> # var op3 = next-word(line) # if (slice-empty?(op3) || slice-starts-with?(op3, "#")) return # op3 = next-token-from-slice(op3->start, op3->end, "/") - # write-slice(out, op3) + # write-slice-buffered(out, op3) # # . prolog 55/push-EBP @@ -2079,12 +2079,12 @@ $emit-opcodes:op1: e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # write-slice(out, op1) + # write-slice-buffered(out, op1) # . . push args 51/push-ECX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # write-buffered(out, " ") @@ -2172,12 +2172,12 @@ $emit-opcodes:op2: e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # write-slice(out, op2) + # write-slice-buffered(out, op2) # . . push args 52/push-EDX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # write-buffered(out, " ") @@ -2251,12 +2251,12 @@ $emit-opcodes:op3: e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # write-slice(out, op3) + # write-slice-buffered(out, op3) # . . push args 52/push-EDX ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # write-buffered(out, " ") @@ -2388,12 +2388,12 @@ $emit-modrm:loop: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 51/push-ECX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -2699,12 +2699,12 @@ $emit-sib:loop: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 51/push-ECX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -2964,12 +2964,12 @@ $emit-disp:loop: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 51/push-ECX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -3185,12 +3185,12 @@ $emit-imm:loop: #? e8/call clear-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP -#? # . write-slice(Stderr, word-slice) +#? # . write-slice-buffered(Stderr, word-slice) #? # . . push args #? 51/push-ECX #? 68/push Stderr/imm32 #? # . . call -#? e8/call write-slice/disp32 +#? e8/call write-slice-buffered/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP #? # . flush(Stderr) @@ -6373,7 +6373,7 @@ emit: # out : (address buffered-file), word : (address slice), width : int -> < e8/call next-token-from-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP - # if (is-valid-name?(datum)) write-slice(out, word) and return + # if (is-valid-name?(datum)) write-slice-buffered(out, word) and return # . EAX = is-valid-name?(name) # . . push args 57/push-EDI @@ -6385,12 +6385,12 @@ emit: # out : (address buffered-file), word : (address slice), width : int -> < 3d/compare-EAX-and 0/imm32 74/jump-if-equal $emit:hex-int/disp8 $emit:name: - # . write-slice(out, word) + # . write-slice-buffered(out, word) # . . push args 56/push-ESI ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) # . . call - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # . write-buffered(out, " ") @@ -7054,20 +7054,20 @@ $emit-hex:loop: # if (curr >= width) break 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX 7d/jump-if-greater-or-equal $emit-hex:end/disp8 - # print-byte(out, EBX) + # print-byte-buffered(out, EBX) # . . push args 53/push-EBX 57/push-EDI # . . call - e8/call print-byte/disp32 + e8/call print-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # write-byte(out, ' ') + # write-byte-buffered(out, ' ') # . . push args 68/push 0x20/imm32/space 57/push-EDI # . . call - e8/call write-byte/disp32 + e8/call write-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # EBX = EBX >> 8 diff --git a/subx/apps/subx-common.subx b/subx/apps/subx-common.subx index 0807b210..cba1e9cc 100644 --- a/subx/apps/subx-common.subx +++ b/subx/apps/subx-common.subx @@ -7,7 +7,7 @@ # write an entire stream's contents to a buffered-file # ways to do this: -# - construct a 'maximal slice' and pass it to write-slice +# - construct a 'maximal slice' and pass it to write-slice-buffered # - 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-data: # f : (address buffered-file), s : (address stream) -> <void> @@ -30,12 +30,12 @@ write-stream-data: # f : (address buffered-file), s : (address stream) -> <void 50/push-EAX # . ECX = ESP 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX - # write-slice(f, slice) + # write-slice-buffered(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 + e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP $write-stream-data:end: |