Language
SMURF
A small language for state: spaces, a 256×256 grid, nodes with typed fields, and transitions in three fixed phases — require, apply, ensure. A refused transition changes nothing and writes no log row.
The genesis space
Two nodes on one grid, and one transition that moves energy between them. This is the file every recording on this site was taken from.
// SMURF genesis: two nodes on a logical grid, one transition that conserves energy.
//
// Every `@ref` names the exact bytes a declaration was written from, by content id. Comment the refs
// out to compile without a databank; the compiler then reports fewer verified claims, not a lie.
space Genesis {
grid world: Grid<256, 256>;
node source at (10, 20) {
energy: f64 = 100.0;
label: string = "source";
}
node target at (11, 20) {
energy: f64 = 0.0;
label: string = "target";
}
transition transfer(amount: f64) {
require amount >= 0.0;
require source.energy >= amount;
source.energy -= amount;
target.energy += amount;
ensure source.energy + target.energy == 100.0;
}
}Source sha256 7cf56e78f625c07c9815f6aa49fc77f3d3129178b4e36fa86299ef75a07d9c09.
What the compiler printed
source.energy = f64:90.0 target.energy = f64:10.0
ok examples/genesis.smurf: space `Genesis` with 2 node(s), 1 transition(s), 0 ref(s); genesis root=dcb9f8d48daf2cc728db2ddf53da9b35783cd616ddd02b6cab921546e81396b5Recorded by tools/smurf-fixtures.sh from smurf (../smurf); re-run that script and compare. The recording is 18654 bytes, sha256 d2977e431fde7e2c84d0c8d05aa8d2d8acb1fcc1ef794320b995b05b39bebf15.
The examples in this repository
examples/genesis.smurf is the space above. examples/ledger.smurf is the one that uses every field type the language has — a u64, an i64, a bool, a string and an f64 — so it is the file that would notice a backend dropping one. Both are highlighted here, on the server, with no script.
// SMURF ledger: every field type the language has, in a program small enough to read.
//
// Two nodes, two transitions, one invariant each. `deposit` proves the money came from nowhere (the
// balance only ever rises by the amount asked for); `freeze` proves a boolean can be required and set
// in the same transition. The point of the example is that the emitted C, C++, Rust, Python and
// JavaScript programs print exactly what the interpreter prints for the same ticks — including the
// u64, f64, bool and string fields — and that a transition that violates its `ensure` is refused in
// every one of them, not just in SMURF.
space Ledger {
grid world: Grid<128, 128>;
node cash at (5, 5) {
balance: u64 = 1000;
fee: i64 = -3;
currency: string = "USD";
frozen: bool = false;
}
node savings at (5, 6) {
balance: u64 = 250;
rate: f64 = 0.025;
currency: string = "USD";
}
transition deposit(amount: u64) {
require amount > 0;
require cash.frozen == false;
cash.balance += amount;
ensure cash.balance >= amount;
}
transition charge(fee: i64) {
require fee >= 0;
cash.fee += fee;
ensure cash.fee >= -3;
}
transition adjust(rate: f64) {
require rate > 0.0;
savings.rate = rate;
ensure savings.rate == rate;
}
transition rename(label: string) {
require label != "";
cash.currency = label;
ensure cash.currency == label;
}
transition set_frozen(flag: bool) {
require flag == true;
cash.frozen = flag;
ensure cash.frozen == true;
}
transition freeze() {
require cash.frozen == false;
cash.frozen = true;
ensure cash.frozen == true;
}
}The three phases, and why the order is fixed
require
Runs first, over the whole transition. A failing require stops the run before one byte changes, so a refusal costs nothing and leaves the root untouched.
apply
Writes the fields. Every write is typed: an f64 field takes an f64, and the compiler does not coerce it.
ensure
Runs last. A failing ensure refuses the commit; it never repairs it. The log gets a row only when the commit happens.
The grammar
A file is one space. A space holds a grid, nodes and transitions. There are no statements outside a transition, no functions, and no loops.
space Name {
grid world: Grid<256, 256>;
node name at (x, y) {
field: type = value;
}
transition name(arg: type) {
require ...;
...
ensure ...;
}
}
The six types
Fields may be exactly one of f32, f64, i64, u64, bool or string. A field takes its own type; the compiler does not coerce a string into a number or an integer into a float.
Addresses and layers
A node lives at (x, y, z, layer) on the grid. Two nodes may share a position if their layer differs, so one place can hold several readings without one overwriting the other. The whole graph has a canonical content id: change one field and the root changes with it.
What it refuses to have
- A refused transition changes no field and writes no log row. A refusal is an exit code, not a partial write.
- A corrupted log is refused at the line that broke, never silently skipped.
- An integer edge — a division by zero, an overflow, a u64 below zero — refuses in every backend rather than returning a wrong number.
- Nesting past 256 levels is refused with a position instead of exhausting the stack.
A trace, not a story
The trace names the phases and counts the statements in each, so require #2 is a position you can find in the source.
transition transfer (1 parameter(s))
phase 1 require x2
phase 2 apply x2
phase 3 ensure x1
changed source.energy = f64:90.0
changed target.energy = f64:10.0
committed root=f99950eab83d71d1a239f0981249a185e457f663cf31fc5d40ca9c579b8d6d3d (was dcb9f8d48daf2cc728db2ddf53da9b35783cd616ddd02b6cab921546e81396b5)