Mon May 14 09:18:05 EDT 2012

Forth Direct vs. Indirect threading?

I forget..  What is again the difference?

IIRC, indirect threading is easier to implement in C...

Starting out with just straight-line code, it might be simplest to
forget about code fields altogether.

So, what is pointed to by IP?  It's essentially an opcode for a VM.

Again: what's the simplest threading mechanism to use to implement
Forth in C?  I think it's called switch threading, where the main loop
is something like:

  switch(*ip++) {
    case CMD_EXIT: ... ;
    case CMD_LIT: ... ;

Disadvantage: this needs a "call" opcode for composite words.  So it's
essentially one layer on top of subroutine threading (ST for a stack
VM).  Probably, CALL can use half of the address space.  Also, this
needs both CALL and JUMP for tail calls + RETURN for primitive words.
Is it really simpler?

What about making the instruction stream abstract?  Calling a word ==
pushing a new instruction stream, and popping it at the end (EXIT).