forth: make readline skip prompt when appropriate

This commit is contained in:
Virgil Dupras 2020-03-21 14:59:12 -04:00
parent b47a3ee234
commit 9791c0957d
2 changed files with 32 additions and 6 deletions

View File

@ -53,6 +53,9 @@
.equ HERE @+2
; Interpreter pointer. See Execution model comment below.
.equ IP @+2
; Global flags
; Bit 0: whether the interpreter is executing a word (as opposed to parsing)
.equ FLAGS @+2
; Pointer to the system's number parsing function. It points to then entry that
; had the "(parse)" name at startup. During stage0, it's out builtin PARSE,
; but at stage1, it becomes "(parse)" from core.fs. It can also be changed at
@ -170,15 +173,29 @@ INTERPRET:
.dw FIND_
.dw CSKIP
.dw FBR
.db 6
.db 34
; It's a word, execute it
.dw FLAGS_
.dw FETCH
.dw NUMBER
.dw 0x0001 ; Bit 0 on
.dw OR
.dw FLAGS_
.dw STORE
.dw EXECUTE
.dw FLAGS_
.dw FETCH
.dw NUMBER
.dw 0xfffe ; Bit 0 off
.dw AND
.dw FLAGS_
.dw STORE
.dw BBR
.db 13
.db 41
; FBR mark, try number
.dw PARSEI
.dw BBR
.db 18
.db 46
; infinite loop
; *** Collapse OS lib copy ***
@ -1334,10 +1351,18 @@ WORDBUF_:
.dw sysvarWord
.dw WORDBUF
.db "FLAGS"
.fill 2
.dw WORDBUF_
.db 0
FLAGS_:
.dw sysvarWord
.dw FLAGS
; ( n a -- )
.db "!"
.fill 6
.dw WORDBUF_
.dw FLAGS_
.db 0
STORE:
.dw nativeWord

View File

@ -61,8 +61,9 @@
( Read one line in input buffer and make IN> point to it )
: (rdln)
( TODO: don't emit prompt in middle of defs and comments )
LF '>' EMIT SPC
( Should we prompt? if we're executing a word, FLAGS bit
0, then we shouldn't. )
FLAGS @ 0x1 AND NOT IF LF '>' EMIT SPC THEN
(infl)
BEGIN (rdlnc) NOT UNTIL
IN( @ IN> !