Rob Roland

Random writing on computing, baking, life. Find me on Mastodon too.

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.

Over the Christmas break of 2022, I started reading the excellent book “Crafting Interpreters” by Robert Nystrom. In this book you write a parser and interpreter, and later bytecode interpreter, for a object oriented scripting language named Lox.

I’m going through this book, implementing the language per the exercises in Java (a tree-walk interpreter) and then the bytecode interpreter in C.

For approximately 12 years, I’ve wanted to write my own Smalltalk implementation. Squeak, and the Cog VM, are excellent, but I want to write my own. I’ve read the “Blue Book” and it tells you exactly how the Smalltalk-80 VM was built.

For my own implementation, I’ve chosen to write the VM and compiler in Ada, as I don’t like writing C code.

My vision is for a NeXTSTEP like system, because I adore the GUI, with Smalltalk as the basis for the whole system.

This project is going to take a long time, but I’ll post as I write it.

I got my start with computers when I was very young, in 1982. My parents got a Timex-Sinclair 1000 (the American version of the British Sinclair ZX81). I suffer from pretty severe ADHD, and it was a struggle for my parents. I plopped down on the carpet in front of the TV and pushed buttons on this computer and didn’t get up for hours. To my parents, this was a dream – they had found something that I could pour attention into. I had no idea what I was doing at that point, but I was hooked.

Later, they replaced that with an Atari 800XL and a tape drive. That computer was theirs, and I occasionally got to play games on it. I can’t remember when it was sold, but a couple of years later (around 1986) my parents took me to Federated (a department store chain) and purchased another Atari 800XL, and an XF551 floppy drive, and a few games and some BASIC books. That was my computer from that point on. At school, there was a lab full of Commodore 64’s, and so I got to use them. I couldn’t translate Commodore BASIC to Atari BASIC easily, due to some differences. I remember writing a letter to Atari Corporation in Sunnyvale, CA, using AtariWriter and the Okimate 10 printer I had, asking them what I was doing wrong. I explained my age, etc. My mom added her own details to the letter, and mailed it.

To all of our surprise, someone at Atari wrote back! They told me what I was doing wrong (you have to DIM string variables in Atari BASIC) and some other pointers, included some software and a subscription to Antic! magazine. I was hooked. I wanted to be that guy who wrote me back when I got older.

My family wasn’t wealthy, so I didn’t have a ton of peripherals or software for my Atari, but I learned to write BASIC and write my own software. I had some friends with wealthier families, so I got to see their even fancier hardware, but I still loved mine.

Fast forward many years, and I’m a professional software engineer. I started collecting computers from the late 70s to the early 90s, the machines that fascinated me and I never owned. I started with an Amiga 2000, because I had friends with them that I thought were amazing computers. I did personally have an Amiga 500 for about a year in 1996, that I bought secondhand, and later had to sell to pay my car payment.

I’ve been collecting for about 7 years now, and upgrading the machines to be the most amazing they could be for the time period. The Amiga being the exception, it has more modern hardware that takes it beyond anything that was available in the 1990s.

Playing games and writing software on this older hardware reminds me of when I fell in love with computing. When it was possible to fully understand how the computer works end-to-end, how to write software without hundreds of dependencies, gigabytes of RAM and limited people to ask for help.

I also miss the variety in computing systems that existed back then – different CPUs, different graphics capabilities, and a computer that just says “READY” as soon as it powers on. I know those days are past, but it’s fun to enjoy the nostalgia.