mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-17 06:18:06 +11:00
parse: use "0<" instead of "0 <"
As I wrote in my "Clarify signed-ness" commit, "0 <" is broken. Also, made this unit a bit more compact. The RC2014 stage1 can really use some breathing room...
This commit is contained in:
parent
66f65daa08
commit
b062a9092a
2
blk/018
2
blk/018
@ -5,7 +5,7 @@ unsigned. For convenience, decimal parsing and formatting
|
||||
support the "-" prefix, but under the hood, it's all unsigned.
|
||||
|
||||
This leads to some oddities. For example, "-1 0 <" is false.
|
||||
To compare whether something is negative, use the "<0" word
|
||||
To compare whether something is negative, use the "0<" word
|
||||
which is the equivalent to "0x7fff >".
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -2,8 +2,7 @@
|
||||
|
||||
: >= < NOT ;
|
||||
: <= > NOT ;
|
||||
: <0 32767 > ;
|
||||
: >=0 <0 NOT ;
|
||||
: 0>= 0< NOT ;
|
||||
|
||||
( n1 -- n1 true )
|
||||
: <>{ 1 ;
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
: . ( n -- )
|
||||
( handle negative )
|
||||
DUP <0 IF '-' EMIT -1 * THEN
|
||||
DUP 0< IF '-' EMIT -1 * THEN
|
||||
_
|
||||
BEGIN
|
||||
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )
|
||||
|
@ -51,6 +51,7 @@
|
||||
: = CMP NOT ;
|
||||
: < CMP -1 = ;
|
||||
: > CMP 1 = ;
|
||||
: 0< 32767 > ;
|
||||
|
||||
( r c -- r f )
|
||||
( Parse digit c and accumulate into result r.
|
||||
|
@ -11,7 +11,7 @@
|
||||
;
|
||||
|
||||
( returns negative value on error )
|
||||
: hexdig ( c -- n )
|
||||
: _ ( c -- n )
|
||||
( '0' is ASCII 48 )
|
||||
48 -
|
||||
DUP 0< IF EXIT THEN ( bad )
|
||||
@ -31,21 +31,20 @@
|
||||
2+
|
||||
( validate slen )
|
||||
DUP SLEN ( a l )
|
||||
DUP 0 = IF DROP 0 EXIT THEN ( a 0 )
|
||||
DUP NOT IF DROP 0 EXIT THEN ( a 0 )
|
||||
4 > IF DROP 0 EXIT THEN ( a 0 )
|
||||
0 ( a r )
|
||||
BEGIN
|
||||
OVER C@
|
||||
DUP 0 = IF DROP SWAP DROP 1 EXIT THEN ( r, 1 )
|
||||
hexdig ( a r n )
|
||||
DUP 0 < IF DROP DROP 1 EXIT THEN ( a 0 )
|
||||
SWAP 16 * + ( a r*16+n )
|
||||
SWAP 1+ SWAP ( a+1 r )
|
||||
SWAP C@+ ( r a+1 c )
|
||||
DUP NOT IF 2DROP 1 EXIT THEN ( r, 1 )
|
||||
_ ( r a n )
|
||||
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 )
|
||||
ROT 16 * + ( a r*16+n )
|
||||
AGAIN
|
||||
;
|
||||
|
||||
( returns negative value on error )
|
||||
: bindig ( c -- n )
|
||||
: _ ( c -- n )
|
||||
( '0' is ASCII 48 )
|
||||
48 -
|
||||
DUP 0< IF EXIT THEN ( bad )
|
||||
@ -65,12 +64,11 @@
|
||||
16 > IF DROP 0 EXIT THEN ( a 0 )
|
||||
0 ( a r )
|
||||
BEGIN
|
||||
OVER C@
|
||||
DUP 0 = IF DROP SWAP DROP 1 EXIT THEN ( r, 1 )
|
||||
bindig ( a r n )
|
||||
DUP 0 < IF DROP DROP 1 EXIT THEN ( a 0 )
|
||||
SWAP 2 * + ( a r*2+n )
|
||||
SWAP 1+ SWAP ( a+1 r )
|
||||
SWAP C@+ ( r a+1 c )
|
||||
DUP NOT IF 2DROP 1 EXIT THEN ( r 1 )
|
||||
_ ( r a n )
|
||||
DUP 0< IF ROT 2DROP 0 EXIT THEN ( a 0 )
|
||||
ROT 2 * + ( a r*2+n )
|
||||
AGAIN
|
||||
;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user