Clarify signed-ness

And fix broken negative display in ".".
This commit is contained in:
Virgil Dupras 2020-04-15 12:29:47 -04:00
parent b73e1a5f7a
commit 22f132094a
6 changed files with 15 additions and 5 deletions

View File

@ -9,4 +9,4 @@ Contents
4 DOES> 6 Compilation vs meta-comp.
8 I/O 11 Chained comparisons
14 Addressed devices
14 Addressed devices 18 Signed-ness

9
blk/018 Normal file
View File

@ -0,0 +1,9 @@
Signed-ness
For simplicity purposes, numbers are generally considered
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
which is the equivalent to "0x7fff >".

View File

@ -5,6 +5,6 @@ LIT -- Write a LIT entry. You're expected to write
LIT< x -- Read following word and write to HERE as a
string literal.
LITS a -- Write word at addr a as a atring literal.
S= a1 a2 -- f Compare strings a1 and a2, return true if equal
S= a1 a2 -- f Returns whether string a1 == a2.
SCPY a -- Copy string at addr a into HERE.
SLEN a -- n Push length of str at a.

View File

@ -2,6 +2,8 @@
: >= < NOT ;
: <= > NOT ;
: <0 32767 > ;
: >=0 <0 NOT ;
( n1 -- n1 true )
: <>{ 1 ;

View File

@ -12,9 +12,7 @@
: . ( n -- )
( handle negative )
( that "0 1 -" thing is because we don't parse negative
number correctly yet. )
DUP 0 < IF '-' EMIT 0 1 - * THEN
DUP <0 IF '-' EMIT -1 * THEN
_
BEGIN
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )

View File

@ -3,3 +3,4 @@
0x42 <>{ 0x40 &> 0x44 &< <>} #
0x44 <>{ 0x40 &> 0x44 &< <>} NOT #
0x22 0x8065 < #
-1 0 > #