commit 8ac0e4809eb5a9ea59ced26f637dff26aa123bb1
parent cbfcc97e0ebc9cf71d871a28c2323bf1fd9b5a1e
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 11 Mar 2023 07:44:17 -0500
hal: all tests passing under the POSIX VM!
CC forth backend is a bit of a mess at the moment, but the whole thing is going
to be rewritten in HAL anyways.
Now, let's tackle i386! it's going to be fun...
Diffstat:
7 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/fs/comp/c/vm/forth.fs b/fs/comp/c/vm/forth.fs
@@ -46,8 +46,9 @@ struct+[ VMOp
: :>res dup :compile :>reg ;
]struct
+: _psrewind ?dup if CELLSZ - ?dup if ps+, then drop, then ;
\ Free elements leaked to PS during the execution of the function
-: neutral# 0 to@! psoff ?dup if ps+, then ;
+: neutral# 0 to@! psoff _psrewind ;
\ generate function prelude code by allocating "locsz" bytes on RS.
: vmprelude, ( argsz locsz -- )
@@ -59,8 +60,8 @@ struct+[ VMOp
: vmret,
vmop^ :noop# \ returning with a second operand? something's wrong
vmop loc dup >r if vmop :compile$ PS- then
- 0 to@! psoff argsz + ps+,
- r> ( vmop loc ) not if drop, then
+ 0 to@! psoff argsz + ?dup if
+ r@ ( had loc? ) if ps+, else _psrewind then then rdrop
locsz ?dup if rs+, then exit, ;
: vmcall, ( ?argN .. ?arg0 nargs -- ) dup >r \ V1=nargs
@@ -87,8 +88,7 @@ struct+[ VMOp
\ on PS *has* to be right after the last argument of the args frame.
\ The same logic applies to vmswitch,.
: _compileFinal
- vmop^ :noop# vmop :compile$ PS-
- 0 to@! psoff ?dup if ps+, then ;
+ vmop^ :noop# vmop :compile$ PS- 0 to@! psoff ?dup if ps+, then ;
: vmjz, ( a -- ) _compileFinal [compile] until ;
: vmjz[, ( -- a ) _compileFinal [compile] if ;
: vmjnz, ( a -- ) _compileFinal compile not [compile] until ;
diff --git a/fs/tests/all.fs b/fs/tests/all.fs
@@ -5,8 +5,8 @@ f<< /tests/sys/all.fs
f<< /tests/fs/all.fs
f<< /tests/comp/c/all.fs
f<< /tests/asm/all.fs
-\ f<< /tests/ar/all.fs
-\ f<< /tests/emul/all.fs
+f<< /tests/ar/all.fs
+f<< /tests/emul/all.fs
f<< /tests/gr/all.fs
f<< /tests/text/all.fs
." All tests passed\n"
diff --git a/fs/tests/comp/c/all.fs b/fs/tests/comp/c/all.fs
@@ -1,5 +1,5 @@
\ Run all CC test suites
f<< tests/comp/c/type.fs
f<< tests/comp/c/vm.fs
-\ f<< tests/comp/c/cc.fs
-\ f<< tests/comp/c/lib.fs
+f<< tests/comp/c/cc.fs
+f<< tests/comp/c/lib.fs
diff --git a/fs/tests/comp/c/vm.fs b/fs/tests/comp/c/vm.fs
@@ -272,4 +272,12 @@ code test18 ( n n -- n )
vm*,
vmret,
2 3 test18 6 #eq
+
+\ A simple pspush(pspop()) doesn't mess the stack
+code test19 ( n -- n )
+ 0 0 vmprelude, ops$
+ vmpspop,
+ vmpspush,
+ vmret,
+123 test19 123 #eq
testend
diff --git a/fs/tests/lib/all.fs b/fs/tests/lib/all.fs
@@ -13,4 +13,4 @@ f<< /tests/lib/math.fs
f<< /tests/lib/stack.fs
f<< /tests/lib/tree.fs
f<< /tests/lib/fmt.fs
-\ f<< /tests/lib/crc.fs
+f<< /tests/lib/crc.fs
diff --git a/posix/dis.c b/posix/dis.c
@@ -169,6 +169,9 @@ struct call {
struct call calls[CALLCNT] = {
{0x2e8, "-"},
{0x1760, "dup"},
+ {0x18a4, "rot"},
+ {0x18f8, "nip"},
+ {0x1a94, "!"},
{0x1b18, "@"},
{0x1e54, "execute"},
{0x1e94, "not"},
diff --git a/posix/vm.c b/posix/vm.c
@@ -892,7 +892,7 @@ int main() {
vm.PC = find("(abort)");
while (vm.PC < MEMSZ) oprun1();
if (fp) fclose(fp);
- if (1 || (vm.PC > MEMSZ)) {
+ if (vm.PC > MEMSZ) {
fprintf(stderr, "Dumping memory to memdump.\n");
FILE *fp = fopen("memdump", "w");
fwrite(vm.mem, MEMSZ, 1, fp);