diff --git a/subx/058stream-equal.subx b/subx/058stream-equal.subx index ee04d4eb..88a09d9c 100644 --- a/subx/058stream-equal.subx +++ b/subx/058stream-equal.subx @@ -588,7 +588,7 @@ test-next-stream-line-equal-handles-final-line: 5d/pop-to-EBP c3/return -test-next-stream-line-equal-always-fails-after-eof: +test-next-stream-line-equal-always-fails-after-Eof: # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -610,7 +610,7 @@ test-next-stream-line-equal-always-fails-after-eof: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # check-ints-equal(EAX, 0, msg) # . . push args - 68/push "F - test-next-stream-line-equal-always-fails-after-eof"/imm32 + 68/push "F - test-next-stream-line-equal-always-fails-after-Eof"/imm32 68/push 1/imm32 50/push-EAX # . . call @@ -627,7 +627,7 @@ test-next-stream-line-equal-always-fails-after-eof: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # check-ints-equal(EAX, 0, msg) # . . push args - 68/push "F - test-next-stream-line-equal-always-fails-after-eof/2"/imm32 + 68/push "F - test-next-stream-line-equal-always-fails-after-Eof/2"/imm32 68/push 1/imm32 50/push-EAX # . . call diff --git a/subx/061read-byte.subx b/subx/061read-byte.subx index 26b63e63..cb068869 100644 --- a/subx/061read-byte.subx +++ b/subx/061read-byte.subx @@ -40,8 +40,8 @@ Stdin: #? cd/syscall 0x80/imm8 # return next byte value in EAX, with top 3 bytes cleared. -# On EOF, return 0xffffffff. -read-byte: # f : (address buffered-file) -> byte-or-eof/EAX +# On reaching end of file, return 0xffffffff (Eof). +read-byte: # 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 @@ -76,7 +76,7 @@ read-byte: # f : (address buffered-file) -> byte-or-eof/EAX # if (EAX == 0) return 0xffffffff 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32 # compare EAX 75/jump-if-not-equal $read-byte:from-stream/disp8 - b8/copy-to-EAX 0xffffffff/imm32 + b8/copy-to-EAX 0xffffffff/imm32/Eof eb/jump $read-byte:end/disp8 $read-byte:from-stream: # read byte from stream @@ -196,7 +196,7 @@ test-read-byte-multiple: c3/return test-read-byte-end-of-file: - # - call read-byte on an empty 'file', check that it returns 0xffffffff + # - call read-byte on an empty 'file', check that it returns Eof # setup # . clear-stream(_test-stream) # . . push args @@ -224,7 +224,7 @@ test-read-byte-end-of-file: # check-ints-equal(EAX, 0xffffffff, msg) # . . push args 68/push "F - test-read-byte-end-of-file"/imm32 - 68/push 0xffffffff/imm32 + 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 diff --git a/subx/071read-line.subx b/subx/071read-line.subx index bb0c03be..eff6f9c4 100644 --- a/subx/071read-line.subx +++ b/subx/071read-line.subx @@ -59,10 +59,11 @@ $read-line:loop: # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # if (f->write == 0) return true + # since f->read was initially 0, EAX is the same as f->write # . if (EAX == 0) return true 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32 # compare EAX 75/jump-if-not-equal $read-line:from-stream/disp8 - b8/copy-to-EAX 0xffffffff/imm32 + b8/copy-to-EAX 0xffffffff/imm32/Eof eb/jump $read-line:end/disp8 $read-line:from-stream: # AL = f->data[f->read] @@ -168,10 +169,10 @@ test-read-line: e8/call read-line/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(EAX, 0/not-at-eof, msg) + # check-ints-equal(EAX, 0/not-at-Eof, msg) # . . push args 68/push "F - test-read-line: return value"/imm32 - 68/push 0/imm32/not-at-eof + 68/push 0/imm32/not-at-Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 @@ -189,7 +190,7 @@ test-read-line: # end c3/return -test-read-line-returns-true-on-eof: +test-read-line-returns-true-on-Eof: # setup # . clear-stream(_test-stream) # . . push args @@ -223,10 +224,10 @@ test-read-line-returns-true-on-eof: e8/call read-line/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(EAX, eof, msg) + # check-ints-equal(EAX, Eof, msg) # . . push args - 68/push "F - test-read-line-returns-true-on-eof"/imm32 - 68/push 0xffffffff/imm32/not-at-eof + 68/push "F - test-read-line-returns-true-on-Eof"/imm32 + 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 @@ -235,7 +236,7 @@ test-read-line-returns-true-on-eof: # end c3/return -test-read-line-reads-final-line-until-eof: +test-read-line-reads-final-line-until-Eof: # setup # . clear-stream(_test-stream) # . . push args @@ -277,10 +278,10 @@ test-read-line-reads-final-line-until-eof: e8/call read-line/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # check-ints-equal(EAX, eof, msg) + # check-ints-equal(EAX, Eof, msg) # . . push args - 68/push "F - test-read-line-reads-final-line-until-eof: return value"/imm32 - 68/push 0xffffffff/imm32/not-at-eof + 68/push "F - test-read-line-reads-final-line-until-Eof: return value"/imm32 + 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 @@ -288,7 +289,7 @@ test-read-line-reads-final-line-until-eof: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/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-reads-final-line-until-Eof"/imm32 68/push "cd"/imm32 68/push _test-tmp-stream/imm32 # . . call diff --git a/subx/073next-token.subx b/subx/073next-token.subx index 1d37ba70..e65d5e60 100644 --- a/subx/073next-token.subx +++ b/subx/073next-token.subx @@ -11,7 +11,7 @@ #? cd/syscall 0x80/imm8 # extract the next run of characters that are different from a given 'delimiter' (skipping multiple delimiters if necessary) -# on eof return an empty interval +# on reaching end of file, return an empty interval next-token: # in : (address stream), delimiter : byte, out : (address slice) # . prolog 55/push-EBP @@ -123,7 +123,7 @@ test-next-token: 5d/pop-to-EBP c3/return -test-next-token-eof: +test-next-token-Eof: # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -151,7 +151,7 @@ test-next-token-eof: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # check-ints-equal(slice->end, slice->start, msg) # . . push args - 68/push "F - test-next-token-eof"/imm32 + 68/push "F - test-next-token-Eof"/imm32 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . . # push *ECX # . . call @@ -164,7 +164,7 @@ test-next-token-eof: c3/return # extract the next run of characters that are different from a given 'delimiter' (skipping multiple delimiters if necessary) -# on eof return an empty interval +# on reaching end of file, return an empty interval next-token-from-slice: # start : (address byte), end : (address byte), delimiter : byte, out : (address slice) -> # . prolog 55/push-EBP @@ -266,7 +266,7 @@ test-next-token-from-slice: 5d/pop-to-EBP c3/return -test-next-token-from-slice-eof: +test-next-token-from-slice-Eof: # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -287,7 +287,7 @@ test-next-token-from-slice-eof: # out should be empty # . check-ints-equal(out->end - out->start, 0, msg) # . . push args - 68/push "F - test-next-token-from-slice-eof"/imm32 + 68/push "F - test-next-token-from-slice-Eof"/imm32 68/push 0/imm32 # . . push out->start - in->start 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 4/disp8 . # copy *(EDI+4) to ECX @@ -328,7 +328,7 @@ test-next-token-from-slice-nothing: # out should be empty # . check-ints-equal(out->end - out->start, 0, msg) # . . push args - 68/push "F - test-next-token-from-slice-eof"/imm32 + 68/push "F - test-next-token-from-slice-Eof"/imm32 68/push 0/imm32 # . . push out->start - in->start 8b/copy 1/mod/*+disp8 7/rm32/EDI . . . 1/r32/ECX 4/disp8 . # copy *(EDI+4) to ECX diff --git a/subx/apps/hex.subx b/subx/apps/hex.subx index 4f65d03b..69f426e7 100644 --- a/subx/apps/hex.subx +++ b/subx/apps/hex.subx @@ -74,7 +74,7 @@ convert: # in : (address buffered-file), out : (address buffered-file), err : ( # pseudocode: # repeatedly # EAX = convert-next-octet(in, err, ed) - # if (EAX == 0xffffffff) break # eof + # if (EAX == Eof) break # write-byte(out, AL) # flush(out) # @@ -93,8 +93,8 @@ $convert:loop: e8/call convert-next-octet/disp32 # . . discard first 2 args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP - # if (EAX == 0xffffffff) break - 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32 # compare EAX + # if (EAX == Eof) break + 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32/Eof # compare EAX 74/jump-if-equal $convert:loop-end/disp8 # write-byte(out, AL) # . . push args @@ -127,14 +127,14 @@ $convert:end: # on '#' skip bytes until newline # raise an error and abort on all other unexpected bytes # return in EAX an _octet_ containing the binary value of the two hex characters -# return 0xffffffff on end of file -convert-next-octet: # in : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> byte-or-eof/EAX +# return Eof on reaching end of file +convert-next-octet: # in : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> byte-or-Eof/EAX # pseudocode: # EAX = scan-next-byte(in, err, ed) - # if (EAX == 0xffffffff) return + # if (EAX == Eof) return # ECX = from-hex-char(EAX) # EAX = scan-next-byte(in, err, ed) - # if (EAX == 0xffffffff) error("partial byte found.") + # if (EAX == Eof) error("partial byte found.") # EAX = from-hex-char(EAX) # EAX = (ECX << 4) | EAX # return @@ -153,8 +153,8 @@ convert-next-octet: # in : (address buffered-file), err : (address buffered-fil e8/call scan-next-byte/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP - # if (EAX == 0xffffffff) return - 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32 # compare EAX + # if (EAX == Eof) return + 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32/Eof # compare EAX 74/jump-if-equal $convert-next-octet:end/disp8 # EAX = from-hex-char(EAX) e8/call from-hex-char/disp32 @@ -169,8 +169,8 @@ convert-next-octet: # in : (address buffered-file), err : (address buffered-fil e8/call scan-next-byte/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP - # if (EAX == 0xffffffff) error(ed, err, "partial byte found.") - 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32 # compare EAX + # if (EAX == Eof) error(ed, err, "partial byte found.") + 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32/Eof # compare EAX 75/jump-if-not-equal $convert-next-octet:convert/disp8 # . error-byte(ed, err, msg, '.') # reusing error-byte to avoid creating _yet_ another helper # . . push args @@ -298,8 +298,8 @@ $test-convert-next-octet:end: 5d/pop-to-EBP c3/return -test-convert-next-octet-handles-eof: - # - check that eof returns the sentinel octet +test-convert-next-octet-handles-Eof: + # - check that reaching end of file returns Eof # This test uses exit-descriptors. Use EBP for setting up local variables. 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -375,17 +375,17 @@ test-convert-next-octet-handles-eof: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # return if abort 81 7/subop/compare 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # compare *(ECX+4) - 75/jump-if-not-equal $test-convert-next-octet-handles-eof:end/disp8 - # check-ints-equal(EAX, 0xffffffff, msg) + 75/jump-if-not-equal $test-convert-next-octet-handles-Eof:end/disp8 + # check-ints-equal(EAX, Eof, msg) # . . push args - 68/push "F - test-convert-next-octet-handles-eof"/imm32 - 68/push 0xffffffff/imm32/eof + 68/push "F - test-convert-next-octet-handles-Eof"/imm32 + 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -$test-convert-next-octet-handles-eof:end: +$test-convert-next-octet-handles-Eof:end: # . epilog # don't restore ESP from EBP; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP @@ -483,14 +483,14 @@ $test-convert-next-octet-aborts-on-single-hex-byte:end: c3/return # read whitespace until a hex byte, and return it -# return 0xffffffff if file ends without finding a hex byte +# return Eof if file ends without finding a hex byte # on '#' skip all bytes until newline # abort on any other byte -scan-next-byte: # in : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> byte-or-eof/EAX +scan-next-byte: # in : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> byte-or-Eof/EAX # pseudocode: # repeatedly # EAX = read-byte(in) - # if (EAX == 0xffffffff) return EAX + # if (EAX == Eof) return EAX # if (is-hex-digit?(EAX)) return EAX # if (EAX == ' ' or '\t' or '\n') continue # if (EAX == '#') skip-until-newline(in) @@ -508,8 +508,8 @@ $scan-next-byte:loop: e8/call read-byte/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # if (EAX == 0xffffffff) return EAX - 3d/compare-with-EAX 0xffffffff/imm32 + # if (EAX == Eof) return EAX + 3d/compare-with-EAX 0xffffffff/imm32/Eof 74/jump-if-equal $scan-next-byte:end/disp8 # if (is-hex-digit?(EAX)) return EAX # . save EAX for now @@ -1225,7 +1225,7 @@ $test-scan-next-byte-reads-final-byte:end: 5d/pop-to-EBP c3/return -test-scan-next-byte-handles-eof: +test-scan-next-byte-handles-Eof: # - check that the right sentinel value is returned when there's no data remaining to be read # This test uses exit-descriptors. Use EBP for setting up local variables. 55/push-EBP @@ -1292,7 +1292,7 @@ test-scan-next-byte-handles-eof: # check that scan-next-byte didn't abort # . check-ints-equal(ed->value, 0, msg) # . . push args - 68/push "F - test-scan-next-byte-handles-eof: unexpected abort"/imm32 + 68/push "F - test-scan-next-byte-handles-Eof: unexpected abort"/imm32 68/push 0/imm32 # . . push ed->value ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 . # push *(ECX+4) @@ -1302,17 +1302,17 @@ test-scan-next-byte-handles-eof: 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # return if abort 81 7/subop/compare 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 0/imm32 # compare *(ECX+4) - 75/jump-if-not-equal $test-scan-next-byte-handles-eof:end/disp8 - # check-ints-equal(EAX, 0xffffffff/eof, msg) + 75/jump-if-not-equal $test-scan-next-byte-handles-Eof:end/disp8 + # check-ints-equal(EAX, Eof, msg) # . . push args - 68/push "F - test-scan-next-byte-handles-eof"/imm32 - 68/push 0xffffffff/imm32/eof + 68/push "F - test-scan-next-byte-handles-Eof"/imm32 + 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -$test-scan-next-byte-handles-eof:end: +$test-scan-next-byte-handles-Eof:end: # . epilog # don't restore ESP from EBP; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP @@ -1414,7 +1414,7 @@ skip-until-newline: # in : (address buffered-file) -> # push EAX # repeatedly: # EAX = read-byte(in) - # if (EAX == 0xffffffff) break + # if (EAX == Eof) break # if (EAX == 0x0a) break # pop EAX # . prolog @@ -1430,8 +1430,8 @@ $skip-until-newline:loop: e8/call read-byte/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # . if (EAX == 0xffffffff) break - 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32 # compare EAX + # . if (EAX == Eof) break + 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xffffffff/imm32/Eof # compare EAX 74/jump-if-equal $skip-until-newline:end/disp8 # . if (EAX != 0xa/newline) loop 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0xa/imm32 # compare EAX @@ -1520,7 +1520,7 @@ _test-error-stream: # data 00 00 00 00 00 00 00 00 # 8 bytes -# a test buffered file for _test-stream +# a test buffered file for _test-error-stream _test-error-buffered-file: # file descriptor or (address stream) _test-error-stream/imm32 diff --git a/subx/apps/pack b/subx/apps/pack index a16daf5b..70139ff5 100755 Binary files a/subx/apps/pack and b/subx/apps/pack differ diff --git a/subx/apps/pack.subx b/subx/apps/pack.subx index fa383042..c6cdaf14 100644 --- a/subx/apps/pack.subx +++ b/subx/apps/pack.subx @@ -89,7 +89,7 @@ convert: # in : (address buffered-file), out : (address buffered-file) ->