Re: Does EXPECT store a zero at the end of the text?
Posted: Thu Jan 11, 2024 11:52 am
Here is Uniforths definintions for compiling if someone wants to see if they can follow them.
The problem I have with all this is, if one enters a long line of up to 80 characters, like QUERY limits one to, then the next input line is shorter, what prevents INTERPRET from re-compiling the words that come after the shorter input as it looks like the previous, longer definitions are still in the TIB?
INTERPRET also doesn't check for SPAN or #TIB for the limit.
ADDENDUM: ok, as I was uploading this, I noticed ?STACK is in INTERPRET. I think the way ?STACK would work is if -FIND left the stack empty as it was searching for words, then it would ABORT.
I put a note in #FIND that it calls NEXT. But if #FIND calls NEXT, then there would be no need for ?STACK.
I still have to disassemble #FIND to see what it sees as an end-of-line marker that it knows to leave the stack empty. Without a zero at the end of the input, it should theoretically keep compiling old word definitions.
The problem I have with all this is, if one enters a long line of up to 80 characters, like QUERY limits one to, then the next input line is shorter, what prevents INTERPRET from re-compiling the words that come after the shorter input as it looks like the previous, longer definitions are still in the TIB?
INTERPRET also doesn't check for SPAN or #TIB for the limit.
ADDENDUM: ok, as I was uploading this, I noticed ?STACK is in INTERPRET. I think the way ?STACK would work is if -FIND left the stack empty as it was searching for words, then it would ABORT.
I put a note in #FIND that it calls NEXT. But if #FIND calls NEXT, then there would be no need for ?STACK.
I still have to disassemble #FIND to see what it sees as an end-of-line marker that it knows to leave the stack empty. Without a zero at the end of the input, it should theoretically keep compiling old word definitions.
Code: Select all
: QUIT 0 BLK ! [ BEGIN RP! CR QUERY INTERPRET STATE @ O= IF ." OK" REPEAT THEN ;
: QUERY TIB @ 80 EXPECT 0 >IN ! ;
: EXPECT ( addr len -- ) OVER + DUP 1 - SPAN ! OVER
DO KEY DUP 16 +ORIGIN C@ = OVER 17 +ORIGIN C@ = OR
( 16 + ORIGIN = 8, 17 + ORIGIN = 7F )
IF DROP DUP I = R> 2 - OVER - >R
IF 7
ELSE 8 DUP EMIT BL EMIT
THEN
ELSE
DUP 15 = ( ctrl-u) IF DROP R> DROP DUP 1 - R@ - >R
5E EMIT 55 EMIT D EMIT A
ELSE
DUP D = IF DROP BL EMIT I SPAN ! LEAVE
ELSE DUP
THEN I C!
THEN
THEN
EMIT LOOP
SPAN @ SWAP - SPAN ! ;
: WORD BLK @ IF BLK @ BLOCK ELSE TIB @ THEN >IN @ + SWAP ENCLOSE
HERE 2+ 22 BLANKS >IN +! OVER - >R R@ HERE 2+ C! + HERE 3 + R>
CMOVE HERE 2+ ;
: INTERPRET
BEGIN
-FIND IF
STATE @ < IF ,
ELSE EXECUTE ?STACK
ELSE
HERE 2+ NUMBER DPL @ 1+ IF
PRECIS @ 2 = IF FLITERAL
ELSE DLITERAL
ELSE SWAP DROP LITERAL
THEN
THEN ?STACK
THEN
THEN
REPEAT ( There is no ;S to end this word )
: -FIND 0 TRUNK @ CONTEXT @ #FIND ;
: TFIND 0 TRUNK @ CONTEXT @ 2DUP = IF DROP THEN CURRENT @ SWAP #FIND ;
: #FIND BL DUP WORD COUNT 2DUP UPPER + C! BEGIN DUP IF HERE 2+ SWAP HASH @ (FIND) ?DUP IF >R BEGIN ROT 0= UNTIL R> ELSE THEN REPEAT THEN THEN ;
: HASH - Inline code ( calls NEXT - why? )
: (FIND) - Inline code