From 3a08fa7e7454928b66025f249ea76ea2af5dc441 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 24 Mar 2020 23:02:06 -0400 Subject: [PATCH] forth: add a stable ABI --- emul/forth/z80c.bin | Bin 144 -> 144 bytes forth/dictionary.txt | 2 +- forth/forth.asm | 20 +++++++++++--------- forth/z80c.fs | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index 227d7c54eaaf4bb19f1d5b36b0c316034e112b84..04a30e5549a578505aff6f991d08655a8ea409eb 100644 GIT binary patch literal 144 zcmWIY4`BcTb_RxRj1Mm!JS)p^_36>WQVd2ep#eZ~QHVHL`07)TxPO>y5M2D=--ke{ vzfX@|eF`K%(!t@5Kz%Y$Wa~X|XLIZ%}q7ZSg@YSavasM#aAh`I!zYl>@ vf1e(``V>fjq=Um9f%;^i#(||_a*lp3Agd(dMpiG)uUe80GBq9oBp4U~Fk?OA diff --git a/forth/dictionary.txt b/forth/dictionary.txt index 9001547..d27f351 100644 --- a/forth/dictionary.txt +++ b/forth/dictionary.txt @@ -55,7 +55,7 @@ LITN n -- Write number n as a literal. [LITN] n -- *I* Immediate version of LITN. ROUTINE x -- a Push the addr of the specified core routine C=cellWord L=compiledWord V=nativeWord N=next S=LIT - N=NUMBER Y=sysvarWord D=doesWord + M=NUMBER Y=sysvarWord D=doesWord VARIABLE c -- Creates cell x with 2 bytes allocation. Compilation vs meta-compilation. When you compile a word with "[COMPILE] foo", diff --git a/forth/forth.asm b/forth/forth.asm index 53c53be..c4e1952 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -108,6 +108,14 @@ ; At the end of every compiledWord is an EXIT. This pops RS, sets IP to it, and ; continues. +; *** Stable ABI *** +; Those jumps below are supposed to stay at these offsets, always. If they +; change bootstrap binaries have to be adjusted because they rely on them. +.fill 0x1a-$ +JUMPTBL: + jp next + jp chkPS + ; *** Code *** forthMain: ; STACK OVERFLOW PROTECTION: @@ -185,12 +193,6 @@ INTERPRET: .db 30 ; infinite loop -; Oops, I forgot to create a stable ABI before starting to rely on stability... -; I'll fix this soon, but for now, I need to offset a recent simplification -; I've made in INTERPRET above. If we don't, z80c.bin doesn't refer to proper -; routine addresses... -.fill 14 - ; *** Collapse OS lib copy *** ; In the process of Forth-ifying Collapse OS, apps will be slowly rewritten to ; Forth and the concept of ASM libs will become obsolete. To facilitate this @@ -815,7 +817,7 @@ ROUTINE: ld de, nativeWord cp 'V' jr z, .end - ld de, next + ld de, JUMPTBL cp 'N' jr z, .end ld de, sysvarWord @@ -828,9 +830,9 @@ ROUTINE: cp 'S' jr z, .end ld de, NUMBER - cp 'N' + cp 'M' jr z, .end - ld de, chkPS + ld de, JUMPTBL+3 cp 'P' jr nz, .notgood ; continue to end on match diff --git a/forth/z80c.fs b/forth/z80c.fs index 5770e07..2c55819 100644 --- a/forth/z80c.fs +++ b/forth/z80c.fs @@ -34,7 +34,7 @@ CODE ROT CODE 2DUP HL POPqq, ( B ) DE POPqq, ( A ) - ROUTINE P CALLnn, + chkPS, DE PUSHqq, ( A ) HL PUSHqq, ( B ) DE PUSHqq, ( A ) @@ -48,7 +48,7 @@ CODE 2OVER DE POPqq, ( C ) BC POPqq, ( B ) IY POPqq, ( A ) - ROUTINE P CALLnn, + chkPS, IY PUSHqq, ( A ) BC PUSHqq, ( B ) DE PUSHqq, ( C ) @@ -64,7 +64,7 @@ CODE 2SWAP DE POPqq, ( C ) BC POPqq, ( B ) IY POPqq, ( A ) - ROUTINE P CALLnn, + chkPS, DE PUSHqq, ( C ) HL PUSHqq, ( D ) IY PUSHqq, ( A )