add support for # suffix to indicate double-cell numbers

This commit is contained in:
Jesse D. McDonald 2020-11-06 20:31:34 -06:00
parent c076939fe2
commit 7d859d4f23
2 changed files with 40 additions and 22 deletions

View File

@ -1450,10 +1450,10 @@ defword PARSENUMBER,,F_HIDDEN
.int SWAP,ADD1,SWAP,BRANCH,(0b - .) .int SWAP,ADD1,SWAP,BRANCH,(0b - .)
5: .int DROP 5: .int DROP
6: .int RDROP,RDROP 6: .int RDROP,RDROP
7: .int TWODROP,FALSE,EXIT 7: .int TWODROP,LIT,0,EXIT
8: .int DROP,FROMR,FROMR,ZBRANCH,(9f - .) 8: .int DROP,FROMR,FROMR,ZBRANCH,(9f - .)
.int NEGATE .int NEGATE
9: .int TRUE,EXIT 9: .int LIT,1,EXIT
defword INTERPRET,,F_HIDDEN defword INTERPRET,,F_HIDDEN
.int SKIP_SPACE .int SKIP_SPACE
@ -1466,21 +1466,26 @@ defword INTERPRET,,F_HIDDEN
litstring "Tried to interpret a string literal\n" litstring "Tried to interpret a string literal\n"
.int TYPE,BAILOUT .int TYPE,BAILOUT
/* ELSE */ /* ELSE */
1: .int PARSE_NAME,TWODUP,BOOTSTRAP_PARSENUMBER,ZBRANCH,(3f - .) 1: .int PARSE_NAME,TWOTOR
.int STATE,FETCH,TWONIP,ZBRANCH,(2f - .) .int TWORFETCH,BOOTSTRAP_PARSENUMBER,QDUP,ZBRANCH,(4f - .)
.int LIT,LIT,COMMA,COMMA .int TWORDROP,STATE,FETCH,ZEQU,ZBRANCH,(2f - .)
2: .int EXIT .int DROP,EXIT
/* ELSE-IF */
2: .int LIT,2,EQU,ZBRANCH,(3f - .)
.int LIT,TWOLIT,COMMA,COMMA,COMMA,EXIT
/* ELSE */ /* ELSE */
3: .int FIND_OR_BAILOUT,DROP 3: .int LIT,LIT,COMMA,COMMA,EXIT
.int STATE,FETCH,ZBRANCH,(4f - .) /* ELSE */
4: .int TWOFROMR,FIND_OR_BAILOUT,DROP
.int STATE,FETCH,ZBRANCH,(5f - .)
/* ( OR ) */ /* ( OR ) */
.int DUP,ISIMMEDIATE,ZBRANCH,(5f - .) .int DUP,ISIMMEDIATE,ZBRANCH,(6f - .)
4: .int EXECUTE,EXIT 5: .int EXECUTE,EXIT
/* ELSE */ /* ELSE */
5: .int DUP,ISBOOTSTRAP,ZBRANCH,(6f - .) 6: .int DUP,ISBOOTSTRAP,ZBRANCH,(7f - .)
litstring "Tried to compile bootstrap word: " litstring "Tried to compile bootstrap word: "
.int TYPE,TNAME,TYPE,EOL,BAILOUT .int TYPE,TNAME,TYPE,EOL,BAILOUT
6: .int COMMA,EXIT 7: .int COMMA,EXIT
defword QUIT,,F_HIDDEN defword QUIT,,F_HIDDEN
.int R0,RSPSTORE .int R0,RSPSTORE

View File

@ -1118,10 +1118,18 @@ CREATE DISPLAY-ITEM-LIMIT 6 ,
>>UTILITY >>UTILITY
\ Parse a signed number; to succeed the entire input string must be consumed \ Parse a signed number; to succeed the entire input string must be consumed
: PARSENUMBER ( c-addr u -- n TRUE | FALSE ) : PARSENUMBER ( c-addr u -- 0 | n 1 | d 2 )
DUP 0= IF NIP EXIT THEN ▪ OVER C@ [[ CHAR - ]] = DUP 0= IF NIP EXIT THEN ▪ OVER C@ [[ CHAR - ]] = >R
DUP >R IF 1/STRING DUP 0= IF RDROP NIP EXIT THEN THEN R@ IF 1/STRING DUP 0= IF RDROP NIP EXIT THEN THEN
>NUMBER R> 2NIP SWAP 0= DUP >R IF IF NEGATE THEN ELSE 2DROP THEN R> ; >NUMBER
R> IF 2SWAP DNEGATE 2SWAP THEN
DUP 1 = AND-THEN OVER C@ [[ CHAR # ]] = THEN IF
2DROP 2
ELSE-IF NIP 0= THEN-IF
DROP 1
ELSE
2DROP 0
THEN ;
' PARSENUMBER ' BOOTSTRAP-PARSENUMBER DEFER! ' PARSENUMBER ' BOOTSTRAP-PARSENUMBER DEFER!
@ -2078,13 +2086,18 @@ NULL 0 STRING-BUFFER 2!
HERE SWAP DUP ALLOT CMOVE ALIGN HERE SWAP DUP ALLOT CMOVE ALIGN
THEN THEN
ELSE ELSE
PARSE-NAME PARSE-NAME 2>R
2DUP PARSENUMBER IF 2R@ PARSENUMBER ?DUP IF
STATE @ 2NIP IF 2RDROP
STATE @ 0= IF
DROP
ELSE-IF 2 = THEN-IF
POSTPONE 2LITERAL
ELSE
POSTPONE LITERAL POSTPONE LITERAL
THEN THEN
ELSE ELSE
FIND-OR-THROW 2R> FIND-OR-THROW
\ -1 => immediate word; execute regardless of STATE \ -1 => immediate word; execute regardless of STATE
\ 1 => read STATE; compile if true, execute if false \ 1 => read STATE; compile if true, execute if false
0< ▪ OR-ELSE STATE @ 0= THEN ▪ IF EXECUTE ELSE COMPILE, THEN 0< ▪ OR-ELSE STATE @ 0= THEN ▪ IF EXECUTE ELSE COMPILE, THEN