Re: More <0 strangeness

Samuel Tardieu <[email protected]> 24 Nov 2004 09:52:39 +0100
Newsgroups gmane.comp.lang.forth.picforth
Organization Avian Carrier & Friends
Message-ID <[email protected]>
>>>>> "Alex" == Alex Holden <[email protected]> writes:

Alex> This time I appear to have found a weird optimization bug with
Alex> the 0< word.

Could you try the following patch? (or get it from my repository)

Wed Nov 24 09:47:14 CET 2004  Samuel Tardieu <[email protected]>
  * Fix 0 < case

--- picforth-1-old/picforth.fs	2004-11-24 09:50:24.000000000 +0100
+++ picforth-1-new-4/picforth.fs	2004-11-24 09:47:34.000000000 +0100
@@ -1733,7 +1733,11 @@
    
 : <
     const? if
-	kill-const negate popw addlw pushw carry-clr?
+	kill-const ?dup if
+	    negate popw addlw pushw carry-clr?
+	else
+	    meta> 0<
+	then
     else
 	meta> - carry-clr?
     then

The reason was that to implement "ACONSTANT <", PicForth was adding
the opposite value of ACONSTANT and checking the carry bit. Of course,
adding minus zero didn't set the carry bit.

"0<" on the other hand was told to properly look at the sign bit. Now,
it is called when "0 <" is used.

  Sam
-- 
Samuel Tardieu -- [email protected] -- http://www.rfc1149.net/sam