commit 09415954bb0181cfcc5ec0cebaa19f09d6cd4671
parent 2707d7a8286a35885d583c11d08e8bc2c0530219
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 15 Jun 2023 09:02:02 -0400
Straighten out interpret/compiling model
Have the "]" word handle the whole compile loop and remove the "compiling" check
from runword. It makes more sense this way. Also, this makes "]" and "xtcomp"
into the same word, removing the need for the latter.
Diffstat:
5 files changed, 51 insertions(+), 38 deletions(-)
diff --git a/fs/lib/wordtbl.fs b/fs/lib/wordtbl.fs
@@ -1,7 +1,7 @@
\ Word tables
: wordtbl ( n -- a ) create here swap CELLSZ * allot0 1 here c! ;
: w+ ( a -- a+4? ) CELLSZ + dup @ if drop then ;
-: :w ( a -- a+4? ) here xtcomp over ! w+ ;
+: :w ( a -- a+4? ) here [compile] ] over ! w+ ;
: 'w ( a -- a+4? ) ' over ! w+ ;
: wtbl@ ( tbl idx -- w ) CELLSZ * + @ ;
: wexec ( tbl idx -- ) wtbl@ execute ;
diff --git a/fs/xcomp/arm/rpi/kernel.fs b/fs/xcomp/arm/rpi/kernel.fs
@@ -34,8 +34,8 @@
: setrn0) ( -- operand ) bic) $f0000 i) ;
: values ( n -- ) for 0 value next ;
-20 values lblcurword lblsysdict lblhere lblnextmeta lblcompiling lblbootptr
- lblhbank lblmod lbl[rcnt] lblnextword
+21 values lblcurword lblsysdict lblhere lblnextmeta lblcompiling lblcompiling!
+ lblbootptr lblhbank lblmod lbl[rcnt] lblnextword
lblimmsplit lbladdnwr lbllitwr lblmemwr
lblcwrite lbldwrite lblmoverange lblwriterange
lblerrmsg lblmain
@@ -144,15 +144,11 @@ lblmod xaddr MOD
xcode [ ximm
mov) r0 rd) 0 i) ,)
-pc
+pc to lblcompiling!
lblcompiling r1 pc>reg,
str) r0 rd) r1 rn) ,)
exit,
-xcode ]
- mov) r0 rd) 1 i) ,)
- ( pc ) abs>rel b) ,)
-
pc to L1 \ set lblmod to 0
mov) r0 rd) 0 i) ,)
lblmod r1 pc>reg,
@@ -854,6 +850,19 @@ xcode compword ( str -- )
pushret, wcall, findmod popret,
wjmp, execute,
+xcode ]
+ pushret,
+ mov) r0 rd) 1 i) ,)
+ lblcompiling! abs>rel bl) ,)
+pc
+ wcall, word
+ wcall, compword
+ wcall, compiling
+ cmp) rTOP rn) 0 i) ,)
+ xdrop,
+ ( pc ) abs>rel b) nz) ,)
+ popret, exit,
+
pc lblcompiling le,
xcode runword ( str -- )
( pc ) r0 pc@>reg, ldr) r0 rdn) ,)
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -210,10 +210,9 @@ alias execute | immediate
: dip [compile] >r ['] _ ; immediate
\ Iteration
-: xtcomp [compile] ] begin word runword compiling not until ;
: ivar, ( off -- ) RSP) swap +) toptr@ execute ;
: i 4 ivar, ; immediate : j 8 ivar, ; immediate : k 12 ivar, ; immediate
-: :iterator doer immediate xtcomp does> ( w -- yieldjmp loopaddr )
+: :iterator doer immediate [compile] ] does> ( w -- yieldjmp loopaddr )
-16 rs+, RSP) !, LIT>W, RSP) @!,
[compile] ahead \ jump to yield
[compile] begin ( loop ) ;
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -584,18 +584,6 @@ xcode parse ( str -- n? f )
si 0 d) neg,
ret,
-xcode [ ximm
- lblcompiling m) 0 i) mov,
- ret,
-
-xcode ]
- lblcompiling m) 1 i) mov,
- ret,
-
-xcode ; ximm
- wcall, exit,
- wjmp, [
-
pc ," stack underflow"
xcode stack?
si PSTOP i) cmp,
@@ -658,9 +646,24 @@ xcode compword ( str -- )
wcall, findmod
wjmp, execute,
-xcode runword ( str -- ) pc w>e lblsysdict pc>addr !
+xcode [ ximm
+ lblcompiling m) 0 i) mov,
+ ret,
+
+xcode ]
+ lblcompiling m) 1 i) mov,
+pc
+ wcall, word
+ wcall, compword
lblcompiling m) -1 i) test,
- xwordlbl compword abs>rel jnz,
+ ( pc ) abs>rel jnz,
+ ret,
+
+xcode ; ximm
+ wcall, exit,
+ wjmp, [
+
+xcode runword ( str -- ) pc w>e lblsysdict pc>addr !
wcall, parse
bx ax mov, xdrop,
bx bx test,
diff --git a/posix/vm.c b/posix/vm.c
@@ -509,23 +509,25 @@ static void COMPWORD() {
}
}
static void RUNWORD() {
- if (vm.compiling) {
- COMPWORD();
- } else {
- PARSE();
- if (!ppop()) {
- ppush(CURWORD);
- ppush(sysdict());
- FIND();
- if (!vm.W) { WNF(); return; }
- FINDMOD();
- callword(ppop());
- STACKCHK();
- }
+ PARSE();
+ if (!ppop()) {
+ ppush(CURWORD);
+ ppush(sysdict());
+ FIND();
+ if (!vm.W) { WNF(); return; }
+ FINDMOD();
+ callword(ppop());
+ STACKCHK();
}
}
static void COMPILING() { ppush(vm.compiling); }
-static void STARTCOMP() { vm.compiling = 1; }
+static void STARTCOMP() {
+ vm.compiling = 1;
+ while (vm.compiling) {
+ WORD();
+ COMPWORD();
+ }
+}
static void STOPCOMP() { vm.compiling = 0; }
static void RSADDWR() {
dword n = ppop();