@tisyn/ir
v0.4.0
Published
`@tisyn/ir` defines the intermediate representation at the heart of Tisyn.
Readme
@tisyn/ir
@tisyn/ir defines the intermediate representation at the heart of Tisyn.
It is the shared program format that the rest of the system agrees on: the compiler produces it, the validator checks it, the kernel interprets it, the runtime executes it, and protocols move its values across boundaries.
If Tisyn has a common language, this is it.
Where It Fits
@tisyn/ir is the representation layer for the whole system.
@tisyn/compilerlowers authored workflows into IR@tisyn/validatechecks that IR is well-formed@tisyn/kerneldefines how IR evaluates@tisyn/runtimeexecutes IR durably@tisyn/protocoland@tisyn/transportmove IR-compatible values across boundaries
Almost every other Tisyn package depends on this one, directly or indirectly.
What It Contains
This package provides the core building blocks for working with Tisyn programs as data:
- expression and value types such as
TisynExpr,Val,Json, andTisynFn - constructor helpers such as
Fn,Ref,Let,Call,Try,Eval,All, andRace - traversal and transformation utilities such as
walk(),fold(), andtransform() - inspection and developer tooling such as
classifyNode(),collectRefs(),print(), anddecompile()
Core Concepts
Expressions are data
A Tisyn program is represented as a tree of JSON-compatible expression nodes. TisynExpr is the broad union of those nodes and literals.
That makes workflows explicit, serializable, inspectable, and transportable across package and process boundaries.
Functions are data too
TisynFn represents a function-shaped IR value with parameter names and a body expression. Function values are not opaque host-language closures; they remain part of the IR.
Values stay boundary-friendly
Json represents plain JSON-compatible values. Val represents the broader runtime value domain that environments and protocols can accept.
These types define what can safely move through Tisyn systems.
Main APIs
The API surface is broad, but it falls into a few clear groups.
Types and values
Json— plain JSON-compatible valuesVal— runtime values accepted by environments and protocolsTisynExpr— the full union of legal Tisyn expressions and literalsExpr— typed expression input accepted by constructor helpersTisynFn— a function-shaped IR value with parameters and a bodyIrInput— validated input shapes accepted by IR-consuming APIs
Constructors
Use these to build IR programmatically:
Q— quote an expression as IR dataRef— reference a named value from the current environmentFn— construct a function-shaped IR valueLet— bind a value and continue in an extended environmentSeq— evaluate a series of expressions in orderIf— choose between two expressions conditionallyWhile— represent looping while a condition remains trueCall— invoke a function-shaped IR valueGet— read a named property from an object expressionAdd,Sub,Mul,Div,Mod,NegGt,Gte,Lt,Lte,Eq,NeqAnd,Or,NotConstruct,Arr,ConcatThrowTry— handle exceptions with optional catch and finally clausesEval— invoke an external operation or structural form by idAll— evaluate multiple expressions concurrently and collect their resultsRace— evaluate multiple expressions concurrently and resolve with the first result
Classification and guards
Use these when inspecting unknown values or narrowing types:
classifyNodeclassifyisStructuralisExternalisCompoundExternalisEvalNodeisFnNode
Traversal and transformation
Use these to analyze or rewrite IR trees:
walk— visit every node with enter/leave hooksfold— reduce an IR tree to a single valuefoldWith— extend a default fold with custom behaviortransform— rewrite an IR tree during traversalcollectRefs— gather referenced namescollectExternalIds— gather external eval idscollectFreeRefs— gather references not bound locally byFnorLet
Developer tooling
Use these for debugging, testing, and inspection:
print— stable constructor-style renderingdecompile— readable TypeScript-like rendering
Example
import { Add, Q } from "@tisyn/ir";
const ir = Add(Q(20), Q(22));Function-shaped IR values are data too:
import { Add, Fn, Ref } from "@tisyn/ir";
const double = Fn(["x"], Add(Ref("x"), Ref("x")));Relationship to the Rest of Tisyn
@tisyn/compilerlowers authored workflows into IR@tisyn/validatechecks that trees match the allowed grammar@tisyn/kernelinterprets the nodes@tisyn/runtimeexecutes them with replay and dispatch
Boundaries
@tisyn/ir is intentionally focused on representation. It does not define:
- validation policy
- execution semantics
- durable storage
- remoting protocol
Its job is to give the rest of Tisyn a common program format and vocabulary.
