⇐ DEVELOPMENT-INDEX Implementing a FORTH virtual machine

Implementing a FORTH virtual machine

(c) Andreas Klimas 2017 (w3group, German)

In another series I would show how easy and powerful the programming with FORTH can be.

To extend self written applications (in any programming language) with interactive capabilities (at runtime) could lead in quite interesting features. More powerful testing, debugging and maintenance as well. To have a command line available all the time (even at the customer) could be a striking feature. With such a tool the application can get a preemptive multitasker for free, even for languages which are not capable of doing preemptive multi tasking.

This is a series of 5 courses which shows how simple the implementation of a FORTH engine can become (indirect threaded code for now). The source is ANSI-C but implementations in Java and JavaScript will follow soon.

You can download the ANSI-C archive andreas_forth_course.tgz (4k) here.

Course Lines code Description
⇒ course01 119 Data stack, dictionary, simple interpreter, no string handling
⇒ course02 140 little string handling added
⇒ course03 269 now we get a return stack, a macro dictionary, code segment and an instruction pointer
The big deal now is that we must have a virtual machine running where the interpreter and compiler is running inside. So we have to compile our first word (I name it shell) by hand
⇒ course04 304 Add conditions like if and while and unconditional loops
⇒ course05 353 In the last part we build an disassembler (see and dis) to show the power of ITC (indirect threaded code). We introduce function pointer, pointer to words which can be executed with the word execute

This course is for educational purpose only. The missing parts are: includes from files (we have stdin only), file handling, exception handling (from the host language and from FORTH itself), debugger (breakpoints, conditional breakpoints, watchpoints, singlestepper) and multitasking (preemptive). Profiling and instrumenting is missing as well.

All these things can be implemented easily and may be I will extend the course further. It depends on the request from the comunnity.

You can email me klimas@klimas-consulting.com