5672 - move hex out of apps
This commit is contained in:
parent
825d9ebbe4
commit
dfbe155087
|
@ -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
|
|
@ -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
|
||||
|
|
BIN
apps/assort
BIN
apps/assort
Binary file not shown.
BIN
apps/braces
BIN
apps/braces
Binary file not shown.
BIN
apps/calls
BIN
apps/calls
Binary file not shown.
BIN
apps/crenshaw2-1
BIN
apps/crenshaw2-1
Binary file not shown.
Binary file not shown.
BIN
apps/dquotes
BIN
apps/dquotes
Binary file not shown.
BIN
apps/factorial
BIN
apps/factorial
Binary file not shown.
BIN
apps/handle
BIN
apps/handle
Binary file not shown.
|
@ -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
|
||||
|
|
BIN
apps/sigils
BIN
apps/sigils
Binary file not shown.
BIN
apps/survey
BIN
apps/survey
Binary file not shown.
BIN
apps/tests
BIN
apps/tests
Binary file not shown.
5
build
5
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 && {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue