Go Down

Topic: FORTH pre-loaded UNO or NANO? (Read 14409 times) previous topic - next topic

MrMark

#45
Feb 22, 2017, 02:22 pm Last Edit: Feb 22, 2017, 02:25 pm by MrMark
[ Would to hitch-hike and not start a new Forth thread. ]

SEE CODE

Passing the address of a function to a simulated stack ..how to do so?
Maybe I don't understand the question, but I think the tick word does what you want to do.

e.g.

' howtrue EXECUTE

will execute the function "howtrue" in FIG forth and those words are fundamental enough that they should be in any forth kernel.  (I have listing for STM8 eforth at hand and they are both in it.)

https://www.forth.com/starting-forth/9-forth-execution/

KeithRB


Chris_H

Maybe I don't understand the question, but I think the tick word does what you want to do.

e.g.

' howtrue EXECUTE

will execute the function "howtrue" in FIG forth and those words are fundamental enough that they should be in any forth kernel.
Got one of them, now (didn't, before you suggested it -- didn't think to; didn't know to):

Code: [Select]

SEE ATTACHED

    386 /* Number of words in the dictionary */
    387 const int entries = sizeof dictionary / sizeof dictionary[0];
    388
    389 /* new word: xt>adrs */
    390 void xtTOadrs() { // ( xt -- addrs )
    391   func function;
    392   // must be reflected at top of source
    393   // where the struct is
    394   int plc = pop();
    395   unsigned int adxrs; // REEXAMINE if adxrs cannot be adrs -- why uniqueness
    396   function = (func) pgm_read_word(&dictionary[plc].function);
    397   push((unsigned int) function);
    398   int a = pop();
    399   push(a - 1);
    400 }

    402 /* new word for xt execution */
    403 void execadrs() { // ( adrs -- ) action: execute at adrs
    404   int a = pop();  // an address of a word's execution token
    405   push(a + 1);    // alignment (why?)
    406   func function = ((func) pop());
    407   function();
    408   // fix bottom of stack so that
    409   // adrs is reusable, with 'back EXECUTE':
    410   back(); push(1); negate(); add(); drop();
    411   // starts to look like forth, doesn't it.
    412 }

    414 /* new word for xt execution */
    415 // execute from an xt (execution token) lookup
    416 void execXT() { // ( xt -- ) action: execute    XT exec - the EXECUTE word
    417   xtTOadrs();  // ( xt -- addrs )
    418   execadrs();  // ( adrs -- ) action: execute at adrs
    419 }
    420
    421 /* new alias for new word 'execXT' */
    422 void EXECUTE() { // ( xt -- ) action: execute
    423   execXT();
    424 }
    425
    426 /* short alias for EXECUTE:  xxt 'execute execution token' */
    427 void xxt() {
    428   execXT();
    429 }
    430
    431 /* Display all words in dictionary */
    432 void words() {


Quote
https://www.forth.com/starting-forth/9-forth-execution/
I'll be taking another look at Leo Brodie.  Hehe.  I've been doing this a *long* time, without having done so.

Oy.

Thanks, MrMark.  --Chris_H

Go Up