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.
; We're at 0 here
jp forthMain
.fill 0x11-$
.fill 0x0e-$
JUMPTBL:
jp compiledWord
jp pushRS
jp popRS
jp nativeWord
@ -768,10 +769,10 @@ ROUTINE:
ld de, JUMPTBL
cp 'J'
jr z, .end
ld de, JUMPTBL+6
ld de, JUMPTBL+9
cp 'V'
jr z, .end
ld de, JUMPTBL+9
ld de, JUMPTBL+12
cp 'N'
jr z, .end
ld de, sysvarWord
@ -786,7 +787,7 @@ ROUTINE:
ld de, NUMBER
cp 'M'
jr z, .end
ld de, JUMPTBL+12
ld de, JUMPTBL+15
cp 'P'
jr nz, .notgood
; continue to end on match
@ -822,52 +823,10 @@ EXECUTE:
jp (hl) ; go!
.fill 22
.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
.fill 77
.db "DOES>"
.dw $-DEFINE
.dw $-EXECUTE
.db 5
DOES:
.dw nativeWord
@ -1104,17 +1063,7 @@ PARSED:
jp next
.fill 41
; Indirect parse caller. Reads PARSEPTR and calls
PARSEI:
.dw compiledWord
.dw PARSEPTR_
.dw FETCH
.dw EXECUTE
.dw EXIT
.fill 51
; Spit name (in (HL)) + prev in (HERE) and adjust (HERE) and (CURRENT)
; HL points to new (HERE)

View File

@ -81,13 +81,30 @@
AGAIN
;
( ; has to be defined last because it can't be executed now )
: X ( can't have its real name now )
( : and ; have to be defined last because it can't be
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 ,
_c R> DROP ( exit COMPILE )
_c R> DROP ( exit : )
; IMMEDIATE
( Give ";" its real name )
';' CURRENT @ 4 - C!
( Give ":" and ";" their real name )
':' ' X 4 - C!
';' ' Y 4 - C!

View File

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