www.delorie.com/gnu/docs/gforth/gforth_254.html   search  
Buy GNU books!

Gforth Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14.2 Threading

GNU C's labels as values extension (available since gcc-2.0, see section `Labels as Values' in GNU C Manual) makes it possible to take the address of label by writing &&label. This address can then be used in a statement like goto *address. I.e., goto *&&x is the same as goto x.

With this feature an indirect threaded NEXT looks like:
cfa = *ip++;
ca = *cfa;
goto *ca;
For those unfamiliar with the names: ip is the Forth instruction pointer; the cfa (code-field address) corresponds to ANS Forths execution token and points to the code field of the next word to be executed; The ca (code address) fetched from there points to some executable code, e.g., a primitive or the colon definition handler docol.

Direct threading is even simpler:
ca = *ip++;
goto *ca;

Of course we have packaged the whole thing neatly in macros called NEXT and NEXT1 (the part of NEXT after fetching the cfa).

14.2.1 Scheduling  
14.2.2 Direct or Indirect Threaded?  
14.2.3 DOES>  

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003