Pages: 1
|
 |
|
Author
|
Topic: help with GP in retroforth (Read 2406 times)
|
|
|
lsa
Newbie

Karma: +0/-0
Offline
Posts: 3
|
Hello clacker
There are many solutions as you write. However i think the best is to compile the instructions from your command list, then execute the compiled instructions. I came up with the code below.
;============================================; : execute invoke ;
variable x1
create mycommands 5 cells allot ' + mycommands ! ' - mycommands cell+ ! ' * mycommands 2 cells + ! ' x1 mycommands 3 cells + ! 0 mycommands 4 cells + !
: >class >entry :class @ ; : cc dup @ 0; dup literal, >class compile cell+ cc ; : compile-cmds here mycommands cc drop ['] ; compile ;
10 50 10 20 compile-cmds execute ( GIVES: 200 addr-of-x1 )
|
|
|
|
|
Logged
|
|
|
|
clacker
Newbie

Karma: +0/-0
Offline
Posts: 3
|
lsa, thanks, that's exactly what I needed. I can't see why I need to use the >class instead of just ' yet, but it works great. Is there a reason why you used >class instead of just using the xt? I was also able to set aside some memory on the heap (using create and allot) and then setting h0 temporarily to that spot so compile compiles the new commands there.
Thanks again.
|
|
|
|
|
Logged
|
|
|
|
lsa
Newbie

Karma: +0/-0
Offline
Posts: 3
|
Well i haven`t used retroforth for some time but i think this is how it is implemented at the current version:
XT`s only point to the code, each word has a class, which is the action to take on the XT. With variables you can`t execute the XT (since it contains the value), when executing the class it leaves the XT.
You don`t need to use >class if you create variables as ": x1 4 ;" but variables created by "variable x1" would not be able to execute with "' x1 execute". Quickly stated: with classes you get the correct action to words.
|
|
|
|
|
Logged
|
|
|
|
|
|
clacker
Newbie

Karma: +0/-0
Offline
Posts: 3
|
Thanks, this was exactly what I needed. The reason I was thinking along the lines of : x1 4 was because I would like to test the functions against a set of data, and I thought that the easiest way would be to use:
variable currentX1 4 currentX1 !
: x1 currentX1 @ ;
Then by changin the variable currentX1, I don't need to change anything else.
As a side note, can I change the value of a constant? That is probably closer to what I really want but I couldn't tell how to do that.
|
|
|
|
|
Logged
|
|
|
|
|
|
lsa
Newbie

Karma: +0/-0
Offline
Posts: 3
|
If you use: : x1 20 ;
as a constant value. You may change it by:
: const! 5 + ! ; 50 ' x1 const!
the "5 +" advances past the "call dolit" which is compiled into the word.
The "values" solution may be cleaner, however.
|
|
|
|
|
Logged
|
|
|
|
Pages: 1
|
|
|
|
|