forth: Forth-ify ":"!!!

Lifting ourselves by the bootstraps!
This commit is contained in:
Virgil Dupras 2020-03-27 16:16:57 -04:00
parent 7967c654e0
commit 799ea72974
4 changed files with 34 additions and 68 deletions

Binary file not shown.

View File

@ -115,8 +115,9 @@
; change bootstrap binaries have to be adjusted because they rely on them. ; change bootstrap binaries have to be adjusted because they rely on them.
; We're at 0 here ; We're at 0 here
jp forthMain jp forthMain
.fill 0x11-$ .fill 0x0e-$
JUMPTBL: JUMPTBL:
jp compiledWord
jp pushRS jp pushRS
jp popRS jp popRS
jp nativeWord jp nativeWord
@ -768,10 +769,10 @@ ROUTINE:
ld de, JUMPTBL ld de, JUMPTBL
cp 'J' cp 'J'
jr z, .end jr z, .end
ld de, JUMPTBL+6 ld de, JUMPTBL+9
cp 'V' cp 'V'
jr z, .end jr z, .end
ld de, JUMPTBL+9 ld de, JUMPTBL+12
cp 'N' cp 'N'
jr z, .end jr z, .end
ld de, sysvarWord ld de, sysvarWord
@ -786,7 +787,7 @@ ROUTINE:
ld de, NUMBER ld de, NUMBER
cp 'M' cp 'M'
jr z, .end jr z, .end
ld de, JUMPTBL+12 ld de, JUMPTBL+15
cp 'P' cp 'P'
jr nz, .notgood jr nz, .notgood
; continue to end on match ; continue to end on match
@ -822,52 +823,10 @@ EXECUTE:
jp (hl) ; go! jp (hl) ; go!
.fill 22 .fill 77
.db ":"
.dw $-EXECUTE
.db 0x81 ; IMMEDIATE
DEFINE:
.dw compiledWord
.dw ENTRYHEAD
.dw NUMBER
.dw compiledWord
.dw WR
; BBR branch mark
.dw .compile
.dw BBR
.db 4
; no need for EXIT, ENDDEF takes care of taking us out
.compile:
.dw compiledWord
.dw WORD
.dw FIND_
.dw NOT
.dw CSKIP
.dw FBR
.db 7
; Maybe number
.dw PARSEI
.dw LITN
.dw EXIT
; FBR mark
.dw DUP
.dw ISIMMED
.dw CSKIP
.dw FBR
.db 5
; is immediate. just execute.
.dw EXECUTE
.dw EXIT
; FBR mark
; just a word, write
.dw WR
.dw EXIT
.db "DOES>" .db "DOES>"
.dw $-DEFINE .dw $-EXECUTE
.db 5 .db 5
DOES: DOES:
.dw nativeWord .dw nativeWord
@ -1104,17 +1063,7 @@ PARSED:
jp next jp next
.fill 41 .fill 51
; Indirect parse caller. Reads PARSEPTR and calls
PARSEI:
.dw compiledWord
.dw PARSEPTR_
.dw FETCH
.dw EXECUTE
.dw EXIT
; Spit name (in (HL)) + prev in (HERE) and adjust (HERE) and (CURRENT) ; Spit name (in (HL)) + prev in (HERE) and adjust (HERE) and (CURRENT)
; HL points to new (HERE) ; HL points to new (HERE)

View File

@ -81,13 +81,30 @@
AGAIN AGAIN
; ;
( ; has to be defined last because it can't be executed now ) ( : and ; have to be defined last because it can't be
: X ( can't have its real name now ) executed now also, they can't have their real name
right away )
: X
(entry)
( JUMPTBL+0 == compiledWord )
[ ROUTINE J LITN ] ,
BEGIN
WORD
(find)
( is word )
IF DUP IMMED? IF EXECUTE ELSE , THEN
( maybe number )
ELSE (parse*) @ EXECUTE LITN THEN
AGAIN
; IMMEDIATE
: Y
['] EXIT , ['] EXIT ,
_c R> DROP ( exit COMPILE )
_c R> DROP ( exit : ) _c R> DROP ( exit : )
; IMMEDIATE ; IMMEDIATE
( Give ";" its real name ) ( Give ":" and ";" their real name )
';' CURRENT @ 4 - C! ':' ' X 4 - C!
';' ' Y 4 - C!

View File

@ -220,12 +220,12 @@ CODE J
CODE >R CODE >R
HL POPqq, HL POPqq,
chkPS, chkPS,
( JUMPTBL+0 == pushRS ) ( JUMPTBL+3 == pushRS )
ROUTINE J CALLnn, ROUTINE J 3 + CALLnn,
;CODE ;CODE
CODE R> CODE R>
( JUMPTBL+3 == popRS ) ( JUMPTBL+6 == popRS )
ROUTINE J 3 + CALLnn, ROUTINE J 6 + CALLnn,
HL PUSHqq, HL PUSHqq,
;CODE ;CODE