home .. forth .. colorforth mail list archive ..

[ColorForth] Question regarding if


Alex Thiel wrote:
I want to write a word that test the TOS for a non-zero value. I have tried

I was getting really confused by this so I sacrificed some efficiency for some clarity.

I have renamed 'if' to 'ifnz' to reflect the way it behaves.
I have defined 'if' as the macro:
(red) if (cyan) 0 + drop ifnz (green) ;

So 'if' now works like it does in regular forths, where it's behaviour is determined by the TOS, which is then discarded.

I ummed and arred about this a lot, as I didn't want to backslide to a worse way of doing things. I'm new to forth, so it is more important to me that I can understand what I am doing than things being the most efficient. From looking at the Machine Forth in Chuck's chips I am pretty sure that this difficulty around tests is an artifact of mapping Machine Forth on to the Pentium as opposed to achieving things in a better way that I don't understand. Please tell me if I am wrong here.

Redefining the behaviour of 'if' is going to be a pain when I start sharing code with other colorForthers. But I will deal with that in due course.

I've also defined the macros:
(red) false (cyan) 0 (green) ;
red) true (cyan) 0 - (green) ;

And the equality operators as forth words in the attached picture.

I haven't attempted to optimise these. But I'm not spending time trying to remember how the Pentium's flags work anymore.

Richard Collins

------------------------

To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems   -   List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site   -   http://www.colorforth.com
Wiki page http://kristopherjohnson.net/wiki/ColorForth
ColorForth index http://www.users.qwest.net/~loveall/c4index.htm

JPEG image