A few months ago I released Bob - a "suite" of Scheme implementations in Python, featuring:
- A Scheme interpreter
- A stack-based VM running special bytecode, with a compiler from Scheme to this bytecode
Since then, I've been working on-and-off on another member of the suite - a C++ implementation of the Bob VM, dubbed (for lack of a better name!) BareVM. Here's the updated diagram showing what Bob includes:
Why is BareVM interesting? Python is a powerful programming language - sometimes too powerful. In particular, when implementing a virtual machine, Python makes the task relatively easy. Its powerful object system with duck typing, reflection capabilities and built-in garbage collection is something most Python programmers take for granted.
And yet, most real-world VMs are implemented in C or C++, since a VM is one of those programs which are never fast enough. Compared to Python, these are low-level languages requiring much more of the implementation to be explicit. BareVM was created as an exercise in VM implementation in a low-level language. As such, it has some interesting features that the Python implementation lacks. For example, since Scheme is a garbage-collected language, BareVM implements a mark & sweep GC for Scheme objects. The Python implementation doesn't need this implementation detail since it can rely on the underlying Python interpreter to perform GC.