diff --git a/blk/003 b/blk/003 index c6a9b93..8b4ada6 100644 --- a/blk/003 +++ b/blk/003 @@ -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 diff --git a/blk/018 b/blk/018 new file mode 100644 index 0000000..0f8d53e --- /dev/null +++ b/blk/018 @@ -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 >". diff --git a/blk/058 b/blk/058 index 9de8bc2..8e73430 100644 --- a/blk/058 +++ b/blk/058 @@ -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. diff --git a/forth/cmp.fs b/forth/cmp.fs index 51f905d..866bae5 100644 --- a/forth/cmp.fs +++ b/forth/cmp.fs @@ -2,6 +2,8 @@ : >= < NOT ; : <= > NOT ; +: <0 32767 > ; +: >=0 <0 NOT ; ( n1 -- n1 true ) : <>{ 1 ; diff --git a/forth/fmt.fs b/forth/fmt.fs index db3744b..e974a8f 100644 --- a/forth/fmt.fs +++ b/forth/fmt.fs @@ -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 ) diff --git a/tests/forth/test_cmp.fs b/tests/forth/test_cmp.fs index dfe8876..2e76152 100644 --- a/tests/forth/test_cmp.fs +++ b/tests/forth/test_cmp.fs @@ -3,3 +3,4 @@ 0x42 <>{ 0x40 &> 0x44 &< <>} # 0x44 <>{ 0x40 &> 0x44 &< <>} NOT # 0x22 0x8065 < # +-1 0 > #