ir

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BinOpKinds = map[string]bool{
	"+": true, "-": true, "*": true, "/": true,
	"<": true, ">": true, "<=": true, ">=": true,
	"and": true, "or": true, "==": true, "!=": true, "=": true,
}

Functions

func ValidateGraph

func ValidateGraph(graph *Graph) error

ValidateGraph is the function form of Graph.Validate.

func ValidateShared

func ValidateShared(node *ast.Node) (string, bool)

ValidateShared returns a semantic error for malformed shared forms. The boolean reports whether the node is a shared form, including invalid ones.

Types

type BasicBlock

type BasicBlock struct {
	Label        BlockLabel
	Instructions []Instruction
	Terminator   *Terminator
}

BasicBlock is ordered in Graph.Blocks and contains instructions in source evaluation order.

type BlockLabel

type BlockLabel string

BlockLabel is a stable, human-readable basic block identifier.

type Graph

type Graph struct {
	Entry  BlockLabel
	Blocks []*BasicBlock
}

Graph is a flat SSA control-flow graph for one expression or function body.

func LowerSSA

func LowerSSA(node *ast.Node) (*Graph, error)

LowerSSA lowers a checker-annotated shared AST expression into a flat SSA graph. It does not mutate the source tree or affect existing tree-IR users.

func LowerSSAFunction

func LowerSSAFunction(params []Param, body *ast.Node) (*Graph, error)

LowerSSAFunction lowers one function body into its own flat SSA graph, pre-binding each parameter as a resolvable SYMBOL reference via an OpParam instruction in the entry block, so the body's ordinary SYMBOL-lowering path in lower() resolves parameter references exactly like any other name bound by builder.env (e.g. a let binding).

func (*Graph) Validate

func (graph *Graph) Validate() error

Validate verifies structural and value-reference invariants for a graph.

type IRCase

type IRCase struct {
	Label     *ast.Node
	Body      *ast.Node
	IsDefault bool
}

type IRNode

type IRNode struct {
	Kind  string
	Op    string
	Kids  []*ast.Node
	Cases []IRCase
	Type  ast.TypeInfo
}

func LowerShared

func LowerShared(node *ast.Node) (*IRNode, bool)

LowerShared performs the shared arity/shape validation and child extraction for the ~19 node kinds with identical cross-backend semantics. It intentionally does not unify the small number of validation asymmetries already present between the Go and JS backends (e.g. Go type-checks the append/map_set/map_delete target is a SYMBOL and JS does not; JS's binop arity check is absent where Go's exists) — preserving each backend's exact pre-refactor behavior takes priority over cosmetic validation parity, so those extra checks stay in the per-backend emit functions. LowerShared preserves the semantic type annotation produced by the checker. Backends that need native layout information can consume IRNode's Type without walking back to the source node.

type Instruction

type Instruction struct {
	Result   Value
	Op       SSAOp
	Operands []ValueID
	Blocks   []BlockLabel
	Literal  string
	Symbol   string
}

Instruction defines exactly one SSA value. Blocks is populated for phi instructions and is positionally aligned with Operands.

type Param

type Param struct {
	Name string
	Type ast.TypeInfo
}

Param describes one function parameter for LowerSSAFunction: the name it is referenced by within the function body, and its checker-inferred type.

type SSAOp

type SSAOp string

SSAOp identifies a flat instruction operation.

const (
	OpConst         SSAOp = "const"
	OpSymbol        SSAOp = "symbol"
	OpPhi           SSAOp = "phi"
	OpUnit          SSAOp = "unit"
	OpAdd           SSAOp = "add"
	OpSubtract      SSAOp = "subtract"
	OpMultiply      SSAOp = "multiply"
	OpDivide        SSAOp = "divide"
	OpLess          SSAOp = "less"
	OpGreater       SSAOp = "greater"
	OpLessEqual     SSAOp = "less_equal"
	OpGreaterEqual  SSAOp = "greater_equal"
	OpEqual         SSAOp = "equal"
	OpNotEqual      SSAOp = "not_equal"
	OpAnd           SSAOp = "and"
	OpOr            SSAOp = "or"
	OpSet           SSAOp = "set"
	OpCall          SSAOp = "call"
	OpParam         SSAOp = "param"
	OpList          SSAOp = "list"
	OpDict          SSAOp = "dict"
	OpMapGet        SSAOp = "map_get"
	OpListGet       SSAOp = "list_get"
	OpPrint         SSAOp = "print"
	OpToInt         SSAOp = "to_int"
	OpToFloat       SSAOp = "to_float"
	OpToString      SSAOp = "to_string"
	OpBytesToString SSAOp = "bytes_to_string"
)

type SourceLocation

type SourceLocation struct {
	Filename string
	Line     int
	Column   int
}

SourceLocation retains enough of the source AST location for diagnostics.

type Terminator

type Terminator struct {
	Kind        TerminatorKind
	Cond        ValueID
	Value       ValueID
	Target      BlockLabel
	TrueTarget  BlockLabel
	FalseTarget BlockLabel
	Source      SourceLocation
}

Terminator is an explicit control-flow edge. Value is optional for a void return and Cond is required for a branch.

type TerminatorKind

type TerminatorKind string

TerminatorKind identifies the control transfer ending a basic block.

const (
	TermJump   TerminatorKind = "jump"
	TermBranch TerminatorKind = "branch"
	TermReturn TerminatorKind = "return"
)

type Value

type Value struct {
	ID     ValueID
	Type   ast.TypeInfo
	Source SourceLocation
}

Value is the result defined by an instruction.

type ValueID

type ValueID uint64

ValueID is a graph-wide identifier for one SSA definition. The zero value is reserved for terminators and expressions that do not produce a value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL