#bytecode-interpreter #bytecode #interpreter #vm #sum

nightly zub

A fast, stack-based virtual machine for dynamic languages, with an intuitive IR-builder, garbage collection and NaN-tagging

56 releases

0.3.14 May 19, 2020
0.3.13 May 19, 2020
0.2.21 May 14, 2020
0.1.18 May 12, 2020

#261 in Programming languages

Download history 4/week @ 2023-10-14 7/week @ 2023-10-21 46/week @ 2023-10-28 18/week @ 2023-11-04 60/week @ 2023-11-11 6/week @ 2023-11-18 118/week @ 2023-11-25 58/week @ 2023-12-02 3/week @ 2023-12-09 60/week @ 2023-12-16 115/week @ 2023-12-23 2/week @ 2023-12-30 60/week @ 2024-01-06 51/week @ 2024-01-13 122/week @ 2024-01-20 116/week @ 2024-01-27

349 downloads per month

MIT license

105KB
3K SLoC

Zub VM

A super-fast, stack-based virtual machine for dynamic languages

Features

  • NaN-tagging value representation
  • Mark n' sweep garbage collection
  • Compact bytecode format
  • Easy-to-use intermediate representation

Milestones

  • Refined VM based on work by Mr Briones
  • Tracing garbage collector
  • High-level IR
  • Compilation of IR
  • Optimizer (currently 80-90% Python speed, aiming for much faster)
  • Profiler and disassembler

Example

Building IR is easy

Getting your backend up and running shouldn't have to be hard.

The following code builds IR for evaluating sum = 20.0 + 30.0:

let mut builder = IrBuilder::new();

let a = builder.number(20.0);
let b = builder.number(30.0);

let sum = builder.binary(a, BinaryOp::Add, b);

builder.bind(Binding::global("sum"), sum);

When you feel like the IR is looking smooth. Simply let VM throw it through the compiler, and run it.

let mut vm = VM::new();
vm.exec(&builder.build());

Languages

Hugorm

Hugorm is a dynamic, python-like language being built for small data science and game projects.

https://github.com/nilq/hugorm

Examples

The examples/ folder includes two small language implementations running on the ZubVM.

Atto

Atto is a functional, minimal language that showcases how little code is needed to implement a working, Turing-complete language. The syntax can be seen in the following teaser:

fn sum x is
    if = x 0
        1
    + sum - x 1 sum - x 1

fn main is
    sum 12

Mini

Mini is a simple language that looks basically like a mix of Rust and JavaScript. It covers a bit wider set of features than Atto. This does show in the size of the language though.

let bar = 13.37;

fn foo() {
  fn baz(c) {
    return c + bar;
  }
  
  return baz(10);
}

global gangster = foo();

Special thanks

Dependencies

~5–15MB
~182K SLoC