mirror of
https://github.com/nineties/planckforth
synced 2025-01-14 08:01:27 +01:00
Implement source-buffer
This commit is contained in:
parent
af8fc4f57f
commit
de1a7cfc1e
1 changed files with 32 additions and 7 deletions
39
bootstrap.fs
39
bootstrap.fs
|
@ -1786,6 +1786,13 @@ stdin_ push-inputstream
|
||||||
|
|
||||||
\ Replacing parser functions using input stream.
|
\ Replacing parser functions using input stream.
|
||||||
|
|
||||||
|
variable source-buffer BUFSIZE allot drop
|
||||||
|
BUFSIZE constant source-buffer-size
|
||||||
|
variable source-buffer-pos source-buffer source-buffer-pos !
|
||||||
|
variable source-buffer-end source-buffer source-buffer-end !
|
||||||
|
|
||||||
|
: increment-lineno ( -- ) 1 inputstreams @ input>lineno +! ;
|
||||||
|
|
||||||
\ Throw UNEXPECTED-EOF-ERROR at EOF
|
\ Throw UNEXPECTED-EOF-ERROR at EOF
|
||||||
:noname ( -- c )
|
:noname ( -- c )
|
||||||
key dup EOF = if drop UNEXPECTED-EOF-ERROR throw then
|
key dup EOF = if drop UNEXPECTED-EOF-ERROR throw then
|
||||||
|
@ -1795,12 +1802,30 @@ stdin_ push-inputstream
|
||||||
: \ begin key! '\n' = until ; immediate
|
: \ begin key! '\n' = until ; immediate
|
||||||
|
|
||||||
\ New version of 'key'.
|
\ New version of 'key'.
|
||||||
:noname ( -- c )
|
: new-key ( -- c )
|
||||||
inputstreams @ input>file @ key-file dup '\n' = if
|
source-buffer-pos @ source-buffer-end @ = if
|
||||||
\ increment line count
|
\ the buffer is empty
|
||||||
1 inputstreams @ input>lineno +!
|
source-buffer source-buffer-pos !
|
||||||
|
source-buffer source-buffer-end !
|
||||||
|
|
||||||
|
source-buffer BUFSIZE inputstreams @ input>file @ read-line throw
|
||||||
|
if
|
||||||
|
\ reached end of line
|
||||||
|
dup 0= if
|
||||||
|
drop '\n' exit \ empty line
|
||||||
|
then
|
||||||
|
source-buffer-end +!
|
||||||
|
else
|
||||||
|
\ reached EOF
|
||||||
|
dup 0= if
|
||||||
|
drop EOF exit
|
||||||
|
then
|
||||||
|
source-buffer-end +!
|
||||||
|
then
|
||||||
then
|
then
|
||||||
; &key !
|
source-buffer-pos @ c@
|
||||||
|
1 source-buffer-pos +!
|
||||||
|
;
|
||||||
|
|
||||||
\ Read a word from input stream, return address of the string
|
\ Read a word from input stream, return address of the string
|
||||||
\ and error-code.
|
\ and error-code.
|
||||||
|
@ -1847,14 +1872,13 @@ stdin_ push-inputstream
|
||||||
]
|
]
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
( === 4th Stage Interpreter === )
|
( === 4th Stage Interpreter === )
|
||||||
|
|
||||||
-56 s" Bye" def-error QUIT
|
-56 s" Bye" def-error QUIT
|
||||||
|
|
||||||
: interpret-inner
|
: interpret-inner
|
||||||
begin
|
begin
|
||||||
word \ read name from input
|
word \ read name from input
|
||||||
|
|
||||||
\ EOF at this point is not an error
|
\ EOF at this point is not an error
|
||||||
UNEXPECTED-EOF-ERROR = if QUIT throw then
|
UNEXPECTED-EOF-ERROR = if QUIT throw then
|
||||||
|
@ -1922,6 +1946,7 @@ stdin_ push-inputstream
|
||||||
|
|
||||||
:noname
|
:noname
|
||||||
rp0 rp! \ drop 3rd stage
|
rp0 rp! \ drop 3rd stage
|
||||||
|
['] new-key &key !
|
||||||
|
|
||||||
['] interpret-outer catch bye
|
['] interpret-outer catch bye
|
||||||
; execute
|
; execute
|
||||||
|
|
Loading…
Reference in a new issue