bytecode

package
v2.0.0-alpha.13 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCollectionPreallocation = 1 << 20

MaxCollectionPreallocation limits the preallocated capacity accepted for persisted OpLoadArray and OpLoadObject instructions. This prevents untrusted artifacts from forcing excessive upfront allocations during execution.

View Source
const MaxEncodedSortDirections = bits.UintSize - 1

MaxEncodedSortDirections limits the number of sort directions that can be encoded into OpDataSetMultiSorter using the current signed-int bit-packing. The highest bit must remain clear so the encoded operand stays non-negative, which caps the supported direction count at one less than the machine word size during persisted-program validation.

View Source
const NoopOperand = Operand(0)

NoopOperand is a reserved operand for no operation and final results.

View Source
const Version = 1

Variables

View Source
var (
	// ErrInvalidProgram reports that a program is structurally invalid for
	// persistence or validation.
	ErrInvalidProgram = errors.New("bytecode: invalid program")
	// ErrInvalidInstruction reports that a program contains an invalid or
	// unsupported instruction or operand.
	ErrInvalidInstruction = errors.New("bytecode: invalid instruction")
	// ErrInvalidConstant reports that a persisted constant frame is malformed or
	// uses an unsupported type.
	ErrInvalidConstant = errors.New("bytecode: invalid constant")
)

Functions

func IsCallOpcode

func IsCallOpcode(op Opcode) bool

func IsConditionalJumpOpcode

func IsConditionalJumpOpcode(op Opcode) bool

func IsProtectedCall

func IsProtectedCall(op Opcode) bool

func IsProtectedCallOpcode

func IsProtectedCallOpcode(op Opcode) bool

func IsTerminatorOpcode

func IsTerminatorOpcode(op Opcode) bool

func IsUnconditionalJumpOpcode

func IsUnconditionalJumpOpcode(op Opcode) bool

func JumpTargetOperandIndex

func JumpTargetOperandIndex(op Opcode) int

func ValidateProgram

func ValidateProgram(program *Program) error

ValidateProgram checks that a bytecode program is structurally valid for persistence and later execution. ISA compatibility is validated separately by loaders and the VM.

func VisitCallArgumentRegisters

func VisitCallArgumentRegisters(op Opcode, src1, src2 Operand, visit func(reg int))

Types

type AggregateKind

type AggregateKind int
const (
	AggregateCount AggregateKind = iota
	AggregateSum
	AggregateMin
	AggregateMax
	AggregateAverage
)

type AggregatePlan

type AggregatePlan struct {
	Index            map[string]int   `json:"index"`
	Keys             []runtime.String `json:"keys"`
	Kinds            []AggregateKind  `json:"kinds"`
	TrackGroupValues bool             `json:"trackGroupValues,omitempty"`
}

func NewAggregatePlan

func NewAggregatePlan(keys []runtime.String, kinds []AggregateKind, trackGroupValues bool) AggregatePlan

type CallArgEncoding

type CallArgEncoding uint8
const (
	CallArgEncodingNone CallArgEncoding = iota
	CallArgEncodingRegisterRange
)

type CallKind

type CallKind uint8
const (
	CallKindNone CallKind = iota
	CallKindHost
	CallKindUser
	CallKindTail
)

type Catch

type Catch [3]int

Catch stores an inclusive instruction range [start, end] and an optional recovery jump target.

type CollectorType

type CollectorType int
const (
	CollectorTypeCounter CollectorType = iota
	CollectorTypeKey
	CollectorTypeKeyCounter
	CollectorTypeKeyGroup
	CollectorTypeAggregate
	CollectorTypeAggregateGroup
)

type ControlFlowRole

type ControlFlowRole uint8
const (
	ControlFlowNone ControlFlowRole = iota
	ControlFlowJumpUnconditional
	ControlFlowJumpConditional
	ControlFlowTerminator
)

type Functions

type Functions struct {
	Host        map[string]int `json:"host,omitempty"`
	UserDefined []UDF          `json:"userDefined,omitempty"`
}

Functions groups host and user-defined function metadata required for execution.

type Instruction

type Instruction struct {
	Opcode   Opcode     `json:"opcode"`
	Operands [3]Operand `json:"operands"`
}

func NewInstruction

func NewInstruction(opcode Opcode, operands ...Operand) Instruction

func (Instruction) String

func (i Instruction) String() string

type Metadata

type Metadata struct {
	Labels                 map[int]string  `json:"labels"`
	CompilerVersion        string          `json:"compilerVersion"`
	AggregatePlans         []AggregatePlan `json:"aggregatePlans"`
	AggregateSelectorSlots []int           `json:"aggregateSelectorSlots,omitempty"`
	CallArgumentSpans      [][]source.Span `json:"callArgumentSpans,omitempty"`
	MatchFailTargets       []int           `json:"matchFailTargets,omitempty"`
	DebugSpans             []source.Span   `json:"debugSpans"`
	OptimizationLevel      int             `json:"optimizationLevel"`
}

type Opcode

type Opcode byte
const (
	// Control Flow
	OpReturn Opcode = iota
	OpJump
	OpJumpIfFalse
	OpJumpIfTrue
	OpJumpIfNone

	// Register Operations
	OpMove // Plain register copy — no tracking

	// Tracked Register Operations
	OpMoveTracked // Tracked register copy — ownership-aware

	// Loading Operations
	OpLoadNone   // Set None value to a register
	OpLoadBool   // Set a boolean value to a register
	OpLoadZero   // Set a zero value to a register
	OpLoadConst  // Load a constant to a register or a global variable
	OpLoadParam  // Load a parameter slot to a register A
	OpMakeCell   // Create an internal mutable cell handle from a value
	OpLoadCell   // Load the current value from an internal mutable cell
	OpStoreCell  // Replace the current value in an internal mutable cell
	OpLoadArray  // Create an array
	OpLoadObject // Create an object
	OpLoadRange  // Create a range

	// Collection Access Operations
	OpLoadIndex            // Load a value from a built-in Array to a register
	OpLoadIndexOptional    // Load a value from a built-in Array to a register, if it exists
	OpLoadKey              // Load a value from a built-in Object to a register
	OpLoadKeyOptional      // Load a value from a built-in Object to a register, if it exists
	OpLoadProperty         // Load a property from a map or list to a register
	OpLoadPropertyOptional // Load a property from a map or list to a register, if it exists
	OpLoadIndexConst       // Load a value from a built-in Array to a register using a constant index
	OpLoadIndexOptionalConst
	OpLoadKeyConst // Load a value from a built-in Object to a register using a constant key
	OpLoadKeyOptionalConst
	OpLoadPropertyConst // Load a property from a map or list to a register using a constant key
	OpLoadPropertyOptionalConst
	OpMatchLoadPropertyConst // Load an object-pattern property or jump to the arm fail target

	// Integrated Query Operations
	OpQuery // Apply a query to a value

	// Arithmetic Operations
	OpAdd
	OpAddConst
	OpConcat
	OpSub
	OpMul
	OpDiv
	OpMod
	OpIncr
	OpDecr

	// Type Operations
	OpCastBool
	OpNegate
	OpFlipPositive
	OpFlipNegative

	// Comparison Operations
	OpCmp
	OpNot
	OpEq
	OpNe
	OpGt
	OpLt
	OpGte
	OpLte

	// Membership & Pattern Matching
	OpIn
	OpLike
	OpRegexp

	// Array Operations
	OpFlatten // Flattens nested arrays

	// Array Comparison Operations (do not swap order of EQ, GT, GTE, LT, LTE, IN. it must be equal to operators)
	OpAnyEq
	OpAnyNe
	OpAnyGt
	OpAnyGte
	OpAnyLt
	OpAnyLte
	OpAnyIn
	OpNoneEq
	OpNoneNe
	OpNoneGt
	OpNoneGte
	OpNoneLt
	OpNoneLte
	OpNoneIn
	OpAllEq
	OpAllNe
	OpAllGt
	OpAllGte
	OpAllLt
	OpAllLte
	OpAllIn

	// Utility Operations
	OpLength
	OpType
	OpClose
	OpSleep

	// Host Function Operations
	OpHCall
	OpProtectedHCall

	// UDF Operations
	OpCall
	OpProtectedCall
	OpTailCall

	// Dataset Operations
	OpDataSet
	OpDataSetCollector
	OpDataSetSorter
	OpDataSetMultiSorter
	OpPush           // Adds a value to a generic List
	OpPushKV         // Adds a key-value pair to a dataset
	OpCounterInc     // Increments a counter collector
	OpArrayPush      // Adds a value to a built-in Array instance
	OpObjectSet      // Sets a property on a built-in Object instance
	OpObjectSetConst // Sets a property on a built-in Object instance using a constant key

	// Stream Operations
	OpStream     // Subscribes to a stream
	OpStreamIter // Consumes a stream

	// Iterator Operations
	OpIter            // Creates an iterator
	OpIterNext        // Moves to the next element
	OpIterNextTimeout // Moves to the next element and records timeout completion
	OpIterValue       // Returns the current value
	OpIterKey         // Returns the current key
	OpIterLimit
	OpIterSkip

	// Existence Operations
	OpExists

	// Random Operations
	OpRand

	// Dispatch Operations
	OpDispatch

	// Compare-Jump Operations
	OpJumpIfNe
	OpJumpIfNeConst
	OpJumpIfEq
	OpJumpIfEqConst
	OpJumpIfMissingProperty
	OpJumpIfMissingPropertyConst
	OpFail        // Raises a runtime failure with a constant message
	OpFailTimeout // Raises a runtime timeout failure

	// Internal Aggregate Operations
	OpLoadAggregateKey // Creates an internal grouped-aggregate selector key
	OpAggregateUpdate
	OpAggregateGroupUpdate
)

func (Opcode) String

func (op Opcode) String() string

type OpcodeClass

type OpcodeClass uint8
const (
	OpcodeClassUnknown OpcodeClass = iota
	OpcodeClassControl
	OpcodeClassLoad
	OpcodeClassAccess
	OpcodeClassArithmetic
	OpcodeClassType
	OpcodeClassComparison
	OpcodeClassArray
	OpcodeClassUtility
	OpcodeClassCall
	OpcodeClassDataset
	OpcodeClassStream
	OpcodeClassIterator
)

type OpcodeInfo

type OpcodeInfo struct {
	Class           OpcodeClass
	ControlFlow     ControlFlowRole
	CallKind        CallKind
	CallArgEncoding CallArgEncoding
	ProtectedCall   bool
}

func OpcodeInfoOf

func OpcodeInfoOf(op Opcode) OpcodeInfo

type Operand

type Operand int

func NewConstant

func NewConstant(idx int) Operand

func NewRegister

func NewRegister(idx int) Operand

func (Operand) Constant

func (op Operand) Constant() int

func (Operand) Equals

func (op Operand) Equals(other Operand) bool

func (Operand) IsConstant

func (op Operand) IsConstant() bool

func (Operand) IsRegister

func (op Operand) IsRegister() bool

func (Operand) Register

func (op Operand) Register() int

func (Operand) String

func (op Operand) String() string

type Program

type Program struct {
	Source     *source.Source
	Functions  Functions
	Bytecode   []Instruction
	Constants  []runtime.Value
	CatchTable []Catch
	Params     []string
	Metadata   Metadata
	ISAVersion int
	Registers  int
}

func (*Program) MarshalJSON

func (p *Program) MarshalJSON() ([]byte, error)

func (*Program) UnmarshalJSON

func (p *Program) UnmarshalJSON(data []byte) error

type UDF

type UDF struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName,omitempty"`
	Entry       int    `json:"entry"`
	Registers   int    `json:"registers"`
	Params      int    `json:"params"`
}

UDF describes a user-defined function compiled into bytecode.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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