diff options
-rw-r--r-- | 070---hex.subx (renamed from apps/hex.subx) | 26 | ||||
-rw-r--r-- | Readme.md | 2 | ||||
-rwxr-xr-x | apps/assort | bin | 40175 -> 44323 bytes | |||
-rwxr-xr-x | apps/braces | bin | 39569 -> 43717 bytes | |||
-rwxr-xr-x | apps/calls | bin | 44930 -> 49078 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1 | bin | 33919 -> 38067 bytes | |||
-rwxr-xr-x | apps/crenshaw2-1b | bin | 34478 -> 38626 bytes | |||
-rwxr-xr-x | apps/dquotes | bin | 45364 -> 49512 bytes | |||
-rwxr-xr-x | apps/factorial | bin | 32931 -> 37079 bytes | |||
-rwxr-xr-x | apps/handle | bin | 33785 -> 37972 bytes | |||
-rw-r--r-- | apps/handle.subx | 18 | ||||
-rwxr-xr-x | apps/hex | bin | 42573 -> 19492 bytes | |||
-rwxr-xr-x | apps/pack | bin | 52846 -> 56994 bytes | |||
-rwxr-xr-x | apps/sigils | bin | 52868 -> 57016 bytes | |||
-rwxr-xr-x | apps/survey | bin | 49448 -> 53596 bytes | |||
-rwxr-xr-x | apps/tests | bin | 38992 -> 43140 bytes | |||
-rwxr-xr-x | build | 5 | ||||
-rwxr-xr-x | test_apps | 8 |
18 files changed, 42 insertions, 17 deletions
diff --git a/apps/hex.subx b/070---hex.subx index ad09a3c3..9092c6dd 100644 --- a/apps/hex.subx +++ b/070---hex.subx @@ -34,7 +34,7 @@ Entry: # run tests if necessary, convert stdin if not # - if argc > 1 and argv[1] == "test", then return run_tests() # if (argc <= 1) goto run-main 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0/disp8 1/imm32 # compare *ebp - 7e/jump-if-lesser-or-equal $run-main/disp8 + 7e/jump-if-lesser-or-equal $hex:run-main/disp8 # if (!kernel-string-equal?(argv[1], "test")) goto run-main # . eax = kernel-string-equal?(argv[1], "test") # . . push args @@ -46,13 +46,13 @@ Entry: # run tests if necessary, convert stdin if not 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . if (eax == 0) goto run-main 3d/compare-eax-and 0/imm32 - 74/jump-if-equal $run-main/disp8 + 74/jump-if-equal $hex:run-main/disp8 # run-tests() e8/call run-tests/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 - eb/jump $main:end/disp8 -$run-main: + eb/jump $hex:end/disp8 +$hex:run-main: # - otherwise convert stdin # var ed/eax : exit-descriptor 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # subtract from esp @@ -60,24 +60,24 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # convert(Stdin, 1/stdout, 2/stderr, ed) + # convert-hex(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-eax/ed 68/push Stderr/imm32 68/push Stdout/imm32 68/push Stdin/imm32 # . . call - e8/call convert/disp32 + e8/call convert-hex/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp # syscall(exit, 0) bb/copy-to-ebx 0/imm32 -$main:end: +$hex:end: b8/copy-to-eax 1/imm32/exit cd/syscall 0x80/imm8 # the main entry point -convert: # in : (address buffered-file), out : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> <void> +convert-hex: # in : (address buffered-file), out : (address buffered-file), err : (address buffered-file), ed : (address exit-descriptor) -> <void> # pseudocode: # while true # eax = convert-next-octet(in, err, ed) @@ -90,7 +90,7 @@ convert: # in : (address buffered-file), out : (address buffered-file), err : ( 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax -$convert:loop: +$convert-hex:loop: # eax = convert-next-octet(in, err, ed) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 . # push *(ebp+20) @@ -102,7 +102,7 @@ $convert:loop: 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # if (eax == Eof) break 3d/compare-eax-and 0xffffffff/imm32/Eof - 74/jump-if-equal $convert:loop-end/disp8 + 74/jump-if-equal $convert-hex:loop-end/disp8 # write-byte-buffered(out, AL) # . . push args 50/push-eax @@ -112,8 +112,8 @@ $convert:loop: # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # loop - eb/jump $convert:loop/disp8 -$convert:loop-end: + eb/jump $convert-hex:loop/disp8 +$convert-hex:loop-end: # flush(out) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) @@ -121,7 +121,7 @@ $convert:loop-end: e8/call flush/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -$convert:end: +$convert-hex:end: # . restore registers 58/pop-to-eax # . epilog diff --git a/Readme.md b/Readme.md index 578ec91a..733e1bb8 100644 --- a/Readme.md +++ b/Readme.md @@ -104,7 +104,7 @@ You can use SubX to translate itself. For example, running natively on Linux: ```sh # generate translator phases using the C++ translator - $ ./subx translate init.linux 0*.subx apps/subx-common.subx apps/hex.subx -o hex + $ ./subx translate init.linux 0[0-6]*.subx 070---hex.subx -o hex $ ./subx translate init.linux 0*.subx apps/subx-common.subx apps/survey.subx -o survey $ ./subx translate init.linux 0*.subx apps/subx-common.subx apps/pack.subx -o pack $ ./subx translate init.linux 0*.subx apps/subx-common.subx apps/assort.subx -o assort diff --git a/apps/assort b/apps/assort index d04fab27..ef57e4e3 100755 --- a/apps/assort +++ b/apps/assort Binary files differdiff --git a/apps/braces b/apps/braces index 187567e5..36e33941 100755 --- a/apps/braces +++ b/apps/braces Binary files differdiff --git a/apps/calls b/apps/calls index 863bd993..68c86663 100755 --- a/apps/calls +++ b/apps/calls Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1 index fd28bf3a..aefbe733 100755 --- a/apps/crenshaw2-1 +++ b/apps/crenshaw2-1 Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b index 8c96482d..fcd81297 100755 --- a/apps/crenshaw2-1b +++ b/apps/crenshaw2-1b Binary files differdiff --git a/apps/dquotes b/apps/dquotes index 108a74bb..c682b312 100755 --- a/apps/dquotes +++ b/apps/dquotes Binary files differdiff --git a/apps/factorial b/apps/factorial index 0fa9ab2b..3c8a8e46 100755 --- a/apps/factorial +++ b/apps/factorial Binary files differdiff --git a/apps/handle b/apps/handle index 1ebf8f81..f1e9f60a 100755 --- a/apps/handle +++ b/apps/handle Binary files differdiff --git a/apps/handle.subx b/apps/handle.subx index b5c98422..36283c16 100644 --- a/apps/handle.subx +++ b/apps/handle.subx @@ -26,7 +26,23 @@ # . 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 -# no Entry; the standard library runs all tests by default +Entry: + # initialize heap + # . Heap = new-segment(64KB) + # . . push args + 68/push Heap/imm32 + 68/push 0x10000/imm32/64KB + # . . call + e8/call new-segment/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + + e8/call run-tests/disp32 # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'. +$handle-main:end: + # 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 + cd/syscall 0x80/imm8 new: # ad : (address allocation-descriptor), n : int, out : (address handle) # . prolog diff --git a/apps/hex b/apps/hex index c9241871..4506f819 100755 --- a/apps/hex +++ b/apps/hex Binary files differdiff --git a/apps/pack b/apps/pack index 95a306bd..0926d466 100755 --- a/apps/pack +++ b/apps/pack Binary files differdiff --git a/apps/sigils b/apps/sigils index f4f1834d..6c54e194 100755 --- a/apps/sigils +++ b/apps/sigils Binary files differdiff --git a/apps/survey b/apps/survey index 6097c5df..81a4623c 100755 --- a/apps/survey +++ b/apps/survey Binary files differdiff --git a/apps/tests b/apps/tests index 8def31f9..22968ff7 100755 --- a/apps/tests +++ b/apps/tests Binary files differdiff --git a/build b/build index d65c4dc4..0d723656 100755 --- a/build +++ b/build @@ -134,6 +134,11 @@ then done # self-hosting translator + + older_than apps/hex init.$OS 0[0-6]*.subx 070---hex.subx && { + ./subx_bin translate init.$OS 0[0-6]*.subx 070---hex.subx -o apps/hex + } + for phase in hex survey pack assort dquotes tests do older_than apps/$phase init.$OS [0-9]*.subx apps/subx-common.subx apps/$phase.subx && { diff --git a/test_apps b/test_apps index 29bd6075..bb645e97 100755 --- a/test_apps +++ b/test_apps @@ -226,7 +226,7 @@ test $NATIVE && { # Phases of the self-hosted SubX translator. echo hex -./subx translate init.$OS 0*.subx apps/subx-common.subx apps/hex.subx -o apps/hex +./subx translate init.$OS $(enumerate/enumerate --until 070---hex.subx |grep '\.subx$') -o apps/hex test "$1" = 'record' || git diff --exit-code apps/hex test $EMULATED && { ./subx run apps/hex test @@ -358,7 +358,11 @@ done # Phases of the self-hosted SubX translator. -for app in hex survey pack assort dquotes tests sigils calls braces +echo hex +./ntranslate init.$OS $(enumerate/enumerate --until 070---hex.subx |grep '\.subx$') +diff apps/hex a.elf + +for app in survey pack assort dquotes tests sigils calls braces do echo $app ./ntranslate init.$OS 0*.subx apps/subx-common.subx apps/$app.subx |