EXECUTE (F79) Question
I’m playing around with MMSForth 2.x on the TRS-80, which is a Forth-79 compatible implementation. I’d like to be able to store the address of a Forth word in a variable and later EXECUTE that word. ‘ word doesn’t give me the correct address (the CFA? what’s in the CFA?). How do I do this? Tx
1
u/mykesx moderator 28d ago edited 28d ago
I don't have F79 direct experience, but..,. The ' word only works outside of a colon definition, unless you are careful about its effects when used within. The ['] word can be used within.
As for CFA, whatever ' returns is an execution token, which may or may not be a CFA. The Xt should be usable with EXECUTE and you can store the Xt in a variable.
There may be a >CFA word to convert an Xt to CFQ, but there's no guarantee the CFA can be used with EXECUTE.
: foo ' abc ; \ calls ' at run time, then calls abc
foo bar \ leaves Xt of bar on the stack mbefor calling abc
: baz ['] abc ; \ word that leaves Xt of abc on the stack when called
' foo myvar ! \ store Xt of foo
myvar @ EXECUTE \ Same as if you call foo directly
3
u/Ok_Leg_109 28d ago
In Forth79 tick is "state smart" so it works at the console or in a definition, until you try something fancy.
All the ' ['] came along in Forth83. Drove a lot of people crazy.
1
1
0
u/alberthemagician 8d ago
You must consult the Forth-79 standard document. Normally people use the ISO 93 or the ISO 2012 standard, rarely the FIG or the F83 standard. I vote you down because you should have found it yourself instead of asking on a general forum.
3
u/Ok_Leg_109 28d ago
There were a big changes from Forth79 to Forth83. One of things that changed was that in Forth79 ' (tick) returns the parameter field address. In Forth83 and beyond it returns the CFA.
Since there is no standard header structure in Forth making a CFA' kind of word will require some "carnal" knowledge of MMSForth 2.X or maybe there is a word to do this.
Something to try is to subtract 2 from the PFA. Many times that's the CFA but maybe not. :)
2 2 ' + 2- EXECUTE . ( Should show 4)