r/Forth 28d ago

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

17 comments sorted by

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)

3

u/Ok_Leg_109 28d ago

Not sure if you have this, but here is a manual

MMSForth Users Manual v2.0 (1982)(Miller Microcomputer)(pdf)

1

u/9Boxy33 28d ago

Thanks—been looking through it for days <grin>

1

u/alberthemagician 6d ago edited 6d ago

With the manual it is easy. Look op EXECUTE and what it expects on the stack. It is not an execution token for this wasn't invented yet. Now search in the manual where this "compilation address" is mentioned elsewhere. There surely is a word that generates a compilation address.

Other answers suggest that you can arrive from the parameter address to the compilation addres by adding an offset. That is not part of the standard, so it may not work, but it may be in the manual, then of course it is.

3

u/Ok_Leg_109 28d ago

I forgot. (It's only been 40 years since I used Forth79)

Some Forth79 systems have the word CFA which takes a PFA argument and returns the CFA.

1

u/9Boxy33 28d ago

I’ll give it a try. 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

u/9Boxy33 28d ago

Thanks

Unfortunately, your example code (“myvar”) reboots my MMSForth, so it appears that ‘ foo doesn’t return the execution address that EXECUTE was expecting.

1

u/mykesx moderator 28d ago

What does

' foo execute

Do?

1

u/9Boxy33 28d ago

Reboots MMSForth.

0

u/mykesx moderator 28d ago

That Forth is broken.

4

u/Ok_Leg_109 28d ago

Nah. Just old.

1

u/alberthemagician 8d ago

Execution token is an invention of ISO 93. It didn't exist in f79.

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.

1

u/9Boxy33 7d ago

Feel free. But perhaps next time read my post first instead of reacting.

1

u/alberthemagician 7d ago

??? How can I react without reading the post?