Plush languageexperimental
Maxime Chevalier-Boisvert's minimal dynamically-typed language and register-based VM for teaching and creative coding: actors instead of locks, no FFI, and window, audio and socket host functions built in.
Overview
Plush is Maxime Chevalier-Boisvert's dynamically typed language and register-based bytecode VM, made for fun, teaching and creative coding, with window, audio and socket host functions built in. It exists to explore actor-based parallelism in a language inspired by JavaScript, Lox, Lua, Python and Rust, with no global VM lock and no foreign function interface.
Code
let n = 42; // Int64; 0.5 would be a Float64
let s = "plush"; // immutable UTF-8 string
let ok = n > 10 && s != ""; // Bool from comparison and logical operators
$println(n / 4); // 10.5 — `/` always yields a float
$println(n.idiv(4)); // 10 — truncated integer division
let xs = [0, 1, 2, 3]; // Array: JS-shaped literal
let d = { name: "plush", version: 1 }; // Dict: string keys, JSON syntax
let buf = ByteArray.with_size(16); // raw mutable bytes
$println(xs[2]); // 2 — indexing
$println(d["name"]); // "plush" — or d.name
buf.store_u32(0, 0xFF00FF); // typed write into the buffer
for (let var i = 0; i < xs.len; ++i)
$println(xs[i]); // .len, and a mutable counter
from random import Xoshiro128; // std module: baked into the binary
fun add(a, b) { return a + b; } // fun: a named, immutable global
class Point {
init(self, x, y) { // self is explicit, not an implicit `this`
self.x = x; self.y = y;
}
to_s(self) { return "(" + self.x.to_s() + ", " + self.y.to_s() + ")"; }
}
let p = Point(1, 2); // a class name called is a constructor
let double = |x| x * 2; // lambda: the expression returns implicitly
$println(add(1, 2) + double(p.x)); // 5
$println(Xoshiro128(1234).int(0, 100)); // the std class, consumed
fun worker() {
let msg = $actor_recv(); // block on this actor's mailbox
$println("got: " + msg);
return msg.len; // the actor's result
}
let w = $actor_spawn(worker); // own heap: a copy of the parent's globals
$actor_send(w, "hello"); // no lock, no shared memory
$println($actor_join(w)); // 5
self explicitly
with single inheritance;
libraries come from a relative file or a standard module.
The last slot is the point: a spawned actor gets its own mailbox and collector.Distinctive traits
- Actors, not locks: each actor owns a mailbox and a heap, and messages are deep-copied, so shared-memory races cannot occur.
- No FFI, no package manager:
$-prefixed host functions are the only exit, and imports name either a relative file or a built-in standard module. - Immutable by default:
letbinds once andlet varopts in, which keeps globals and functions redefinition-free and optimizable. - Register-based bytecode VM written in Rust with no global VM lock; the guide claims it can outperform Lua.
- Creative coding is library, not package: frame buffers are BGRA32 byte arrays and audio is float32 samples.
- Corner-case budget: assignment is a statement, not an expression, and
/always yields a float, so=and==cannot be confused.
Status
Work in progress at version 0.6.x under Apache-2.0, with prebuilt binaries for Linux, macOS and Windows, a REPL, a VS Code extension and bundled examples. The author calls it a fun side-project and warns of bugs and missing features.