mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 22:18:07 +11:00
a348ee9106
The few extra bytes they save in the core aren't worth the extra complexity. This was initially done in a context where I had troubles keeping the RC2014 binary with SDC inside the 8K limit. At this point, even with the few extra bytes we add here, we're at 7200 bytes, so I'd say we're fine.
15 lines
713 B
Plaintext
15 lines
713 B
Plaintext
: _pd ( a -- n f, parse decimal )
|
|
( We read the first char outside of the loop because it *has*
|
|
to be nonzero, which means _pdacc *has* to return 0. )
|
|
C@+ OVER C@ 0 ( a len firstchar startat )
|
|
( if we have '-', we only advance. more processing later. )
|
|
SWAP '-' = IF 1+ THEN ( a len startat )
|
|
( We loop until _pdacc is nonzero, which means either WS or
|
|
non-digit. 1 means WS, which means parsing was a success.
|
|
-1 means non-digit, which means we have a non-decimal. )
|
|
0 ROT ROT ( len ) ( startat ) DO ( a r )
|
|
OVER I + C@ ( a r c ) _pdacc ( a r f )
|
|
IF DROP 1- 0 UNLOOP EXIT THEN LOOP ( a r )
|
|
( if we had '-', we need to invert result. )
|
|
SWAP C@ '-' = IF 0 -^ THEN 1 ( r 1 ) ;
|