mirror of
https://github.com/hsoft/collapseos.git
synced 2025-03-31 17:08:40 +11:00
forth: Forth-ify "INTERPRET"!!!
Now we're seriously getting into real boostrapping territory...
This commit is contained in:
parent
cb3e6469b8
commit
dad0081123
@ -103,7 +103,7 @@ updatebootstrap: $(ZASMBIN)
|
|||||||
# words and they write to HERE at initialization.
|
# words and they write to HERE at initialization.
|
||||||
.PHONY: fbootstrap
|
.PHONY: fbootstrap
|
||||||
fbootstrap: forth/stage2
|
fbootstrap: forth/stage2
|
||||||
cat ../forth/dummy.fs ../forth/z80c.fs forth/emul.fs ../forth/dummy.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null
|
cat ../forth/dummy.fs ../forth/z80c.fs forth/emul.fs ../forth/icore.fs ../forth/dummy.fs | ./forth/stage2 | tee forth/z80c.bin > /dev/null
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
Binary file not shown.
@ -10,6 +10,14 @@
|
|||||||
; self-hosts in a more compact manner. File include is a big part of the
|
; self-hosts in a more compact manner. File include is a big part of the
|
||||||
; complexity in zasm. If we can get rid of it, we'll be more compact.
|
; complexity in zasm. If we can get rid of it, we'll be more compact.
|
||||||
|
|
||||||
|
; *** ABI STABILITY ***
|
||||||
|
;
|
||||||
|
; This unit needs to have some of its entry points stay at a stable offset.
|
||||||
|
; These have a comment over them indicating the expected offset. These should
|
||||||
|
; not move until the Grand Bootstrapping operation has been completed.
|
||||||
|
;
|
||||||
|
; When you see random ".fill" here and there, it's to ensure that stability.
|
||||||
|
|
||||||
; *** Defines ***
|
; *** Defines ***
|
||||||
; GETC: address of a GetC routine
|
; GETC: address of a GetC routine
|
||||||
; PUTC: address of a PutC routine
|
; PUTC: address of a PutC routine
|
||||||
@ -110,6 +118,10 @@ JUMPTBL:
|
|||||||
jp nativeWord
|
jp nativeWord
|
||||||
jp next
|
jp next
|
||||||
jp chkPS
|
jp chkPS
|
||||||
|
NUMBER:
|
||||||
|
.dw numberWord
|
||||||
|
LIT:
|
||||||
|
.dw litWord
|
||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
forthMain:
|
forthMain:
|
||||||
@ -175,31 +187,13 @@ BEGIN:
|
|||||||
|
|
||||||
INTERPRET:
|
INTERPRET:
|
||||||
.dw compiledWord
|
.dw compiledWord
|
||||||
; BBR mark
|
.dw LIT
|
||||||
.dw WORD
|
.db "INTERPRET", 0
|
||||||
.dw FIND_
|
.dw FIND_
|
||||||
.dw CSKIP
|
.dw DROP
|
||||||
.dw FBR
|
|
||||||
.db 22
|
|
||||||
; It's a word, execute it
|
|
||||||
; For now, we only have one flag, let's take advantage of
|
|
||||||
; this to keep code simple.
|
|
||||||
.dw NUMBER ; Bit 0 on
|
|
||||||
.dw 1
|
|
||||||
.dw FLAGS_
|
|
||||||
.dw STORE
|
|
||||||
.dw EXECUTE
|
.dw EXECUTE
|
||||||
.dw NUMBER ; Bit 0 off
|
|
||||||
.dw 0
|
.fill 31
|
||||||
.dw FLAGS_
|
|
||||||
.dw STORE
|
|
||||||
.dw BBR
|
|
||||||
.db 29
|
|
||||||
; FBR mark, try number
|
|
||||||
.dw PARSEI
|
|
||||||
.dw BBR
|
|
||||||
.db 34
|
|
||||||
; infinite loop
|
|
||||||
|
|
||||||
; *** Collapse OS lib copy ***
|
; *** Collapse OS lib copy ***
|
||||||
; In the process of Forth-ifying Collapse OS, apps will be slowly rewritten to
|
; In the process of Forth-ifying Collapse OS, apps will be slowly rewritten to
|
||||||
@ -625,9 +619,6 @@ numberWord:
|
|||||||
push de
|
push de
|
||||||
jp next
|
jp next
|
||||||
|
|
||||||
NUMBER:
|
|
||||||
.dw numberWord
|
|
||||||
|
|
||||||
; Similarly to numberWord, this is not a real word, but a string literal.
|
; Similarly to numberWord, this is not a real word, but a string literal.
|
||||||
; Instead of being followed by a 2 bytes number, it's followed by a
|
; Instead of being followed by a 2 bytes number, it's followed by a
|
||||||
; null-terminated string. When called, puts the string's address on PS
|
; null-terminated string. When called, puts the string's address on PS
|
||||||
@ -639,9 +630,6 @@ litWord:
|
|||||||
ld (IP), hl
|
ld (IP), hl
|
||||||
jp next
|
jp next
|
||||||
|
|
||||||
LIT:
|
|
||||||
.dw litWord
|
|
||||||
|
|
||||||
; Pop previous IP from Return stack and execute it.
|
; Pop previous IP from Return stack and execute it.
|
||||||
; ( R:I -- )
|
; ( R:I -- )
|
||||||
.db "EXIT"
|
.db "EXIT"
|
||||||
@ -835,6 +823,9 @@ ROUTINE:
|
|||||||
.db "EXECUTE"
|
.db "EXECUTE"
|
||||||
.dw $-ROUTINE
|
.dw $-ROUTINE
|
||||||
.db 7
|
.db 7
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 0388
|
||||||
|
.out $
|
||||||
EXECUTE:
|
EXECUTE:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
pop iy ; is a wordref
|
pop iy ; is a wordref
|
||||||
@ -983,6 +974,9 @@ SCPY:
|
|||||||
.db "(find)"
|
.db "(find)"
|
||||||
.dw $-SCPY
|
.dw $-SCPY
|
||||||
.db 6
|
.db 6
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 047c
|
||||||
|
.out $
|
||||||
FIND_:
|
FIND_:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
pop hl
|
pop hl
|
||||||
@ -1070,6 +1064,9 @@ TOWORD:
|
|||||||
.db "WORD"
|
.db "WORD"
|
||||||
.dw $-TOWORD
|
.dw $-TOWORD
|
||||||
.db 4
|
.db 4
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 04f7
|
||||||
|
.out $
|
||||||
WORD:
|
WORD:
|
||||||
.dw compiledWord
|
.dw compiledWord
|
||||||
.dw NUMBER ; ( a )
|
.dw NUMBER ; ( a )
|
||||||
@ -1202,6 +1199,9 @@ ENTRYHEAD:
|
|||||||
jp next
|
jp next
|
||||||
|
|
||||||
|
|
||||||
|
; STABLE ABI (every sysvars)
|
||||||
|
; Offset: 05ca
|
||||||
|
.out $
|
||||||
.db "HERE"
|
.db "HERE"
|
||||||
.dw $-ENTRYHEAD
|
.dw $-ENTRYHEAD
|
||||||
.db 4
|
.db 4
|
||||||
@ -1241,6 +1241,9 @@ SYSVNXT_:
|
|||||||
.db "!"
|
.db "!"
|
||||||
.dw $-SYSVNXT_
|
.dw $-SYSVNXT_
|
||||||
.db 1
|
.db 1
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 0610
|
||||||
|
.out $
|
||||||
STORE:
|
STORE:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
pop iy
|
pop iy
|
||||||
@ -1390,6 +1393,9 @@ CMP:
|
|||||||
.db "SKIP?"
|
.db "SKIP?"
|
||||||
.dw $-CMP
|
.dw $-CMP
|
||||||
.db 5
|
.db 5
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 06ee
|
||||||
|
.out $
|
||||||
CSKIP:
|
CSKIP:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
pop hl
|
pop hl
|
||||||
@ -1447,6 +1453,9 @@ CSKIP:
|
|||||||
.db "(fbr)"
|
.db "(fbr)"
|
||||||
.dw $-CSKIP
|
.dw $-CSKIP
|
||||||
.db 5
|
.db 5
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 073e
|
||||||
|
.out $
|
||||||
FBR:
|
FBR:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
push de
|
push de
|
||||||
@ -1460,6 +1469,9 @@ FBR:
|
|||||||
.db "(bbr)"
|
.db "(bbr)"
|
||||||
.dw $-FBR
|
.dw $-FBR
|
||||||
.db 5
|
.db 5
|
||||||
|
; STABLE ABI
|
||||||
|
; Offset: 0757
|
||||||
|
.out $
|
||||||
BBR:
|
BBR:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
ld hl, (IP)
|
ld hl, (IP)
|
||||||
|
34
forth/icore.fs
Normal file
34
forth/icore.fs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
( Inner core. This unit represents core definitions that
|
||||||
|
happen right after native definitions. Before core.fs.
|
||||||
|
|
||||||
|
Unlike core.fs and its followers, this unit isn't self-
|
||||||
|
sustained. Like native defs it uses the machinery of a
|
||||||
|
full Forth interpreter, notably for flow structures.
|
||||||
|
|
||||||
|
Because of that, it has to obey specific rules:
|
||||||
|
|
||||||
|
1. It cannot compile a word from higher layers. Using
|
||||||
|
immediates is fine though.
|
||||||
|
2. If it references a word from this unit or from native
|
||||||
|
definitions, these need to be properly offsetted
|
||||||
|
because their offset at compile time are not the same
|
||||||
|
as their runtime offsets.
|
||||||
|
3. Anything they refer to in the boot binary has to be
|
||||||
|
properly stabilized.
|
||||||
|
4. Make sure that the words you compile are not overridden
|
||||||
|
by the full interpreter.
|
||||||
|
)
|
||||||
|
|
||||||
|
: INTERPRET
|
||||||
|
BEGIN
|
||||||
|
WORD
|
||||||
|
(find)
|
||||||
|
IF
|
||||||
|
1 FLAGS !
|
||||||
|
EXECUTE
|
||||||
|
0 FLAGS !
|
||||||
|
ELSE
|
||||||
|
(parse*) @ EXECUTE
|
||||||
|
THEN
|
||||||
|
AGAIN
|
||||||
|
;
|
Loading…
Reference in New Issue
Block a user