ir

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IROpToBytecode

func IROpToBytecode(op Op) int32

IROpToBytecode returns the bytecode OP_* constant corresponding to the given IR op. Returns vm.OP_NOOP for ops without a direct bytecode counterpart.

func IsCheapMaterializeOp

func IsCheapMaterializeOp(op Op) bool

IsCheapMaterializeOp reports whether op is one of the cheap-to- re-emit loads (Const, LoadArg, LoadVar, LoadClosed). Used by the lowerer's body-emit policy and use-site materialization fallback.

Types

type Op

type Op uint16

Op is the kind of an IR node.

const (
	OpInvalid    Op = iota
	OpConst         // .Aux = vm.Value (the constant; lowered as OP_LOAD_CONST with interned index)
	OpLoadArg       // .Aux = int (arg index)
	OpLoadVar       // .Aux = *vm.Var; var roots are mutable
	OpLoadClosed    // .Aux = int (closed-over index)
	OpBlockArg      // block parameter
	OpSetVar        // .Refs[0] = var (Const aux=*vm.Var), .Refs[1] = value; pushes var back
	OpCall          // .Refs[0] = fn, .Refs[1:] = args; .Aux = arity int
	OpTailCall      // tail call ends a block
	OpAdd
	OpSub
	OpMul
	OpBitAnd                // clojure.core/bit-and — integer bitwise and
	OpBitOr                 // clojure.core/bit-or — integer bitwise or
	OpBitXor                // clojure.core/bit-xor — integer bitwise xor
	OpBitAndNot             // clojure.core/bit-and-not — integer bit clear (&^)
	OpBitShiftLeft          // clojure.core/bit-shift-left — integer left shift
	OpBitShiftRight         // clojure.core/bit-shift-right — integer arithmetic right shift
	OpUnsignedBitShiftRight // clojure.core/unsigned-bit-shift-right — integer logical right shift
	OpQuot                  // clojure.core/quot — integer quotient truncated toward zero. int/int lowers to native Go `/` (which truncates identically); any float/ratio/boxed operand lowers via rt.QuotValue (native float `/` does NOT truncate)
	OpDiv                   // clojure.core// — true division. float/float lowers to native Go `/`; any other operand mix (int/int -> Ratio, mixed -> Float) lowers via rt.DivValue. Distinguished from Quot by op-kw in lower-go (both render Go `/`)
	OpLt
	OpLte
	OpGt
	OpGte
	OpEq
	OpInc
	OpDec
	OpBitNot      // clojure.core/bit-not — integer bitwise complement
	OpPop         // discard top stack value; no result (OP_POP)
	OpReturn      // .Refs[0] = value
	OpBranch      // unconditional; .Aux = *BranchTarget
	OpBranchIf    // .Refs[0] = cond; .Aux = struct{True,False *BranchTarget}
	OpMakeClosure // .Refs[0] = *Func value (the func to wrap as a closure)
	OpPushClosed  // .Refs[0] = closure, .Refs[1] = value to attach
	OpTry         // .Refs[0] = body closure; then optional handler closure (binds the caught value), then optional finally closure; .Aux = {:has-handler bool :has-finally bool}
	OpDot         // .Refs[0] = obj; .Aux = field symbol; Go struct field selector obj.field (gogen_ir path only)
	OpDef         // .Refs[0] = var (Const aux=*vm.Var), optional .Refs[1] = value; interns + returns the var (2-ref also sets root)
)

func OpByKeyword

func OpByKeyword(name string) (Op, bool)

OpByKeyword looks up an Op by its keyword name. The match is case-insensitive AND dash-insensitive, so "load-arg", "loadarg", and "LoadArg" all match opTable entry "LoadArg".

Used by Lisp-side IR construction primitives, where ops are passed as kebab-case keywords (the Clojure idiom).

func (Op) IsPure

func (op Op) IsPure() bool

IsPure reports whether op has no observable side effects.

func (Op) IsTerminator

func (op Op) IsTerminator() bool

IsTerminator reports whether op ends a basic block.

func (Op) StackOut

func (op Op) StackOut() int

StackOut returns the number of values op pushes (0 or 1).

func (Op) String

func (op Op) String() string

String returns the op's display name (or "Op?" for an unknown op).

Jump to

Keyboard shortcuts

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