Planning out my Smalltalk implementation
I am about 80% of the way through reading Crafting Interpreters by Robert Nystrom. This feels like a logical place to start planning my Smalltalk implementation.
As this is the first time I’ve written my own interpreter or compiler, I’m going to follow the framework setup in the book. The first implementation will be a tree-walk interpreter, followed by a bytecode compiler and virtual machine. Eventually I’d love to add just-in-time (JIT) compilation, but I’m not in a hurry for that.
My eventual goal is to have the virtual machine running on a bare metal RISC-V or ARM single board computer, with a minimal operating system layer underneath it.
I’ve made a few decisions already:
- Implementation will be done in Ada. I don’t much care for writing C code – I’m too good at turning code into segmentation faults. Most of my career has been spent in managed languages on the JVM, so I want the compiler to help me. Rust would be a good fit here too, but the second language I ever learned, after BASIC, was Pascal. That syntax will always resonate with me.
- I will write my own eBNF description of the Smalltalk syntax. I could jump right into the parsing code, but it helps to describe it as such first.
- A tree-walk interpreter will be written first. This code won’t be fast, but it’ll let me test the correctness1 of my parser and tokenizer.
- Each component will be thoroughly tested using the AUnit test framework.
- There will be an X11-compatible backend to the GUI, so that the system can be tested and developed on a Linux or BSD system. This will either use X11 directly, or via an abstraction like SDL.
- The on-disk representation of the source code will follow the Squeak FileOut format. This may be a little awkward to write from scratch, but it will enable users to import code from Squeak.
Expect more posts as this develops!
1 I almost said “prove” here, but that means something very different in the context of Ada! It would be nice to mathematically prove the correctness of my interpreter, but I'm under no illusions that I'll be able to do that.