陰 Yin VM
Yin is what happens when Clojure, Smalltalk, and Datomic got together and had a baby. It is a continuation virtual machine whose programs and runtime state are plain immutable data. The Universal AST projects into datoms, queryable with Datalog, and the design does the same for runtime state. Eval is the machine, and persistent data structures keep continuations fast, mobile, and immutable.
Together with the Yang compiler Yin forms a dual system: Yang compiles Clojure, Python, and PHP source into Universal ASTs, while Yin receives, introspects, and executes them.
Main ideas
- Universal AST (ASG) : while called an AST for familiarity, Yin uses an Abstract Semantic Graph whose datom projection captures syntax, semantics, and metadata across languages.
- Persistent CESK : control, environment, store, and continuation reuse structure for speed.
- First-class continuations : computation pauses and resumes as a value. Handing a running machine to another VM works today as a demo; migration across hosts is the design target of the Universal Continuation Format.
- Unified call constructs : functions, closures, and continuations are all reified execution contexts, plain values the machine can hold, pass, and resume.
- Eval as VM : stepping eval drives the machine with no hidden interpreter.
- Macros as stream topology : expansion is a separate process between two streams, so the evaluator never sees a macro and the expander can run anywhere.
Universal AST: The Abstract Semantic Graph
Every program Yin runs is expressed as the Universal AST (Abstract Syntax Tree): a language-agnostic representation that records syntax, semantics, and metadata in immutable data. Traditional compilers treat ASTs as transient trees. In Yin, the AST is persistent data that can be projected into a queryable graph where meaning is encoded directly in the relationships between datoms. It is, therefore, more accurate to call it an Abstract Semantic Graph (ASG) but we will call it AST for familarity
The Universal AST is a map, and datoms are a projection of it . The Yang compiler emits the AST as a nested map, and the AST-walking evaluator executes that map directly. From the map, Yin derives two flat forms. One is datoms: every AST node becomes a set of facts with an entity ID, attributes (node type, operator, operands), and relationships to other nodes. The other is content-addressed tuples: every node becomes a row named by the hash of its own content, so identical subtrees are stored once. Both projections are lossless for what the evaluators need, and the map can be reconstructed from the datoms.
The datom projection is what makes the AST queryable. Streamed into DaoSpace , the datoms are indexed as covering indexes for efficient Datalog queries. The tuple projection is what travels between the compiler, the macro expander, and the evaluators.
The design carries the same idea through to runtime state: continuations, environments, and stores projected into datoms alongside the AST, so that every transformation preserves reversibility, provenance, and rich introspection. Today that state is plain immutable data inside the machine, and an optional telemetry stream emits snapshots of it as datoms.
Bytecode is lowered from the flat forms without rebuilding the map. The datom lane lowers AST datoms into linear executable datoms, and the tuple lane lowers rows into the instruction vector the semantic VM runs. A JIT is planned but not built. Transforming the AST into flat execution bytecode achieves bytecode-like performance while preserving full semantic queryability. See AST Datom Streams: Bytecode Performance with Semantic Preservation for how this works. The datom representation may look like low-level assembly code, but it operates at a fundamentally higher abstraction—see Universal AST vs Assembly for why this matters.
This decomposition transforms the code from a hierarchical tree into a flat, queryable Abstract Semantic Graph (ASG). Any node can be accessed directly, parent-child relationships are explicit edges, and the entire code structure becomes a knowledge graph navigable via Datalog queries. While it serves the role of an AST, it operates as an ASG where structure and meaning are preserved as durable relationships between datoms.
This changes how code is analyzed and transformed. Traditional compilers and VMs build custom data structures: symbol tables, control flow graphs, dominance trees, call graphs, each requiring specialized traversal algorithms. In Yin, all of these are just Datalog queries over the same datom store. Finding all function definitions, tracing variable usage, identifying dead code, or analyzing call chains becomes declarative pattern matching. The AST is not a format the compiler consumes and discards; it is a queryable database that remains live throughout the program's lifetime.
Learn more: Yin.vm: Chinese Characters for Programming Languages explains how the Universal AST enables cross-language semantic preservation, and AST as Higher Dimensional Construction of Datom Streams reveals how the AST exists across five dimensions simultaneously.
CESK machine with persistent data structures
Yin implements the CESK model (Control, Environment, Store, Continuation) with persistent data structures. This is fundamentally different from traditional stack-based VMs like the JVM, Python's CPython, or JavaScript's V8. In a stack machine, function calls push frames onto a call stack, and returns pop them off. In a CESK machine, there is no traditional call stack. The continuation is the stack, but reified as a first-class data structure.
This distinction is critical. In stack machines, the call stack is an implicit runtime construct hidden inside the VM. You cannot capture it, serialize it, or pass it as a value. It exists only as machine state. In Yin's CESK machine, the continuation is explicit, making the "stack" a queryable, transferable, versionable piece of data.
- Control : current AST node or continuation frame
- Environment : persistent lexical scope map
- Store : immutable memory graph
- Continuation : reified, persistent control context (the stack as data)
Structural sharing replaces wholesale copying, so each step produces tiny deltas rather than cloning entire environments. The result is fast snapshots, near-instant rollbacks, and execution that parallelizes cleanly while remaining fully immutable.
Continuations as portable computation
Agents are continuations. In Datom.World, there is no distinction between an agent and a continuation. What we call an 'agent' is simply a mobile continuation equipped with capability tokens that define its authority. This unification is fundamental. Agents don't just use continuations for mobility. They are continuations.
Continuations are first-class values that represent the entire computational state. Because agents are continuations, the design lets them move across network boundaries, running on embedded devices, edge racks, or supercomputers without changing shape: pause, serialize, migrate, and resume, carrying control flow and authority while referencing data in place. What exists today is the first half. A machine's full CESK state is plain data with no host objects in it, a demo hands a running machine from one VM to another as an EDN payload, and the dependency analysis a portable lift needs is implemented. The portable wire format (the Universal Continuation Format) and the capability tokens are still design.
Functions, closures and continuations are a unified concept: each is a reified execution context held as a value. The machine still treats them differently at the point of use (a closure is applied, a continuation is resumed), but because all three are data, metaprogramming, reflection, and code mobility stop being special cases.
What unification enables
The claim that functions, closures, and continuations are unified deserves deeper examination. Treating them as the same underlying construct—a reified execution context—has profound architectural consequences. This isn't just conceptual elegance; it fundamentally changes what the VM can do.
One primitive replaces many
Instead of implementing separate mechanisms for exceptions, async/await, generators, coroutines, threads, actors, and backtracking, Yin needs only continuation manipulation. Every control-flow construct becomes a pattern:
- Exceptions : jump to a continuation representing the nearest handler
- Async/await : suspend the continuation, resume when value arrives
- Generators : yield by suspending, resume from that point on next call
- Actors : a loop of message-triggered continuations
- Green threads : continuations stored in a scheduler, resumed cooperatively
- Backtracking : saved continuations at decision points, restored on failure
This drastically simplifies the VM core while maximizing expressive power. Surface-level language features collapse into a small universal kernel.
Computation becomes data
Because both the AST and the runtime state (continuations, environments, and stores) are plain data that can be projected into datoms in DaoSpace , the boundary between program and process starts to disappear. The AST is queryable with Datalog today. Runtime state is observable today through telemetry snapshots, and the rest of this list is what the design opens up:
- Query with Datalog : inspect active continuations, find bottlenecks, trace execution paths, analyze runtime state
- Version control : every execution state is immutable data, making checkpointing trivial
- Time-travel debugging : step backward through continuation history, query past runtime states
- Code evolution : code is addressed by its content, so a new version is new code beside the old. A running continuation keeps the code it names; the machine refuses to swap different code in under an id a continuation already holds
- AI-assisted modification : LLMs can read, understand, and transform continuations and runtime state
The end state is one DaoSpace holding AST nodes, bytecode, continuation frames, CESK state, type information, and runtime facts. Just as the AST projects into datoms (entity-attribute-value facts), so can continuations, environments, and stores. Code, data, and execution state would then share a unified representation as queryable, versioned facts in the same knowledge graph.
Traditional compilers require custom visitor patterns, tree walkers, and specialized data structures for each analysis pass. Yin replaces all of these with Datalog queries. Want to find all recursive functions? Query for functions that reference themselves. Need to trace data flow? Query for variable definitions and their usages across continuation frames. Looking for performance bottlenecks? Query for hot continuation paths and their execution counts. The entire program—source, IR, runtime state—is a database, not a black box.
Lightweight by design
Because the continuation is the stack in a CESK machine, Yin has complete control over what gets captured. Traditional stack-based VMs must snapshot the entire call stack when capturing continuations. Every frame, every local, every return address. Yin's design inverts this model. Continuations carry only control state (program counter, code reference, hot locals). Everything else lives externally in streams.
This is the target, not the current machine: today a parked continuation still carries its whole environment, stack, and continuation chain. In the design, a continuation becomes a collection of offsets into streams. When it migrates, the following happens:
- The continuation moves (a few kilobytes)
- The streams stay put (megabytes or gigabytes)
- Symbols resolve intelligently. The compiler determines storage class statically, so hot paths stay fast
This avoids Smalltalk's monolithic image problem while preserving its vision of capturing computational state. Continuations become thin enough to migrate across network boundaries cheaply.
Portable authority
This part is planned and not yet built. When continuations unify with capability tokens , authority becomes intrinsic to computation. An agent migrating to a new node doesn't re-authenticate its identity. It presents the capabilities it carries. Possession proves authorization.
- Stream access tokens grant read/write permissions
- Resource tokens meter CPU, memory, and bandwidth
- Migration credentials authorize execution on remote nodes
- Delegation is fine-grained. Attenuate tokens before passing to subordinates
Traditional systems tie permissions to identity and location. Datom.World ties permissions to possession. Authority migrates with the continuation, making distributed security composable by default.
Universal semantic encoding
Continuations are powerful enough to encode the semantics of nearly any programming language. This is why Yin serves as a universal intermediate representation:
- Laziness = thunks (suspended continuations)
- Logic programming = choice points (saved search states)
- Concurrency = interleaved continuation scheduling
- Effects = delimited continuations with handlers
- Monads = continuation-passing style
Clojure, Python, and PHP already compile to the same Universal AST through Yang, and any other language can join them by emitting it. Yin executes them uniformly, transforms them with the same tools, and introspects them with the same queries.
The fundamental inversion
Most VMs optimize for locality. They pull data toward computation, minimize migration costs, and treat code as fixed. Yin optimizes for mobility. It pushes computation toward data, externalizes state, and treats code as flowing.
This changes the cost model.
- Traditional . Data movement dominates, code stays put
- Yin . Code movement is cheap, data stays distributed
In a world where data often exceeds computation by orders of magnitude—training datasets, knowledge graphs, event logs— moving a few kilobytes of continuation to where terabytes of data live makes more sense than copying terabytes to where code runs.
See Continuations as Universal Semantic Kernel for why continuations can encode nearly any language feature, and Computation Moves, Data Stays for how Yin keeps continuations lightweight without sacrificing performance.
Eval is the virtual machine
There is no hidden interpreter. Invoking eval steps the CESK machine directly, executing the AST as data. The evaluator itself knows nothing about macros. Expansion is a separate process between two streams : it reads unexpanded programs from one, rewrites them to a fixpoint, and appends macro-free programs to the other, which is all the evaluator ever sees. There is no compile time and no runtime, only data moving down a pipe, so new code can be evaluated at any moment by appending it to the input stream.
ASTs are pure data, so transformation work can be distributed across nodes. The expander speaks only the stream protocol, so nothing ties it to the machine the evaluator runs on. This opens the way to distributed compilation and collaborative code evolution.
See how execution achieves bytecode-like performance while preserving full queryability in AST Datom Streams: Bytecode Performance with Semantic Preservation .
In summary
Yin turns code into data and data into computation. The Universal ASG anchors every stage, persistent data structures make CESK state efficient and immutable, and the unification of functions, closures, and continuations makes agents mobile by design. One primitive: continuation manipulation, replaces dozens of special-purpose constructs. Eval is the machine, macros live outside it as stream topology, and the AST stays plain data that any process can transform.
Ready to emit new continuations? Explore the Yang compiler to see how Clojure code becomes Universal ASTs and enters the Yin runtime.
To understand how Yin makes continuations lightweight and mobile, read Computation Moves, Data Stays . To see why continuations are the foundation for representing all language semantics, explore Continuations as Universal Semantic Kernel . For a comprehensive defense against skeptical objections to this architecture, see Why yin.vm Succeeds Where Previous Attempts Failed .
Documentation & Source
Dive deeper into the Yin VM implementation:
- Complete Documentation : AST specification, CESK state machine, and implementation details
- Source Code : Browse the portable Clojure implementation (
.cljc), which runs on the JVM, Node, and Dart