mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-08 23:58:06 +11:00
03e529b762
This scheme of "when we handle line-by-line, compile one word at a time then execute" so that we could allow words like "CREATE" to call "readword" before continuing was a bad scheme. It made things like branching outside of a colon definition impossible. This commit implement a new "litWord". When an undefined word is encountered at compile time, it is included as-is in a string literal word. It is at run time that we decide what to do with it.
46 lines
1.3 KiB
NASM
46 lines
1.3 KiB
NASM
; *** Const ***
|
|
; Base of the Return Stack
|
|
.equ RS_ADDR 0xf000
|
|
; Number of bytes we keep as a padding between HERE and the scratchpad
|
|
.equ PADDING 0x20
|
|
; Max length of dict entry names
|
|
.equ NAMELEN 8
|
|
; Offset of the code link relative to the beginning of the word
|
|
.equ CODELINK_OFFSET 10
|
|
|
|
; *** Variables ***
|
|
.equ INITIAL_SP FORTH_RAMSTART
|
|
.equ CURRENT @+2
|
|
.equ HERE @+2
|
|
.equ INPUTPOS @+2
|
|
; Buffer where we compile the current input line. Same size as STDIO_BUFSIZE.
|
|
.equ COMPBUF @+2
|
|
.equ FORTH_RAMEND @+0x40
|
|
|
|
; *** Code ***
|
|
forthMain:
|
|
; STACK OVERFLOW PROTECTION:
|
|
; To avoid having to check for stack underflow after each pop operation
|
|
; (which can end up being prohibitive in terms of costs), we give
|
|
; ourselves a nice 6 bytes buffer. 6 bytes because we seldom have words
|
|
; requiring more than 3 items from the stack. Then, at each "exit" call
|
|
; we check for stack underflow.
|
|
push af \ push af \ push af
|
|
ld (INITIAL_SP), sp
|
|
ld hl, CONSTANT ; last entry in hardcoded dict
|
|
ld (CURRENT), hl
|
|
ld hl, FORTH_RAMEND
|
|
ld (HERE), hl
|
|
forthRdLine:
|
|
ld hl, msgOk
|
|
call printstr
|
|
call printcrlf
|
|
call stdioReadLine
|
|
ld (INPUTPOS), hl
|
|
forthInterpret:
|
|
ld ix, RS_ADDR-2 ; -2 because we inc-before-push
|
|
ld iy, INTERPRET+CODELINK_OFFSET
|
|
jp executeCodeLink
|
|
msgOk:
|
|
.db " ok", 0
|