Phib

A Quilt demo: a cellular-automaton language whose compilers are written in Quilt.

A world is a grid of values, and every rule of it is a recipe: a picture of cells before, and after. Play the puzzles, redraw their rules, or race Phib's three engines.

🐸 Puzzles

Help Phibber the frog to the lotus. Every puzzle is a Phib world, and its recipes are beside the board: open them, redraw a rule, and play with yours instead.

Play ▶

⚡ Stress test

Automata on a big random board, up to a million cells, run by each engine: the interpreter, the compiler to JavaScript, and the compiler to WGSL on your GPU. Compare checks that all three make the same boards, then times them.

Run it ▶

About

How Phib works

A grid of values. Each cell holds a term of an algebraic data type the world declares, such as type Ground += Belt(face: Dir).

Rewrite rules. Each recipe is a small picture: cells before, cells after, with variables that bind parts of terms. Every tick, each recipe that matches somewhere, in any of four turns, rewrites those cells.

One meaning, three engines. An interpreter runs the rules as written. Two compilers turn them into JavaScript and into WGSL for the GPU. All three must make the same boards; the stress test checks.

// The primes, by trial division: each number counts its divisors down.
type C = O | I(Nat<64>, Nat<64>)
cell C
recipe count
  I(n, _)  O  ->  *  I(n + 1, n)
recipe divide
  I(n, d)  ->  I(n, d - 1)
  where n mod d != 0

Where Quilt comes in

Quilt is a metaprogramming language: you write code that writes code with quotes, ↖…↗, and splice values into them with ↙…↘. Phib's code generators are Quilt, expanded ahead of time into plain JavaScript modules, so the page needs no Quilt at run time:

  • anchors.ts.quilt writes the JavaScript the compiler emits for each recipe's tests.
  • wgsl.ts.quilt writes the WGSL compute shader the GPU engine runs.
  • print.ts.quilt writes Phib itself: the printers the editor uses to save a redrawn recipe as text.
// print.ts.quilt: a Phib type, as written.
export function printType(ty) {
  switch (ty.k) {
    case "Nat":
      return ↖Nat<↙ty.n↘>↗;
    case "Int":
      return ↖Int<↙ty.lo↘, ↙ty.hi↘>↗;
    case "opt":
      return ↖↙printType(ty.of)↘?↗;
    …

Source: QuiltLang/phib. Quilt: QuiltLang/quilt.

Hint

Arrows or a tap beside Phibber hop, W waits, Z undoes, R restarts.