diff options
Diffstat (limited to 'subx/apps')
-rwxr-xr-x | subx/apps/assort | bin | 21809 -> 22287 bytes | |||
-rw-r--r-- | subx/apps/assort.subx | 14 | ||||
-rwxr-xr-x | subx/apps/crenshaw2-1 | bin | 18968 -> 19446 bytes | |||
-rw-r--r-- | subx/apps/crenshaw2-1.subx | 4 | ||||
-rwxr-xr-x | subx/apps/crenshaw2-1b | bin | 19527 -> 20005 bytes | |||
-rw-r--r-- | subx/apps/crenshaw2-1b.subx | 7 | ||||
-rwxr-xr-x | subx/apps/dquotes | bin | 22663 -> 24275 bytes | |||
-rw-r--r-- | subx/apps/dquotes.subx | 432 | ||||
-rwxr-xr-x | subx/apps/factorial | bin | 17884 -> 18362 bytes | |||
-rwxr-xr-x | subx/apps/handle | bin | 18711 -> 19189 bytes | |||
-rwxr-xr-x | subx/apps/hex | bin | 21977 -> 22455 bytes | |||
-rw-r--r-- | subx/apps/hex.subx | 18 | ||||
-rwxr-xr-x | subx/apps/pack | bin | 36569 -> 37047 bytes | |||
-rw-r--r-- | subx/apps/pack.subx | 72 | ||||
-rw-r--r-- | subx/apps/subx-common.subx | 6 |
15 files changed, 482 insertions, 71 deletions
diff --git a/subx/apps/assort b/subx/apps/assort index d2aaaf1a..1cd0b6cf 100755 --- a/subx/apps/assort +++ b/subx/apps/assort Binary files differdiff --git a/subx/apps/assort.subx b/subx/apps/assort.subx index cfdef5e1..7498cc3a 100644 --- a/subx/apps/assort.subx +++ b/subx/apps/assort.subx @@ -446,7 +446,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 @@ -497,12 +497,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: @@ -584,12 +584,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) @@ -648,12 +648,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 3fbc9c33..03d3d0c3 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 71265ffe..60521cb0 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 251a3e3a..c180c114 100755 --- a/subx/apps/dquotes +++ b/subx/apps/dquotes Binary files differdiff --git a/subx/apps/dquotes.subx b/subx/apps/dquotes.subx index cd376f5d..5f98d295 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-next-word-returns-string-with-escapes/disp32 +#? e8/call test-emit-string-literal-data/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 @@ -100,7 +100,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) @@ -111,7 +111,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(out, " ") # write(out, "\n\n") # write-stream-data(out, new-data-segment) @@ -165,12 +165,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: @@ -224,12 +224,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 @@ -827,13 +827,393 @@ 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 + # curr = word->start + # ++curr # skip '"' + # while true + # if (curr >= word->end) break + # c = *curr + # if (c == '"') break + # append-byte-hex(out, c) + # if c is alphanumeric: + # write(out, "/") + # append-byte(out, c) + # write(out, " ") + # ++curr + # # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers + 50/push-EAX + 51/push-ECX + 52/push-EDX + 56/push-ESI + # ESI = word + 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 + # ++curr # skip initial '"' + 42/increment-EDX + # max/ESI = word->end + 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 6/r32/ESI 4/disp8 . # copy *(ESI+4) to ESI + # ECX = 0 + 31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . . # clear ECX +$emit-string-literal-data:loop: + # if (curr >= max) break + 39/compare 3/mod/direct 2/rm32/EDX . . . 6/r32/ESI . . # compare EDX with ESI + 7d/jump-if-greater-or-equal $emit-string-literal-data:end/disp8 + # CL = *curr + 8a/copy-byte 0/mod/indirect 2/rm32/EDX . . . 1/r32/CL . . # copy byte at *EDX to CL + # if (ECX == '"') break + 81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0x22/imm32/dquote # compare ECX + 74/jump-if-equal $emit-string-literal-data:end/disp8 + # append-byte-hex(out, CL) + # . . push args + 51/push-ECX + ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) + # . . call + e8/call append-byte-hex/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # if (is-alphanumeric?(*curr)) print(out, "/#{*curr}") + # . EAX = is-alphanumeric?(CL) + # . . push args + 51/push-ECX + # . . call + e8/call is-alphanumeric?/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . if (EAX == 0) goto char-done + 3d/compare-EAX-and 0/imm32 + 74/jump-if-equal $emit-string-literal-data:char-done/disp8 + # . write(out, "/") + # . . push args + 68/push Slash/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 + # . append-byte(out, *curr) + # . . push args + 51/push-ECX + ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) + # . . call + e8/call append-byte/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +$emit-string-literal-data:char-done: + # write(out, " ") + # . . push args + 68/push Space/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 + # ++curr + 42/increment-EDX + eb/jump $emit-string-literal-data:loop/disp8 $emit-string-literal-data:end: - # . reclaim locals # . restore registers + 5e/pop-to-ESI + 5a/pop-to-EDX + 59/pop-to-ECX + 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 + +is-alphanumeric?: # c : int -> EAX : boolean + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # EAX = c + 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 . # copy *(EBP+8) to EAX + # if (EAX < '0') return false + 3d/compare-EAX-with 0x30/imm32/0 + 7c/jump-if-lesser $is-alphanumeric?:false/disp8 + # if (EAX <= '9') return true + 3d/compare-EAX-with 0x39/imm32/9 + 7e/jump-if-lesser-or-equal $is-alphanumeric?:true/disp8 + # if (EAX < 'A') return false + 3d/compare-EAX-with 0x41/imm32/A + 7c/jump-if-lesser $is-alphanumeric?:false/disp8 + # if (EAX <= 'Z') return true + 3d/compare-EAX-with 0x5a/imm32/Z + 7e/jump-if-lesser-or-equal $is-alphanumeric?:true/disp8 + # if (EAX < 'a') return false + 3d/compare-EAX-with 0x61/imm32/a + 7c/jump-if-lesser $is-alphanumeric?:false/disp8 + # if (EAX <= 'z') return true + 3d/compare-EAX-with 0x7a/imm32/z + 7e/jump-if-lesser-or-equal $is-alphanumeric?:true/disp8 + # return false +$is-alphanumeric?:false: + b8/copy-to-EAX 0/imm32/false + eb/jump $is-alphanumeric?:end/disp8 +$is-alphanumeric?:true: + b8/copy-to-EAX 1/imm32/true +$is-alphanumeric?:end: + # . epilog + 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP + 5d/pop-to-EBP + c3/return + +test-emit-string-literal-data: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # setup + # . 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 + # var slice/ECX = '"abc"' + 68/push _test-slice-abc-end/imm32 + 68/push _test-slice-abc/imm32 + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # emit-string-literal-data(_test-output-stream, slice) + # . . push args + 51/push-ECX + 68/push _test-output-stream/imm32 + # . . 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 +#? # 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 +#? # }}} + # . check-stream-equal(_test-output-stream, "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 _test-output-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 + +test-emit-string-literal-data-empty: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # setup + # . 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 + # var slice/ECX = '""' + 68/push _test-slice-empty-string-literal-end/imm32 + 68/push _test-slice-empty-string-literal/imm32 + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # emit-string-literal-data(_test-output-stream, slice) + # . . push args + 51/push-ECX + 68/push _test-output-stream/imm32 + # . . 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 +#? # 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 +#? # }}} + # . check-stream-equal(_test-output-stream, "", msg) + # . . push args + 68/push "F - test-emit-string-literal-data-empty"/imm32 + 68/push ""/imm32 + 68/push _test-output-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 + +# just to keep things simple +test-emit-string-literal-data-no-metadata-for-non-alphanumerics: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # setup + # . 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 + # var slice/ECX = '"a b"' + 68/push _test-slice-a-space-b-end/imm32 + 68/push _test-slice-a-space-b/imm32 + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # emit-string-literal-data(_test-output-stream, slice) + # . . push args + 51/push-ECX + 68/push _test-output-stream/imm32 + # . . 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 +#? # 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 +#? # }}} + # . 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 + # . . 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 _test-output-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 + +test-emit-string-literal-data-handles-escape-sequences: + # . prolog + 55/push-EBP + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # setup + # . 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 + # var slice/ECX = '"a\"b"' + 68/push _test-slice-a-dquote-b-end/imm32 + 68/push _test-slice-a-dquote-b/imm32 + 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX + # emit-string-literal-data(_test-output-stream, slice) + # . . push args + 51/push-ECX + 68/push _test-output-stream/imm32 + # . . 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 +#? # 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 +#? # }}} + # . check-stream-equal(_test-output-stream, "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 _test-output-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 @@ -854,7 +1234,7 @@ emit-metadata: # out : (address buffered-file), word : (address slice) # while true: # if ECX == word->end: return # if *(ECX++) == '/': break - # write-slice(out, {ECX, word->end}) + # write-slice-buffered(out, {ECX, word->end}) # ECX = word 8b/copy/word 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0xc/disp8 . # copy *(EBP+12) to ECX @@ -884,7 +1264,7 @@ $skip-datum-loop: 75/jump-if-not-equal $skip-datum-loop/disp8 # end - # write-slice(out, &{start, end}) + # write-slice-buffered(out, &{start, end}) # . push end 52/push-EDX # . push start @@ -895,7 +1275,7 @@ $skip-datum-loop: # . push out ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) - e8/call write-slice/disp32 + e8/call write-slice-buffered/disp32 # . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . 0x10/imm32 . # add 16 to ESP @@ -1556,6 +1936,36 @@ Heap: # limit 0/imm32 +# length-prefixed string containing just a single space +Space: + # size + 1/imm32 + # data + 20/space + +# length-prefixed string containing just a single slash +Slash: + # size + 1/imm32 + # data + 2f/slash + +_test-slice-abc: + 22/dquote 61/a 62/b 63/c 22/dquote # "abc" +_test-slice-abc-end: + +_test-slice-empty-string-literal: + 22/dquote 22/dquote # "" +_test-slice-empty-string-literal-end: + +_test-slice-a-space-b: + 22/dquote 61/a 20/space 62/b 22/dquote # "a b" +_test-slice-a-space-b-end: + +_test-slice-a-dquote-b: + 22/dquote 61/a 5c/backslash 22/dquote 62/b 22/dquote # "a\"b" +_test-slice-a-dquote-b-end: + # abc/def/ghi _test-slice-word: 61/a 62/b 63/c # abc diff --git a/subx/apps/factorial b/subx/apps/factorial index 4f5f7dc2..c18b8bcc 100755 --- a/subx/apps/factorial +++ b/subx/apps/factorial Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle index 520ca276..4fe1e044 100755 --- a/subx/apps/handle +++ b/subx/apps/handle Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex index 667fbc1f..59170942 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 2b313f08..f2149b59 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: |