A C++ VM added to Bob
April 9th, 2011 at 12:32 pmA 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.
Related posts:

April 9th, 2011 at 17:42
This is good. I’m going to refer to this when I extend my Haskell Scheme interpreter to an actual compiler. Thanks.
April 10th, 2011 at 11:36
At first, I thought about using CPython for a Scheme VM, but for another reason: mainly to leverage the wealth set of libraries available for Python to Scheme, but at last I decided I needed a better support for native OS threads in order to support light-weight processes, much like Erlang, and still take advantage of multiple cores (one scheduler per thread).
In any case, did you have a look at PyPy? They have a lower-level Python-like language called RPython for writing JITted VMs, I thought maybe you would be interested.
Anyway, really cool projects you have here, I’ll definitely check ‘em out. Thank you
April 10th, 2011 at 11:43
Ivan,
Thanks for the feedback. I’m familiar with PyPy, but the whole goal of Bob is to teach myself (and hopefully others) about VM implementation. I did not intend to create yet another Scheme implementation – if you ask me there’s too much of them already.
July 24th, 2011 at 15:56
wow, i like it… Thanks a lot…
September 13th, 2011 at 18:58
Hey can I reference some of the content here in this site if I link back to you?
September 14th, 2011 at 11:25
Leon,
Yes
December 4th, 2011 at 08:04
Isn’t CPython refcounted, and not GC’d?
December 4th, 2011 at 09:26
Elazar,
From Wikipedia:
Additionally, CPython actually has a separate GC mechanism that runs occasionally to collect cycles that were missed by the ref counter.