Browse Source

forth: Forth-ify ";"!!!

Ain't that not self-bootstrapping enough to your taste? Whoa, I'm
getting dizzy...
pull/95/head
Virgil Dupras 4 years ago
parent
commit
1e7e696e4a
3 changed files with 36 additions and 16 deletions
  1. BIN
      emul/forth/z80c.bin
  2. +5
    -16
      forth/forth.asm
  3. +31
    -0
      forth/icore.fs

BIN
emul/forth/z80c.bin View File


+ 5
- 16
forth/forth.asm View File

@@ -839,22 +839,9 @@ EXECUTE:
jp (hl) ; go!


.db ";"
.dw $-EXECUTE
.db 0x81 ; IMMEDIATE
ENDDEF:
.dw compiledWord
.dw NUMBER
.dw EXIT
.dw WR
.dw R2P ; exit COMPILE
.dw DROP
.dw R2P ; exit DEFINE
.dw DROP
.dw EXIT

.fill 22
.db ":"
.dw $-ENDDEF
.dw $-EXECUTE
.db 0x81 ; IMMEDIATE
DEFINE:
.dw compiledWord
@@ -1269,6 +1256,7 @@ FETCH:
.db "DROP"
.dw $-FETCH
.db 4
; STABLE ABI
DROP:
.dw nativeWord
pop hl
@@ -1485,5 +1473,6 @@ BBR:
; To allow dict binaries to "hook themselves up", we always end such binary
; with a dummy, *empty* entry. Therefore, we can have a predictable place for
; getting a prev label.
.db "_bend"
.dw $-BBR
.db 0
.db 5

+ 31
- 0
forth/icore.fs View File

@@ -19,6 +19,37 @@
by the full interpreter.
)

( When referencing words from native defs or this very unit,
use this compiling word, which subtract the proper offset
from the compiled word. That proper offset is:
1. Take ROT-header addr, the first native def.
2. Subtract _bend, boot's last word.
3. That will give us the offset to subtract to get the addr
of our word at runtime.

This means, of course, that any word compiling a _c word
can't be executed immediately.
)

: _c
['] ROT
6 - ( header )
['] _bend
- ( our offset )
' ( get word )
-^ ( apply offset )
, ( write! )
; IMMEDIATE

: X ( can't have its real name now )
['] EXIT ,
R> DROP ( exit COMPILE )
R> DROP ( exit : )
; IMMEDIATE

( Give ";" its real name )
';' CURRENT @ 4 - C!

: INTERPRET
BEGIN
WORD


Loading…
Cancel
Save