A meta-language where programs manipulate programs.
Phi is a self-describing language for defining languages. Write a grammar, get a parser, typechecker, and compiler — all derived from the same specification.
The trick: Everything is a tree with annotations. Parsers, transformers, type systems — they're all the same thing viewed differently.
# Install RosettaVM (the runtime)
cd ports/rust/tools/rvm
cargo build --release
./target/release/rosettavm run examples/hello.rvmDefine a language in Phi:
Nat = Zero | Succ Nat
add : Nat → Nat → Nat
add Zero n = n
add (Succ m) n = Succ (add m n)
This specification is the implementation. No separate parser, no separate evaluator.
specs/ Language definitions
phi.phi Phi defines itself
meta.phi Meta-evaluator
rvm.phi VM specification
ports/
rust/tools/rvm/ RosettaVM (production runtime)
scala/ Scala implementation
haskell/ Haskell implementation
examples/ Sample programs and languages
The Rust runtime with CPU and GPU backends:
rosettavm run program.rvm # CPU
rosettavm cuda program.rvm # Compile to CUDA
./program 1000000 # 1M parallel tasksPerformance: 4,375x speedup at scale on GPU.
Three structures derive everything:
Fix[F] = F[Fix[F]] Recursive data
Free[F, A] = A | F[Free[F, A]] Effect sequences
Cofree[F, A]= (A, F[Cofree[F, A]]) Annotated trees
From these: parsers, zippers, attribute grammars, version control, content addressing.
One math, many tools.
make # Build all
make rust # Build RosettaVM
make scala # Build Scala port
make test # Run testsIf you find Phi useful: PayPal
Note: This project uses a modified MIT license with exclusions.
MIT — with the following parties explicitly excluded from all rights:
- Banks operating in euros
- Those who abstain from pork
- Anti-Musk individuals
These parties have no rights whatsoever under this license.