From 409a9f87e502f2a1ea8221a36d756a59ada6650e Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 27 Mar 2020 19:52:45 -0400 Subject: [PATCH] forth: replace "ROUTINE" with "JTBL" --- forth/core.fs | 6 ++-- forth/dictionary.txt | 3 -- forth/forth.asm | 72 +++++++++----------------------------------- forth/icore.fs | 4 +-- forth/z80a.fs | 11 ++++--- forth/z80c.fs | 10 +++--- 6 files changed, 30 insertions(+), 76 deletions(-) diff --git a/forth/core.fs b/forth/core.fs index 9d7988a..5018b59 100644 --- a/forth/core.fs +++ b/forth/core.fs @@ -2,7 +2,7 @@ : -^ SWAP - ; : [ INTERPRET 1 FLAGS ! ; IMMEDIATE : ] R> DROP ; -: LIT [ ROUTINE S LITN ] , ; +: LIT [ JTBL 26 + LITN ] , ; : LITS LIT SCPY ; : LIT< WORD LITS ; IMMEDIATE : _err LIT< word-not-found (print) ABORT ; @@ -50,7 +50,7 @@ : CREATE (entry) ( empty header with name ) - [ ROUTINE C LITN ] ( push cellWord addr ) + [ JTBL 3 + LITN ] ( push cellWord addr ) , ( write it ) ; : VARIABLE CREATE 2 ALLOT ; @@ -87,7 +87,7 @@ : (sysv) (entry) - [ ROUTINE Y LITN ] , + [ JTBL LITN ] , SYSVNXT @ , 2 SYSVNXT +! ; diff --git a/forth/dictionary.txt b/forth/dictionary.txt index d37dff8..7d5181b 100644 --- a/forth/dictionary.txt +++ b/forth/dictionary.txt @@ -52,9 +52,6 @@ DOES> -- See description at top of file IMMED? a -- f Checks whether wordref at a is immediate. IMMEDIATE -- Flag the latest defined word as immediate. LITN n -- Write number n as a literal. -ROUTINE x -- a Push the addr of the specified core routine - C=cellWord J=JUMPTBL V=nativeWord N=next S=LIT - 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 2eb3019..8f19996 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -115,8 +115,10 @@ ; change bootstrap binaries have to be adjusted because they rely on them. ; We're at 0 here jp forthMain -.fill 0x0e-$ +.fill 0x08-$ JUMPTBL: + jp sysvarWord + jp cellWord jp compiledWord jp pushRS jp popRS @@ -734,64 +736,11 @@ WR: ld (HERE), hl jp next - - .db "ROUTINE" - .dw $-WR - .db 7 -ROUTINE: - .dw compiledWord - .dw WORD - .dw .private - .dw EXIT - -.private: - .dw nativeWord - pop hl - call chkPS - ld a, (hl) - ld de, cellWord - cp 'C' - jr z, .end - ld de, JUMPTBL - cp 'J' - jr z, .end - ld de, JUMPTBL+9 - cp 'V' - jr z, .end - ld de, JUMPTBL+12 - cp 'N' - jr z, .end - ld de, sysvarWord - cp 'Y' - jr z, .end - ld de, doesWord - cp 'D' - jr z, .end - ld de, LIT - cp 'S' - jr z, .end - ld de, NUMBER - cp 'M' - jr z, .end - ld de, JUMPTBL+15 - cp 'P' - jr nz, .notgood - ; continue to end on match -.end: - ; is our slen 1? - inc hl - ld a, (hl) - or a - jr z, .good -.notgood: - ld de, 0 -.good: - push de - jp next +.fill 100 ; ( addr -- ) .db "EXECUTE" - .dw $-ROUTINE + .dw $-WR .db 7 ; STABLE ABI ; Offset: 0388 @@ -1049,13 +998,20 @@ PARSED: jp next -.fill 107 +.fill 96 + + .db "JTBL" + .dw $-PARSED + .db 4 +JTBL: + .dw sysvarWord + .dw JUMPTBL ; STABLE ABI (every sysvars) ; Offset: 05ca .out $ .db "HERE" - .dw $-PARSED + .dw $-JTBL .db 4 HERE_: ; Caution: conflicts with actual variable name .dw sysvarWord diff --git a/forth/icore.fs b/forth/icore.fs index ce69f11..da046f2 100644 --- a/forth/icore.fs +++ b/forth/icore.fs @@ -107,8 +107,8 @@ : X _c (entry) - ( JUMPTBL+0 == compiledWord ) - [ ROUTINE J LITN ] , + ( JTBL+6 == compiledWord ) + [ JTBL 6 + LITN ] , BEGIN WORD (find) diff --git a/forth/z80a.fs b/forth/z80a.fs index 3aec066..6b47b26 100644 --- a/forth/z80a.fs +++ b/forth/z80a.fs @@ -222,16 +222,19 @@ 0x10 OPJR DJNZe, ( Specials ) -: JPNEXT, [ ROUTINE N LITN ] JPnn, ; +( JTBL+18 == next ) +: JPNEXT, [ JTBL 18 + LITN ] JPnn, ; : CODE - ( same as CREATE, but with ROUTINE V ) + ( same as CREATE, but with native word ) (entry) - [ ROUTINE V LITN ] , + ( JTBL+15 == next ) + [ JTBL 15 + LITN ] , ; : ;CODE JPNEXT, ; ( Routines ) -: chkPS, [ ROUTINE P LITN ] CALLnn, ; +( JTBL+21 == next ) +: chkPS, [ JTBL 21 + LITN ] CALLnn, ; diff --git a/forth/z80c.fs b/forth/z80c.fs index f45f769..860c40c 100644 --- a/forth/z80c.fs +++ b/forth/z80c.fs @@ -12,8 +12,6 @@ any word from our high level Forth, as long as it doesn't spit word references. - ROUTINE stuff is fine. It's not supposed to change. - These restrictions are temporary, I'll figure something out so that we can end up fully bootstrap Forth from within itself. @@ -220,12 +218,12 @@ CODE J CODE >R HL POPqq, chkPS, - ( JUMPTBL+3 == pushRS ) - ROUTINE J 3 + CALLnn, + ( JTBL+9 == pushRS ) + JTBL 9 + CALLnn, ;CODE CODE R> - ( JUMPTBL+6 == popRS ) - ROUTINE J 6 + CALLnn, + ( JTBL+12 == popRS ) + JTBL 12 + CALLnn, HL PUSHqq, ;CODE