Simple but not working "program" in colorForth

19 views
Skip to first unread message

Pavel Klinkovsky

unread,
Feb 21, 2012, 8:43:33 AM2/21/12
to ColorForth
Hi all,

I am trying such a simple "program" in cF (windows/linux) but without
success:
[R] array [G] pop ;
[R] tbl [G] array [Y] 10 , 20 , 30 ,

[R] - red
[G] - green
[Y] - yellow

If I try "tbl" I have an adress on TOS.
Then if I try "@' the exception occured...

I must do something wrong...

Can you help me?

Thanks in advance.

Pavel

Ray St. Marie

unread,
Feb 21, 2012, 10:53:43 AM2/21/12
to ColorForth


On Feb 21, 6:43 am, Pavel Klinkovsky <pavel.klinkov...@gmail.com>
wrote:
Hi Pavel,

I am using the newest arrayForth 01g at http://greenarrays.com but
this should work every version of colorforth I know of...

: array pop 2/ 2/ ;
: tbl align array [ 0 , 0 , 0 , 10 0 tbl + ! 20 1 tbl + ! 30 2 tbl
+ ! ]


[ everything in brackets is yellow ]
colon red : obviously :-) everything else is green.


If i type these I get these:
0 tbl + @ === 10
1 tbl + @ === 20
2 tbl + @ === 30

The address popped from YOUR "tbl" definition uses your definition.
: array pop ;

This array--pop pops a BYTE address in your table word. Notice that
your tbl word returns an address 4 times larger than mine does. That
address needs to be converted to a doubleword address like in my array
definition with the "2/" 's added. You COULD use your array--pop
definition but you would also have to define a byte-fetch word,
because "@" fetch is a cell fetcher and a cell is a dword in
colorForth.

Such a table should be "align"ed.

I hope this helps and if you need anything else... only ask :-)

Ray

David Stith

unread,
Feb 21, 2012, 10:22:15 AM2/21/12
to color...@googlegroups.com
Pavel,

Instead of 'pop' I think you will have to have 'pop 4 /' since ColorForth addresses by 32 bit word instead of by byte (but the return stack is still addressed by byte).

Thanks, :-)
David Joseph Stith


Pavel

--
You received this message because you are subscribed to the Google Groups "ColorForth" group.
To post to this group, send email to Color...@googlegroups.com.
To unsubscribe from this group, send email to Color-Forth...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/Color-Forth?hl=en.




--
“This is the way of peace: Overcome evil with good, falsehood with truth, and hatred with love.”
[Peace Pilgrim]

Ray St. Marie

unread,
Feb 21, 2012, 11:13:41 AM2/21/12
to ColorForth


On Feb 21, 8:53 am, "Ray St. Marie" <ray.stma...@gmail.com> wrote:
> On Feb 21, 6:43 am, Pavel Klinkovsky <pavel.klinkov...@gmail.com>
> wrote:
>
> > Hi all,
>
> > I am trying such a simple "program" in cF (windows/linux) but without
> > success:
> > [R] array [G] pop ;
> > [R] tbl [G] array [Y] 10 , 20 , 30 ,
>
> > [R] - red
> > [G] - green
> > [Y] - yellow
>
> > If I try "tbl" I have an adress on TOS.
> > Then if I try "@' the exception occured...
>
> > I must do something wrong...
>
> > Can you help me?
>
> > Thanks in advance.
>
> > Pavel
>
> Hi Pavel,
>
> I am using the newest arrayForth 01g athttp://greenarrays.com but
> this should work every version of colorforth I know of...
>
> : array pop 2/ 2/ ;
> : tbl align array [ 0 , 0 , 0 , 10  0  tbl + ! 20 1 tbl + ! 30 2 tbl
> + ! ]
>
> [ everything in brackets is yellow ]
> colon red : obviously  :-)   everything else is green.
>
> If i type these I get these:
> 0 tbl + @   ===  10
> 1 tbl + @   ===  20
> 2 tbl + @   ===  30
>
> The address popped from YOUR "tbl" definition uses your definition.
> : array pop ;
>
> This array--pop pops a BYTE address in your table word. Notice that
> your tbl word returns an address 4 times larger than mine does. That
> address needs to be converted to a doubleword address like in my array
> definition with the "2/" 's  added. You COULD use your array--pop
> definition but you would also have to define a byte-fetch word,
> because "@" fetch is a cell fetcher and a cell is a dword in
> colorForth.
>
> Such a table should be "align"ed.
>
> I hope this helps and if you need anything else... only ask :-)
>
> Ray

Alternatively, you could also do this:

[ macro ]
: 1@ 0x8a 2, ;
: 1! [compile] a! 0x288 2, [compile] drop ; [ forth ]
:1@ 1@ 0xff and ;
: array pop ;
: tbl align array [ 10 1, 20 1, 30 1, ]

then you would use 1@ to @ and 1! to store a byte at a time.

Best regards,
Ray

Pavel Klinkovský

unread,
Feb 21, 2012, 11:02:31 AM2/21/12
to color...@googlegroups.com
Hi Ray,

: array pop 2/ 2/ ;

Ah, clear!
 
This array--pop pops a BYTE address in your table word. Notice that
your tbl word returns an address 4 times larger than mine does.

It is my typical mistake.
I always forget about such adressing...

Such a table should be "align"ed.

That is clear.
In fact, I also tried "align"ed version.

But I forget to shift the adress...
 
I hope this helps and if you need anything else... only ask :-)

It helped a lot, thank you very much. ;-)

Regards,

Pavel

Pavel Klinkovský

unread,
Feb 21, 2012, 11:05:27 AM2/21/12
to color...@googlegroups.com
Hi David,

Instead of 'pop' I think you will have to have 'pop 4 /' since ColorForth addresses by 32 bit word instead of by byte (but the return stack is still addressed by byte).

yes, you are right.

It is my usual mistake to forget such addressing scheme of cF... ;-)

Thanks!

Regards,

Pavel

David Stith

unread,
Feb 21, 2012, 11:29:54 AM2/21/12
to color...@googlegroups.com
And, having seen the other posts, '2/ 2/' is indeed much better than '4 /'. :-)
(Even better, perhaps, would be to define a 4/ in machine language)

Thanks,
David Joseph Stith

2012/2/21 Pavel Klinkovský <pavel.kl...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "ColorForth" group.
To post to this group, send email to Color...@googlegroups.com.
To unsubscribe from this group, send email to Color-Forth...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/Color-Forth?hl=en.

Pavel Klinkovský

unread,
Feb 21, 2012, 11:57:30 AM2/21/12
to color...@googlegroups.com
> : array pop 2/ 2/ ;

Alternatively, you could also do this:

[ macro ]
: 1@  0x8a 2, ;
: 1! [compile] a! 0x288 2, [compile] drop ; [ forth ]
:1@ 1@ 0xff and ;
: array pop ;
: tbl align array [ 10 1, 20 1, 30 1, ] 

For my purpose, the ": array pop 2/ 2/ ;" approach is better,
since I will need the table of DWORDs.

Regards,

Pavel
 
Reply all
Reply to author
Forward
0 new messages