For the past year I have been trying to write a book around virtual machine construction. The book is entitled ‘Building a virtual machine in 72 hours’ and indeed intents for a Smalltalk programmer with no VM knowledge to build a simple virtual machine in 72 hours. The book is under Creative Commons license (free pdf available).
I know the blue book is great for this purpose, but I wanted to provide a more guided experience, with exercises with each main concept, so the reader don’t have to get everything working from the bootstrap to the VM to figure out if his code is correct.
The idea is that after reading this book and doing the exercises, a non-VM programmer can acquire enough knowledge to build a very naive Smalltalk VM and hopefully to start understanding and contributing to the Cog.
The book is divided as follow:
I. Call stack management
On top of a very simple 7-instructions language, the book describes multiple interpreters with increasing level of difficulty, and the reader can program from templates successively a context interpreter, a stack interpreter, introduce stack page management, a context interpreter with closures, a stack interpreter with closures.
II. Bytecode compilation
On top of an almost complete Smalltalk language (very few things are removed such as pool dictionaries), the reader can understand basic concepts behind bytecode compilation and implement successively through exercises a bytecode compiler that compiles only methods, then methods and closures, lastly inlines control flow operations to jumps.
III. Kernel construction
The book describes a simple 30 classes Smalltalk kernel with exercises to bootstrap it to the first image that can be run, using the compiler of the previous section to cross-compile compiled methods. This part introduces memory representation of objects.
IV. Virtual machine
By opposite to the previous part of the book, this part has to be implemented in C. A template and explanations are provided to build a simple context interpreter with a naive GC, that can run the image bootstrapped in the previous part of the book.
I have written the first part of the book around Call Stack Management. I had a bachelor student (Cyril Ferlicot), a phd student (Vincent Blondeau), an experienced engineer (Christophe Demarey) and an experienced researcher (Stephane Ducasse) to read the first chapters of this part of the book and attempt to do the exercises.
I am interested in having other people reading this part of the book, especially people which have time to read the full part of the book and not only the first chapters. I am willing to listen to the comments such a reader would have and if they’re relevant to me, I will improve the books based on those comments.
You can download here the Call Stack Management part of the book (I keep it updated for stable release):
Thanks for any comments. If you have a lot of comments, please contact me by mail at bera dat clement at gmail dat com, no need to overflow the comment section of the blog post.