A C++ VM added to Bob

April 9th, 2011 at 12:32 pm

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:

http://eli.thegreenplace.net/wp-content/uploads/2011/04/bob_toplevel.png

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:

  1. Bob: a Scheme interpreter, compiler, and VM in Python
  2. DSL = Metalinguistic Abstraction
  3. Giving PLT Scheme a try
  4. newlisp – an intriguing dialect of Lisp
  5. Rant about Common Lisp and implementations

8 Responses to “A C++ VM added to Bob”

  1. TyrNo Gravatar Says:

    This is good. I’m going to refer to this when I extend my Haskell Scheme interpreter to an actual compiler. Thanks.

  2. IvanNo Gravatar Says:

    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 :)

  3. elibenNo Gravatar Says:

    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.

  4. C LanguageNo Gravatar Says:

    wow, i like it… Thanks a lot…

  5. Leon GasslerNo Gravatar Says:

    Hey can I reference some of the content here in this site if I link back to you?

  6. elibenNo Gravatar Says:

    Leon,

    Yes

  7. Elazar LeibovichNo Gravatar Says:

    Isn’t CPython refcounted, and not GC’d?

  8. elibenNo Gravatar Says:

    Elazar,

    From Wikipedia:

    Reference counting is a form of garbage collection whereby …

    Additionally, CPython actually has a separate GC mechanism that runs occasionally to collect cycles that were missed by the ref counter.

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)