longforth:start

This is an old revision of the document!


A Persistent Version of Forth

For me, personally, the best way to start learning about the design of persistent virtual machines is to create a working persistent implementation of the Forth Programming Language.

Forth is a wonderfully minimal programming language that hosts it's own interactive development environment.

Within a simple Forth implementation essential topics are explored, including:

  • Stack based execution
    • The stack sits at the heart of common virtual machines, like the [wp>Java_Virtual_Machine|JVM] or [wp>Common_Language_Runtime|CLR]. Forth is a stack based programming language where the programmer is able to directly interact with the stack, instead of having it abstracted away beneath friendlier syntax.
  • Execution environment
    • Forth provides a minimalist development environment that is incredibly power and, once you get used to it, enjoyable to use. The experience challenges you to reconsider the necessity of all the features that we now have in our bloated IDEs.
  • Instruction set design
    • Forth's minimalism extends to it's instruction set. Forth provides a complete, powerful language using a set of words that is much smaller than the opcodes supported by the typical virtual machine.
  • Portability
    • Forth is easily ported to new hardware because most of the instruction set is implemented using just a handful of core words that use native machine code. To port to a new environment only those core words need to be ported.
  • Interactive and Active development
    • Before we had Agile and Refactoring we had Thinking Forth by Leo Brodie. The subtitle says it all: “A Language and Philosophy for Solving Problems.”
  • Progressive Word Definitions
    • Forth has a feature that I see as important for Plip Plop Programming. When a word is updated, it does not affect existing words, which will continue to use the version of the word as it was at the time of compilation. This frees the programmer to change words without having to constantly regression test.

NibbleForth

Rather than working from a specification, I will be using NibbleForth as my model of Forth. I've chosen NibbleForth because it implements a fully functioning, minimalistic, version of Forth using Python code that is easy to read and understand.

I have chosen NibbleForth over more compact implementations such as [https://hackaday.com/2023/11/06/tiny-forth-could-be-the-smallest/|Tiny Forth] because of this simplicity and clarity of implementation.

NibbleForth was written by Ben Hoyt as an experiment on compact code. The source can be found in his GitHub account: https://github.com/benhoyt/nibbleforth.

One limitation to NibbleForth is that it does not support Progressive Word Definitions. It just maintains a dictionary of word definitions as text rather than compiling to execution tokens. I will need to fix this.

My Approach

I don't have much spare time to spend on this project, so I need to break the whole think up into neat little chunks. I expect this to keep my busy until at least the end of 2025.

  1. Python Console Implementation
    1. Extract the core primitives from NibbleForth into my own console driven implementation that will allow me to run Forth code but not define word.
    2. Add the compiler and words required for writing structured code to the point where I can run Forth code at the command line.
    3. Update the implementation to support progressive word definitions.
    4. Build up a full test suite of forth code that can be automatically executed.
  2. Python SQL Implementation
    1. Redefine core words to execute, using SQLite, against database tables instead of Python lists and dictionaries.
    2. Update the test suite to execute across multiple Python instances access the same database file to ensure that my implementation is persistent.
  3. Minimal Web Front End
    1. Write a simple web front end that will allow me to develop and test LongForth in my browser.
  4. PHP and MySql Port
    1. Port LongForth to PHP and MySql, ensuring that the effort to Port and maintain multiple implementations is kept simple and straightforward.
  5. Interactive Web Front End
    1. Extend the Web Front End to provide the ability to interact with the VM state, stepping through code and viewing the changes to internal state.
  • longforth/start.1722164334.txt.gz
  • Last modified: 2024/07/28 06:58
  • by gedbadmin