Hi, I have been following Ulrich Hoffman and Andrew Read's work for a couple of years.
There an interesting paper from the 2018 Euroforth conference that was held in Edinburgh
http://www.complang.tuwien.ac.at/anton/ ... ffmann.pdf
The Forth kernel is first dis-aggregated into two separate processes that can then be reconnected
The first is "preForth" that was mentioned by ECL above. This contains just 13 primitives which allows the virtual machine to be constructed using only the datastack and the return stack structures.
There is no random memory access at this stage (it is added later) - everything is processed on the stacks.
preForth does not permit the use of immediate words - so it relies on Forth source code that has already been compiled into a sequence of 16-bit addresses. (Or I suppose you could enter manually the address of the routine you wanted to execute - a bit like a monitor program) There is no interpreted mode or the need for a dictionary search or dictionary structure - at this low level - this is also added later.
Code: Select all
preForth is a minimalistic non-interactive Forth kernel that can bootstrap itself and
can be used as an easy-to-port basis for a full Forth implementation.
preForth feels like Forth - it is mainly a sublanguage of ANS-Forth - but is
significantly reduced in its capabilities.
Features:
minimal control structures, no immediate words, strings on stack, few primitives
just
• stack
• return stack
• only ?EXIT and recursion as control structures
• colon definitions
• optional tail call optimization
• IO via KEY/EMIT
• signed single cell decimal numbers (0-9)+
• character constants via ’c’-notation
• output single cell decimal numbers
and
• no immediate words, i.e.
• no control structures IF ELSE THEN BEGIN WHILE REPEAT UNTIL
• no defining words
• no DOES>
• no memory @ ! CMOVE ALLOT ,
• no pictured numeric output
• no input stream
• no state
• no base
• no dictionary, no EXECUTE, not EVALUATE
• no CATCH and THROW
• no error handling
preForth is based on just 13 primitives: emit key dup swap drop 0< ?exit >r r> - nest
unnest lit which are defined in the host language.
The next layer is simpleForth :
Code: Select all
simpleForth is an extension to preForth built using preForth. It is still
non-interactive but adds
• control structures IF ELSE THEN BEGIN WHILE REPEAT UNTIL
• definitions with and without headers in generated code
• memory: @ ! c@ c! allot c, ,
• variable, constants
• [’] execute
• immediate definitions
Enough convenient words to formulate an interactive Forth
As with any Forth implementation it is important to get the inner loop (usually called NEXT) of the VM to execute as efficiently as possible - as this is where Forth gains or loses its speed advantage.
The inner loop picks up the 16-bit start address of the word (function) to be executed and then jumps to that address. At the end of the function, there is a jump back to the start of NEXT.
Sometimes Forth will make use of 8-bit tokens to identify its words, but this introduces an extra stage of look-up to get the code field address.