Content deleted Content added
m →History leading to threaded code: removed offtopic remark about wiki editors |
|||
Line 48:
*String threading: In which operations are identified by strings, usually looked-up by a hash table. This was used in Charles Moore's earliest Forth implementations and in the [[University of Illinois]]'s experimental hardware-interpreted computer language. It is also used in [[Bashforth]].
*[[return threading]]
*Call Threaded Code uses a list of addresses that refers directly to machine language primitives, just like Direct Threaded code. However, the interpreter, instead of ''jumping'' to the primitive, ''calls'' it with a microprocessor subroutine call instruction instead. This system is slower than direct threading, and may even be slower than indirect threading on some systems. However, it is convenient because it allows for implementations written entirely in high-level languages, like C or Oberon. For example, here is an implementation written in both C and Oberon (untested):
/* In C */
extern int stillInterpreting;
extern int dataStack[], returnStack[];
extern int dataStackPointer, returnStackPointer;
typedef void WORD( int **, int **, int *, int * );
stillInterpreting = 1;
while( stillInterpreting )
{
WORD *nextWord = (WORD *)(*instructionPointer++);
nextWord( &dataStackPointer, &returnStackPointer, dataStack, returnStack );
}
/* In Oberon */
MODULE CallThreadingInterpreter;
CONST MaxStackSize* = 256;
TYPE ThreadState* = POINTER TO ThreadStateDesc;
Word* = PROCEDURE( current: ThreadState );
StackSpace* = ARRAY MaxStackSize OF INTEGER;
ThreadStateDesc* = RECORD
dataStackPointer,
returnStackPointer: INTEGER;
dataStack,
returnStack: StackSpace;
instructionPointer: INTEGER;
program: ARRAY OF Word;
END;
VAR stillInterpreting*: BOOLEAN;
PROCEDURE Interpret*( current: ThreadState );
VAR w: Word;
BEGIN
WHILE stillInterpreting DO
w := current.program[ current.instructionPointer ];
INC( current.instructionPointer );
w( current );
END;
END Interpret;
END CallThreadedInterpreter.
Note how in both cases no direct assembly language is required.
==Common amenities==
|