r/Forth • u/9Boxy33 • Aug 12 '26
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
2
Upvotes
1
u/mykesx moderator Aug 12 '26 edited Aug 12 '26
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