Documentation
¶
Overview ¶
Code generated by go generate; DO NOT EDIT.
Package evm implements a register VM for compiled Go programs. Its bytecode is trusted input, not a sandbox boundary or a persisted compatibility format.
Code generated by go generate. DO NOT EDIT.
Immutable KVO records travel as cells and borrow storage until the compiler inserts an ownership copy. Mutable handles retain their editor and materialized field values.
Index ¶
- Constants
- Variables
- func ModelValueShape(row *RecordType) *values.Shape
- func NativeModelPointerLayout(model *kvo.Model, typ reflect.Type) *values.NativeLayout
- func NativeModelValueLayout(model *kvo.Model, typ reflect.Type) *values.NativeLayout
- func NativeMutableRecord(v values.Value, model *kvo.Model) (kvo.Record, error)
- func NativeMutableRecordValue(model *kvo.Model, r kvo.Record) (values.Value, error)
- func PreserveCallbackPanic(value any) error
- func RecordScalarType(t kvo.AnyType) *values.Type
- func RecordValue(v values.Value, model *kvo.Model) (kvo.Record, error)
- func RecordWordType(p kvo.PropImpl) *values.Type
- func RegisterNativeCopies(pkg *Package)
- func StandardLibraryPaths() []string
- func StandardLibrarySource(path string) (string, bool)
- func ValidateDirectBindings(packages []Package) error
- func ValidateShape(s *values.Shape) error
- func ValueModels(packages []Package) (map[*kvo.Model]*ValueModel, error)
- type BorrowSource
- type Budget
- type BudgetScope
- type Callable
- func (f Callable) AcceptsBorrowedBytes(domain string) bool
- func (f Callable) CheckConcurrentUse() error
- func (f Callable) CheckSignature(want Signature) error
- func (f Callable) HasCaptures() bool
- func (f Callable) Name() string
- func (f Callable) Program() *Program
- func (f Callable) Signature() Signature
- func (f *Callable) Value(p *Program, signature Signature) (values.Value, error)
- type CallbackScope
- type CaptureSlot
- type Closure
- type ConcurrentFunctionOf
- type Conversion
- type Coverage
- type DeferKind
- type DeferOp
- type DirectBinding
- type DirectFunc
- type DynamicMethod
- type DynamicType
- type ExecutionError
- type ExtendedKind
- type ExtendedOp
- type ExternalConstant
- type ExternalFunction
- type ExternalMethod
- type ExternalValue
- type Function
- type FunctionOf
- type FunctionRef
- type GuestValue
- type HostShapes
- type Import
- type Instruction
- type InstructionCoverage
- type Invoke
- type JSONTypes
- type Layout
- type Limits
- type LineCoverage
- type LinkEnvironment
- type LinkOptions
- type MethodTables
- type Module
- type Native
- type NativeFunctionType
- type NativeSliceDecl
- type NativeValueCodec
- type NumericKind
- type NumericType
- type Opcode
- type Operand
- type OwnershipEffects
- type OwnershipSite
- type Package
- type PanicError
- type Program
- func (p *Program) AcquireVM(ctx context.Context) *VM
- func (p *Program) AssertValue(v values.Value, target *values.Type) (values.Value, bool, error)
- func (p *Program) Callable(v values.Value) (Callable, error)
- func (p *Program) DefaultLimits() Limits
- func (p *Program) DisassembleFloatLoops() string
- func (p *Program) EncodeJSON(ctx context.Context, v values.Value, limit int) (json.RawMessage, error)
- func (p *Program) HostData() any
- func (p *Program) InterfaceType(v values.Value) *values.Type
- func (p *Program) JSONValue(ctx context.Context, v values.Value, limit int) (any, error)
- func (p *Program) LookupFunction(name string, want *Signature) (Callable, error)
- func (p *Program) NativeFunction(typ *NativeFunctionType, fn Native) (values.Value, error)
- func (p *Program) NativeFunctionData(v values.Value) any
- func (p *Program) PackInterface(t *values.Type, v values.Value) (values.Value, error)
- func (p *Program) PointerInterface(t *values.Type, ptr unsafe.Pointer) (values.Value, error)
- func (p *Program) Shape(t *values.Type) *values.Shape
- func (p *Program) UnpackInterface(v values.Value) (*values.Shape, values.Value, error)
- type RecordScope
- func (s *RecordScope) Close()
- func (s *RecordScope) Edit(model *kvo.Model, m *row2.Editor) values.Value
- func (s *RecordScope) EditRecord(model *kvo.Model, m *kvo.Editor) values.Value
- func (s *RecordScope) Mutable(v values.Value, model *kvo.Model) (*row2.Editor, error)
- func (s *RecordScope) MutableRecord(v values.Value, model *kvo.Model) (*kvo.Editor, error)
- func (s *RecordScope) Read(model *kvo.Model, m row2.View) values.Value
- func (s *RecordScope) ReadRecord(model *kvo.Model, m kvo.Record) values.Value
- type RecordType
- type ScopeEnd
- type ScopedCallback
- type SharedType
- type Signature
- type SourceBranch
- type SourceFile
- type SourcePosition
- type TypeAlias
- type TypeDecl
- type VM
- func (c *VM) AllocCells(n uint64) (unsafe.Pointer, error)
- func (vm *VM) AllocatedBytes() uint64
- func (c *VM) AnyValue(x any) (values.Value, error)
- func (c *VM) BorrowBytes(data []byte) (values.Value, error)
- func (vm *VM) CallArgument(i int) values.Value
- func (c *VM) CallbackError(err error) error
- func (vm *VM) CallbackScope() *CallbackScope
- func (c *VM) ChargeAllocation(bytes uint64) error
- func (vm *VM) CheckConcurrentBorrow(parameter int) error
- func (c *VM) Coverage() *Coverage
- func (c *VM) EncodeJSON(v values.Value, limit int) (json.RawMessage, error)
- func (c *VM) EncodeJSONObject(v values.Value, limit int) (json.RawMessage, error)
- func (c *VM) ErrorValue(err error) (values.Value, error)
- func (c *VM) FlushMutableRecord(v values.Value, model *kvo.Model) error
- func (c *VM) FlushRecord(editor *kvo.Editor) error
- func (c *VM) IncreaseCPUBudget(ms uint64) error
- func (c *VM) IncreaseMemBudget(bytes, allocs uint64) error
- func (c *VM) Interface(slot int) (*values.Type, values.Value, error)
- func (c *VM) JSONValue(v values.Value, limit int) (any, error)
- func (c *VM) JSONValueWithSize(v values.Value, limit int) (any, int, error)
- func (c *VM) LoadNative(s *values.Shape, p unsafe.Pointer) (values.Value, error)
- func (vm *VM) LookupMethod(value values.Value, name string, signature Signature) (Callable, error)
- func (c *VM) MutableRecord(v values.Value, model *kvo.Model) (*kvo.Editor, any, error)
- func (c *VM) NarrowBudget(steps uint64, duration time.Duration) *BudgetScope
- func (c *VM) NarrowCPUBudget(soft, hard time.Duration) *BudgetScope
- func (c *VM) NativeAny(v values.Value) (any, error)
- func (c *VM) NativeArguments(params []*values.Type, args []any) ([]values.Value, error)
- func (c *VM) NativeError(value values.Value) (error, error)
- func (c *VM) NativeFunction(typ *NativeFunctionType, fn Native) (values.Value, error)
- func (c *VM) NativeFunctionWithData(typ *NativeFunctionType, fn Native, data any) (values.Value, error)
- func (c *VM) NativeSlice(layout, element *values.NativeLayout, data unsafe.Pointer, ...) (values.Value, error)
- func (vm *VM) OpenCallbackScope(limits Limits) (*CallbackScope, error)
- func (vm *VM) PackAggregate(t *values.Type, members ...values.Value) (values.Value, error)
- func (vm *VM) PackMap(t *values.Type, items ...values.Value) (values.Value, error)
- func (c *VM) PanicCallback(err error)
- func (c *VM) Program() *Program
- func (c *VM) Record(v values.Value, model *kvo.Model) (kvo.Record, error)
- func (c *VM) RecordValue(model *kvo.Model, m kvo.Record) (values.Value, error)
- func (vm *VM) Release()
- func (vm *VM) Run(fn Callable, slots []values.Value) error
- func (c *VM) SetBackedEditRecordResult(model *kvo.Model, e *kvo.Editor, backing any) error
- func (vm *VM) SetBudget(l Limits)
- func (c *VM) SetCallResult(i int, v values.Value)
- func (vm *VM) SetCoverage(c *Coverage) error
- func (c *VM) SetEditRecordResult(model *kvo.Model, e *kvo.Editor) error
- func (c *VM) SetError(result int, err error) error
- func (c *VM) SetInterface(slot int, t *values.Type, v values.Value) (err error)
- func (c *VM) SetReadRecordResult(model *kvo.Model, m row2.View) error
- func (c *VM) SetRecordResult(model *kvo.Model, m kvo.Record) error
- func (c *VM) SetValue(slot int, v values.Value)
- func (c *VM) SliceElement(s *values.Shape, v values.Value, index uint64) (values.Value, error)
- func (c *VM) StoreNative(s *values.Shape, p unsafe.Pointer, v values.Value) error
- func (c *VM) TypedInterfaceValue(x any) (values.Value, error)
- func (vm *VM) UnpackAggregate(t *values.Type, v values.Value) ([]values.Value, error)
- func (vm *VM) UnpackMap(t *values.Type, v values.Value) ([]values.Value, error)
- func (c *VM) Value(slot int) values.Value
- type ValueModel
Constants ¶
const FieldValueCopy uint8 = 1
FieldValueCopy distinguishes a value read from a fused address load.
const MethodImportBase = 1 << 31
MethodImportBase is the Index of the reference to Module.MethodImports[0].
const RecordListDirect uint8 = 1
RecordListDirect fuses a single adjacent len/index consumer with its property read. No list value escapes the instruction, so no VM temporary is needed.
const RecordValueReceiver uint8 = 2
RecordValueReceiver reads a property from an immutable row value snapshot.
const VMFieldBase = kvo.RuntimePropBase
VMFieldBase separates VM layout fields from persistent KVO property codes.
Variables ¶
var ( ErrSteps = errors.New("instruction limit exceeded") ErrDepth = errors.New("call depth limit exceeded") ErrRegisters = errors.New("register limit exceeded") ErrDivideByZero = errors.New("integer division by zero") ErrAllocations = errors.New("allocation count limit exceeded") ErrAllocation = errors.New("allocation budget exceeded") ErrNegativeShift = errors.New("negative shift amount") ErrInvalidState = errors.New("invalid VM state") ErrNilFunction = errors.New("call of nil function") ErrFunction = errors.New("invalid function value") ErrReentry = errors.New("VM is already running") )
var ( ErrNil = errors.New("nil pointer dereference") ErrBounds = errors.New("index or slice bounds out of range") ErrNilMap = errors.New("assignment to nil map") )
var AnySliceType = values.NewType("[]any", values.Pair)
AnySliceType is the shared VM slice identity for native packages exchanging []any.
var ByteSliceType = values.NewOwnedType("[]uint8", values.Pair, func(v values.Value, _ values.OwnershipBudget) (values.Value, error) {
return v, v.OwnBytes()
})
ByteSliceType is the shared VM slice identity for native packages exchanging []byte.
var ErrCallbackExpired = errors.New("callback scope has expired")
var ErrCallbackInactive = errors.New("callback requires an active native call on its originating VM")
var ErrCallbackScopeOpen = errors.New("callback scope already open")
var ErrDeferStack = errors.New("defer stack is no longer active")
var ErrOutput = errors.New("output limit exceeded")
var ErrTypeAssertion = errors.New("interface conversion failed")
var ErrorSliceType = values.NewType("[]error", values.Pair)
ErrorSliceType is shared by native error methods and guest interfaces.
var JSONObjectType = values.NewType("map[string]any", values.Pointer)
JSONObjectType is shared by native packages that exchange JSON objects.
var NativeAnyCodec = &NativeValueCodec{ Decode: func(c *VM, v values.Value) (values.Value, error) { return c.AnyValue(*(*any)(v.P)) }, Encode: func(c *VM, v values.Value) (values.Value, error) { x, err := c.NativeAny(v) if err != nil { return values.Value{}, err } if err := c.ChargeAllocation(uint64(unsafe.Sizeof(x))); err != nil { return values.Value{}, err } return values.Value{P: unsafe.Pointer(&x)}, nil }, }
NativeAnyCodec is shared by all host packages exposing ordinary any fields. NativeLayout supplies the address of a Go interface, not its ABI words.
var NativeErrorCodec = &NativeValueCodec{ Decode: func(c *VM, v values.Value) (values.Value, error) { return c.ErrorValue(*(*error)(v.P)) }, Encode: func(c *VM, v values.Value) (values.Value, error) { result, err := c.NativeError(v) if err != nil { return values.Value{}, err } if err := c.ChargeAllocation(uint64(unsafe.Sizeof(result))); err != nil { return values.Value{}, err } return values.Value{P: unsafe.Pointer(&result)}, nil }, }
NativeErrorCodec stores native error interfaces using their Go layout.
Functions ¶
func ModelValueShape ¶
func ModelValueShape(row *RecordType) *values.Shape
ModelValueShape describes the opaque value cells used by native bindings. The compiler resolves the row identity to its own model property layout.
func NativeModelPointerLayout ¶
NativeModelPointerLayout exposes native pointer slots through the model's row API. Stores require matching native backing; decoding is explicit.
func NativeModelValueLayout ¶
NativeModelValueLayout uses ordinary native struct snapshots for row values.
func NativeMutableRecord ¶
NativeMutableRecord accepts only native-backed editable rows. An editor handle may have pending changes and must not be silently unwrapped into a Go pointer.
func NativeMutableRecordValue ¶
NativeMutableRecordValue exposes the live native pointer as an editable row. Encoded records require explicit conversion before entering this boundary.
func PreserveCallbackPanic ¶
PreserveCallbackPanic returns an in-flight callback panic unchanged. Wrapped or replaced native panics must not recover the original guest value.
func RecordScalarType ¶
RecordScalarType supplies the VM type for KVO leaves.
func RecordValue ¶
RecordValue reads an immutable row or its explicit value copy.
func RecordWordType ¶
RecordWordType maps a scalar KVO property to its script type.
func RegisterNativeCopies ¶
func RegisterNativeCopies(pkg *Package)
RegisterNativeCopies exposes NativeCopy on immutable rows with a selected native allocation type. Call after choosing allocations and before sharing or compiling the package. Encoded rows decode explicitly; native rows use ordinary shallow struct copies. No conversion changes the original record.
func StandardLibraryPaths ¶
func StandardLibraryPaths() []string
StandardLibrarySource supplies a virtual package to the compiler. Libraries have no globals; only reachable functions become part of a linked Program.
func StandardLibrarySource ¶
func ValidateDirectBindings ¶
ValidateDirectBindings checks register conventions against the declared packages. A compiler schema may omit implementations until Link binds it to a host.
func ValidateShape ¶
ValidateShape checks native declaration storage before the compiler builds Go types. It accepts recursive pointer graphs and rejects recursive value storage.
func ValueModels ¶
func ValueModels(packages []Package) (map[*kvo.Model]*ValueModel, error)
ValueModels validates the value model declarations of packages and returns them by model. Compilers use it to type properties.
Types ¶
type BorrowSource ¶
BorrowSource declares a result whose storage is valid within a scope. ScopeParameter is zero for the enclosing scope, or the one-based argument index identifying it (including the receiver for methods). Domain names are binding-defined identities, e.g. "edb.transaction".
type Budget ¶
type Budget = Limits
Budget is an alias for Limits retained for existing host configuration.
type BudgetScope ¶
type BudgetScope struct {
// contains filtered or unexported fields
}
BudgetScope temporarily restricts the running invocation. A scope may span several external calls. Only the innermost scope can be closed.
func (*BudgetScope) BorrowRecords ¶
func (s *BudgetScope) BorrowRecords(c *VM) *RecordScope
BorrowRecords opens a transaction-local record scope inside this budget.
func (*BudgetScope) End ¶
func (s *BudgetScope) End(c *VM) error
End checks the section before restoring the parent limits. Call it before committing external effects. An exhausted scope also fails the invocation.
type Callable ¶
type Callable struct {
// contains filtered or unexported fields
}
Callable retains a linked function and its optional captures or bound receiver. Copies share the same captures. The zero value is a nil function.
func (Callable) AcceptsBorrowedBytes ¶
AcceptsBorrowedBytes reports whether the compiler tracks byte arguments from domain.
func (Callable) CheckConcurrentUse ¶
CheckConcurrentUse lets a host require capture verification at registration. Plain guest functions have no captures. A host that accepts bytecode directly must trust its producer, as it does for other compiler metadata.
func (Callable) CheckSignature ¶
func (Callable) HasCaptures ¶
type CallbackScope ¶
type CallbackScope struct {
// contains filtered or unexported fields
}
CallbackScope gives native Go adapters access to guest callbacks. The host must serialize its use. An implicit scope expires when the owner releases the VM.
func (*CallbackScope) Close ¶
func (s *CallbackScope) Close() error
Close ends the host callback lifetime. Previously exported functions and errors remain values, but invoking their script methods fails after Close.
type CaptureSlot ¶
type ConcurrentFunctionOf ¶
ConcurrentFunctionOf marks a host parameter for a retained callback that may run concurrently. The compiler verifies its receiver and captures at the call site.
type Conversion ¶
type Conversion struct{ From, To NumericType }
type Coverage ¶
type Coverage struct {
// contains filtered or unexported fields
}
Coverage collects one linked program's instruction and branch counts. Use a separate collector per concurrent execution and Merge after completion.
func NewCoverage ¶
func (*Coverage) Instructions ¶
func (c *Coverage) Instructions() []InstructionCoverage
Instructions returns a snapshot, including instructions never executed.
func (*Coverage) Lines ¶
func (c *Coverage) Lines() []LineCoverage
type DeferOp ¶
type DeferOp struct {
Kind DeferKind
Target FunctionRef
Function Operand
Signature uint32
Invoke uint32
Receiver uint16 // Pair register captured by DeferInvoke.
Args []Operand
ExternalStack bool
}
DeferOp describes values to capture now, then invoke when its owner exits. ExternalStack selects the Raw stack handle in the instruction's A operand.
type DirectBinding ¶
type DirectBinding struct {
Op Opcode
Call DirectFunc
// Window also exposes the ordinary R/P argument window through Call.
// Generated package functions use it for their leading *evm.VM.
Window bool
// contains filtered or unexported fields
}
DirectBinding binds a small external operation with zero or one result. Call receives arguments in declaration order, receiver first. Missing arguments are zero. Its value result is ignored for a void operation. Its error result reports VM or conversion failures. Fallible APIs use Native. Op alone is sufficient in the package supplied to the compiler. Methods may use a function opcode with their receiver as argument zero; this supports pair-valued receivers such as immutable KVO records.
func DirectUnary ¶
func DirectUnary(fn func(uint64) uint64) DirectBinding
DirectUnary binds an infallible word-to-word operation through DirectBinding. Direct calls use a specialized instruction; indirect and deferred calls use the same declaration and ordinary ABI. The returned binding is immutable registration metadata. Use DirectBinding directly for Call/context access.
type DynamicMethod ¶
type DynamicMethod struct {
ID string
Signature Signature
Variadic bool
Function FunctionRef
}
type DynamicType ¶
type DynamicType struct {
Shape *values.Shape
Methods []DynamicMethod
}
DynamicType defines a concrete interface payload. Indexes belong to a Program.
type ExecutionError ¶
type ExecutionError struct {
Function string
PC int
Position SourcePosition
Err error
}
ExecutionError retains the source location and wrapped host/VM error.
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
func (*ExecutionError) Unwrap ¶
func (e *ExecutionError) Unwrap() error
type ExtendedKind ¶
type ExtendedKind uint8
const ( ExtendedMakeInterface ExtendedKind = iota + 1 ExtendedTypeAssert ExtendedFieldAddr ExtendedField ExtendedIndexAddr ExtendedIndex ExtendedSlice ExtendedMakeSlice ExtendedSliceToArray ExtendedMakeMap ExtendedLookup ExtendedMapUpdate ExtendedDelete ExtendedClear ExtendedLen ExtendedCap ExtendedAppend ExtendedCopy ExtendedRange ExtendedNext ExtendedConvert ExtendedEqual ExtendedComplex ExtendedReal ExtendedImag ExtendedComplexBinary ExtendedComplexNegate ExtendedMinMax ExtendedGetKey ExtendedSetKey ExtendedGetChildKey ExtendedPackedArray ExtendedPackedLoad ExtendedPackedStore ExtendedAddressLoad ExtendedAddressStore ExtendedFieldStore ExtendedNativeAlloc ExtendedOwn ExtendedRecordCopy ExtendedRecordList ExtendedRecordListLen ExtendedRecordListIndex ExtendedNativeAddress )
type ExtendedOp ¶
type ExtendedOp struct {
Record *RecordType
Kind ExtendedKind
Shape *values.Shape
Source *values.Shape
In, Out []Operand
Index uint64
ChildKey uint64 // leaf property for ExtendedGetChildKey
Flags uint8
Packed bool // Local slice/array backing uses the element's scalar bank.
// contains filtered or unexported fields
}
ExtendedOp is an immutable bytecode operand descriptor, not an executable callback. BC selects it for operations needing more than three operands.
type ExternalConstant ¶
type ExternalFunction ¶
type ExternalFunction struct {
// Instantiate binds a generic source declaration for concrete type arguments.
// The returned binding must have a concrete signature and no Instantiate hook.
Instantiate func([]*values.Type) (ExternalFunction, error)
Ownership *OwnershipEffects
// ParamNames preserves declaration names for source frontends such as GoX.
ParamNames []string
// Doc preserves declaration comments for source frontends.
Doc string
Direct DirectBinding
// On exposes a receiver-free operation as pkg.Record.Operation(args).
On *RecordType
Variadic bool
// DynamicTypes declares concrete interface results produced by this wrapper.
DynamicTypes []*values.Type
Name string
Signature Signature
Call Native
// contains filtered or unexported fields
}
func BindStandardFunction ¶
func BindStandardFunction(path, name string, signature Signature) (*ExternalFunction, bool)
BindStandardFunction binds a compiler-checked virtual library primitive. Signatures come from the virtual package, never from reflected Go functions.
func (*ExternalFunction) LinkName ¶
func (f *ExternalFunction) LinkName() string
LinkName identifies the function in imports and disassembly.
type ExternalMethod ¶
type ExternalMethod struct {
// Instantiate returns a receiver-free signature for a generic source method.
// Ownership parameter indexes include the receiver at zero.
Instantiate func([]*values.Type) (ExternalFunction, error)
Ownership *OwnershipEffects
Direct DirectBinding
Name string
Receiver *values.Type
Signature Signature
Variadic bool
Call Native
DynamicTypes []*values.Type
}
ExternalMethod has a receiver-free source signature. Its native ABI prepends Receiver to the argument list, reserving incoming V0 via ParameterLayout.
func (ExternalMethod) Binding ¶
func (m ExternalMethod) Binding() ExternalFunction
Binding returns the native ABI declaration, including its receiver.
type ExternalValue ¶
ExternalValue exposes a host-owned package value. Scripts may copy the value and use its methods, but cannot assign or take the address of its binding. Read must not invalidate borrowed records or change transaction scopes.
func (ExternalValue) LinkName ¶
func (v ExternalValue) LinkName() string
type Function ¶
type Function struct {
// CapturesVerifiedForConcurrency reports whether the compiler verified use of the
// bound receiver and closure captures for concurrent calls.
CapturesVerifiedForConcurrency bool
// ConcurrentBorrowCalls lists instructions whose registration arguments
// were checked for post-borrow writes by the compiler.
ConcurrentBorrowCalls map[int][]int
// CallbackByteDomains lists the borrow domains tracked for []byte parameters.
CallbackByteDomains []string
// OwnershipSites describes compiler-emitted clone locations before linking.
OwnershipSites []OwnershipSite
// LocalRecordReads marks instructions whose result cannot outlive its next execution in this frame.
LocalRecordReads map[int]bool
Method bool // The first parameter is the receiver.
// RecoverPC is a bytecode PC plus one; zero means no recovery continuation.
RecoverPC uint32
// RecoverTransparent marks compiler-generated receiver forwarding wrappers.
RecoverTransparent bool
Captures []CaptureSlot
Internal bool // Generated functions are callable by bytecode only.
Name string
Position SourcePosition
Signature Signature
// RCount/PCount cover this function's parameters, results and locals.
// Outgoing arguments/results follow them and are sized by the linker.
RCount, PCount int
Code []Instruction
// Lines is optional; when present it has one source line per instruction.
Lines []int
// Positions is optional too, and takes precedence over Lines. Without
// either, every instruction has the zero position.
Positions []SourcePosition
}
type FunctionOf ¶
FunctionOf annotates a retained callable in a binding declaration. S is the required function signature. Use any for host-checked registrations.
type FunctionRef ¶
FunctionRef selects a linked code or host function. Function values store its module-local index plus one in R, with zero reserved for nil. Runtime native closures use a separate tagged value and retain their owning program.
A native reference indexes Module.Imports. One at or above MethodImportBase names Module.MethodImports instead; only the method tables of Module.Types hold such references.
func MethodImportRef ¶
func MethodImportRef(index int) FunctionRef
MethodImportRef refers to Module.MethodImports[index].
func (FunctionRef) MethodImport ¶
func (r FunctionRef) MethodImport() (int, bool)
MethodImport returns the index into Module.MethodImports that the reference names, and whether it names one.
type GuestValue ¶
GuestValue retains a guest-only value with its owning program. Returning it to that program preserves its type and reference identity without JSON.
func (*GuestValue) MarshalJSON ¶
func (g *GuestValue) MarshalJSON() ([]byte, error)
MarshalJSON serializes a retained guest value at a native JSON output boundary. It uses the same supported types and cycle checks as explicit VM JSON encoding.
func (*GuestValue) String ¶
func (g *GuestValue) String() string
String formats retained JSON-shaped values at native text output boundaries. Unsupported values produce a diagnostic rather than exposing VM handles.
type HostShapes ¶
type HostShapes struct {
Table []*values.Shape
// Set has bit i%64 of word i/64 set for each Table[i] the module lists.
Set []uint64
// After is the number of leading Module.Shapes that the selection
// follows in the order of the listing; see Module.ListedShapes.
After int
}
HostShapes selects shapes from a table that the modules of one compile environment share: the shapes of the host types a module's source can reach, a few thousand on a large host. The module does not own the table and must not change it.
type Instruction ¶
type Instruction uint64
Instruction is one 64-bit word with its opcode in the low 16 bits. Most opcodes have three 16-bit operands. ABCD12 uses four 12-bit operands. WithBC combines B and C into 32 bits. Branches use a signed displacement from the following instruction. Constants live in separate pools.
func ABC ¶
func ABC(op Opcode, a, b, c uint16) Instruction
func ABCD12 ¶
func ABCD12(op Opcode, a, b, c, d uint16) Instruction
ABCD12 packs four 12-bit operands above the ordinary opcode.
func (Instruction) A ¶
func (i Instruction) A() uint16
func (Instruction) ABCD12 ¶
func (i Instruction) ABCD12() (a, b, c, d uint16)
func (Instruction) B ¶
func (i Instruction) B() uint16
func (Instruction) BC ¶
func (i Instruction) BC() uint32
func (Instruction) C ¶
func (i Instruction) C() uint16
func (Instruction) Op ¶
func (i Instruction) Op() Opcode
func (Instruction) SignedD12 ¶
func (i Instruction) SignedD12() int
type InstructionCoverage ¶
type JSONTypes ¶
type JSONTypes struct{ Boolean, Integer, Unsigned, Float, String, Array, Object uint32 }
JSONTypes identifies the concrete types a KVO JSON value can produce.
type Layout ¶
Layout allocates V pairs first, then independent R and P slots. Slots retains source order, so a wrapper can derive its ABI once during registration.
type LineCoverage ¶
LineCoverage summarizes executable instructions at an original source line. A partially covered line was entered but contains unexecuted instructions or a conditional jump whose outcomes were not both observed.
func (LineCoverage) Covered ¶
func (l LineCoverage) Covered() bool
type LinkEnvironment ¶
type LinkEnvironment struct {
// contains filtered or unexported fields
}
LinkEnvironment is a set of bound host packages prepared for linking many modules.
NewLinkEnvironment validates the packages and resolves their bindings once. Each link then does only the work its module needs, and the programs share what the packages alone determine. A LinkEnvironment never changes after NewLinkEnvironment returns and is safe for concurrent use.
The packages must not change while the environment or its programs are in use.
func NewLinkEnvironment ¶
func NewLinkEnvironment(packages ...Package) (*LinkEnvironment, error)
NewLinkEnvironment validates and binds the packages. It fails where every link against them would fail.
func (*LinkEnvironment) Link ¶
func (e *LinkEnvironment) Link(m *Module) (*Program, error)
Link binds a module to the packages. It does not run it.
func (*LinkEnvironment) LinkWithHostData ¶
func (e *LinkEnvironment) LinkWithHostData(m *Module, hostData any) (*Program, error)
LinkWithHostData links like Link and retains host-owned metadata for the lifetime of the program; see LinkWithHostData.
func (*LinkEnvironment) Packages ¶
func (e *LinkEnvironment) Packages() []Package
Packages returns the packages the environment was built from, including the built-in time package.
type LinkOptions ¶
type LinkOptions struct {
// DefaultLimits supplies the initial budget for each VM. Nil selects the
// built-in limits. An explicit empty Limits disables the optional quotas.
DefaultLimits *Limits
// Shapes lists storage shapes that the modules to link name: usually
// every shape of the compile environment that produces the modules. The
// environment snapshots them once and its programs share the snapshots.
// A program snapshots for itself any other shape its module names.
// The shapes must not change while the environment is in use.
Shapes []*values.Shape
// Methods lists the method tables that the modules to link share, one
// for each compile environment that produces them. The environment
// binds them once and its programs share the result. A program binds
// for itself the method tables of any other module.
Methods []MethodTables
}
LinkOptions configures a prepared link environment.
func (LinkOptions) Link ¶
func (o LinkOptions) Link(m *Module, packages ...Package) (*Program, error)
Link links one module using these options.
func (LinkOptions) NewEnvironment ¶
func (o LinkOptions) NewEnvironment(packages ...Package) (*LinkEnvironment, error)
NewEnvironment prepares the packages for linking; see NewLinkEnvironment.
type MethodTables ¶
type MethodTables struct {
Imports []Import
Types []DynamicType
}
MethodTables are the method tables that the modules of one compile environment share: the list every such module has as its MethodImports, and the host types whose methods name nothing but that list. A module that lists one of the types has the same Methods slice as here.
A link environment prepared with the tables binds them once, and its programs share the result. Nothing may change them afterwards.
type Module ¶
type Module struct {
JSONTypes JSONTypes
// NoOptimization disables optional linker rewrites. The compiler sets this for debug modules.
NoOptimization bool
// StrictCallWindows promises that callers only observe declared results after a script call.
StrictCallWindows bool
// Sources holds original text keyed by source-position filename for optional disassembly comments.
Sources map[string]string
Defers []DeferOp
Types []DynamicType // concrete interface types indexed by R; slot zero, if present, must be empty
Invokes []Invoke
FunctionRefs []FunctionRef
Closures []Closure
Signatures []Signature
Functions []Function
// Imports lists the natives that instructions, function references and
// defers name by index, and any native a method table names here.
Imports []Import
// MethodImports lists native methods for the method tables of Types
// alone; see FunctionRef. A link binds those the tables name, so the
// list may hold more. Modules compiled through one environment share
// one list and the method tables of host types that name nothing else:
// the module does not own them and they must not change.
MethodImports []Import
Words []uint64
Strings []string
Conversions []Conversion
// Shapes lists the shapes instructions index, then others the program
// must know by type.
Shapes []*values.Shape
// HostShapes lists more shapes for the program to know by type.
HostShapes HostShapes
ExtendedOps []ExtendedOp
Globals []*values.Shape
Init string
// SourceBranches is reporting metadata keyed by function name, then instruction PC.
SourceBranches map[string]map[int]SourceBranch
}
func (*Module) Disassemble ¶
Disassemble lists all functions in compiled module order, with source lines and decoded operands.
func (*Module) DisassembleFunction ¶
DisassembleFunction lists the function at the given module index.
type NativeFunctionType ¶
type NativeFunctionType struct {
// contains filtered or unexported fields
}
NativeFunctionType caches the signature and register layout of runtime native functions. Build it once with the bindings and reuse it across invocations.
func NewNativeFunctionType ¶
func NewNativeFunctionType(signature Signature) (*NativeFunctionType, error)
type NativeSliceDecl ¶
type NativeSliceDecl struct {
Layout, Element *values.NativeLayout
}
type NativeValueCodec ¶
type NativeValueCodec struct {
Decode func(*VM, values.Value) (values.Value, error)
Encode func(*VM, values.Value) (values.Value, error)
}
TypeDecl exposes a named type, or an unnamed support type when Name is empty. Shape is declarative storage; native wrappers use the same cells as VM code. NativeValueCodec translates between native field values and VM values. Conversions may inspect the current program and charge allocations. They must not retain Call or change its argument/result window.
func NativeInterfaceCodec ¶
func NativeInterfaceCodec(t reflect.Type) *NativeValueCodec
NativeInterfaceCodec bridges a native method-interface slot without changing the concrete object's storage. Guest-only implementations cannot inhabit a Go interface; values must have a native type implementing the interface.
type NumericKind ¶
type NumericKind uint8
const ( NumericSigned NumericKind = iota + 1 NumericUnsigned NumericFloat )
type NumericType ¶
type NumericType struct {
Kind NumericKind
Bits uint8
}
type Opcode ¶
type Opcode uint16
const ( OpConst Opcode = iota + 1 OpString OpMoveR OpMoveP OpMoveV OpClearP OpAddI64 OpSubI64 OpMulI64 OpDivI64 OpDivU64 OpRemI64 OpRemU64 OpAddF64 OpSubF64 OpMulF64 OpDivF64 OpAnd OpOr OpXor OpShl OpShrI64 OpShrU64 OpEqR OpEqP OpLtI64 OpLtU64 OpEqF64 OpLtF64 OpJump OpJz OpJnz OpCallFunc OpCallHost OpReturn OpConvert OpCheckShift OpAddF32 OpSubF32 OpMulF32 OpDivF32 OpEqF32 OpLtF32 OpConcatStr OpEqStr OpLtStr OpAlloc OpLoad OpStore OpExtended OpGlobal OpFunction OpClosure OpCallVirt OpCallIndirect OpCheckNil OpDeferStack OpDefer OpRunDefers OpPanic OpRecover OpLoopLtI64 OpCallHostRR OpCallHostRP OpJNil OpJNotNil OpLoadIndexR OpStoreIndexR OpLeI64 OpLeU64 OpMulAddF64 OpAddMulF64 OpSubAddF64 OpLoopAddLtI64 OpLoopAddLeI64 OpAddImmI64 OpLoopLeI64 // Direct external calls. Each suffix names its explicit arguments, then its result. OpCallHostU OpCallHostS OpCallHostP OpCallHostUU OpCallHostUS OpCallHostUP OpCallHostSU OpCallHostSS OpCallHostSP OpCallHostPU OpCallHostPS OpCallHostPP OpCallHostUUU OpCallHostUUS OpCallHostUUP OpCallHostUSU OpCallHostUSS OpCallHostUSP OpCallHostUPU OpCallHostUPS OpCallHostUPP OpCallHostSUU OpCallHostSUS OpCallHostSUP OpCallHostSSU OpCallHostSSS OpCallHostSSP OpCallHostSPU OpCallHostSPS OpCallHostSPP OpCallHostPUU OpCallHostPUS OpCallHostPUP OpCallHostPSU OpCallHostPSS OpCallHostPSP OpCallHostPPU OpCallHostPPS OpCallHostPPP OpCallHostMethodU OpCallHostMethodS OpCallHostMethodP OpCallHostMethodUU OpCallHostMethodUS OpCallHostMethodUP OpCallHostMethodSU OpCallHostMethodSS OpCallHostMethodSP OpCallHostMethodPU OpCallHostMethodPS OpCallHostMethodPP OpLoadIndexByte OpStoreIndexByte OpLoadIndexWord OpStoreIndexWord OpLoadIndexPtr OpStoreIndexPtr // Side-effecting direct calls; V means no result. A and B are read-only. OpCallHostV OpCallHostUV OpCallHostSV OpCallHostPV OpCallHostUUV OpCallHostUSV OpCallHostUPV OpCallHostSUV OpCallHostSSV OpCallHostSPV OpCallHostPUV OpCallHostPSV OpCallHostPPV OpCallHostMethodV OpCallHostMethodUV OpCallHostMethodSV OpCallHostMethodPV )
func HostCallOpcode ¶
HostCallOpcode selects a direct instruction from its explicit argument and result banks. Pair means string; Pointer means a true pointer or a record token. A zero result selects a void operation.
func UnaryHostOpcode ¶
UnaryHostOpcode selects the fused argument move, external call and result move.
func (Opcode) HostRegisters ¶
HostRegisters supplies the disassembly and assembler prefixes. When a tied operand crosses R/P, print the result bank, except that a string always prints V.
func (Opcode) TiedHostArgument ¶
TiedHostArgument returns the source argument that must occupy A, counting the receiver as argument zero. Void calls read A without overwriting it.
type OwnershipEffects ¶
type OwnershipEffects struct {
NoRetain bool
NoInvalidate bool
Borrowed []BorrowSource
Ends []ScopeEnd
Callbacks []ScopedCallback
// CallbackBytes is the domain of borrowed []byte arguments passed to guest callbacks.
CallbackBytes string
}
OwnershipEffects describes host behavior for compiler ownership analysis. A nil declaration is conservative: the call may retain arguments and end scopes. Ends lists specific invalidations; NoInvalidate forbids all of them. Borrowed results must support ownership copying. Unknown aliasing may cause acquisition-time copying, reported in Function.OwnershipSites.
func (*OwnershipEffects) Clone ¶
func (e *OwnershipEffects) Clone() *OwnershipEffects
func (*OwnershipEffects) Equal ¶
func (e *OwnershipEffects) Equal(other *OwnershipEffects) bool
func (*OwnershipEffects) Validate ¶
func (e *OwnershipEffects) Validate(sig Signature) error
type OwnershipSite ¶
type Package ¶
type Package struct {
// ConcurrentCallbackParams lists the zero-based indexes of callback parameters
// the host may invoke concurrently. Keys are function names or Receiver.Method.
ConcurrentCallbackParams map[string][]int
// ConcurrentInterfaceParams identifies retained interface arguments by the same convention.
ConcurrentInterfaceParams map[string][]int
// StructValues optionally chooses compact storage for source-defined generic
// structs. A nil result retains ordinary storage. Callbacks run at compile time.
StructValues map[string]func(string, []*values.Shape) *values.CellStruct
SourceFiles []SourceFile
Aliases []TypeAlias
Source string
Records []*RecordType
// ValueModels expose sub-objects of KVO models as struct values that this
// package declares.
ValueModels []ValueModel
// EntryTypes are native concrete types that may enter in interface arguments to Run.
EntryTypes []*values.Type
Types []TypeDecl
Methods []ExternalMethod
Path string
Functions []ExternalFunction
Constants []ExternalConstant
Values []ExternalValue
}
func MergePackages ¶
MergePackages combines packages that share a path into one, keeping the order of first appearance. Compile and Link accept each path once; hosts that build one script package from several bindings merge them first. Declarations are concatenated; at most one fragment of a path may carry Source, and StructValues names must not repeat.
func ModelPackage ¶
ModelPackage declares read and edit handles for every entity in a completed KVO schema. Register once and share its type identities across compilations. Database operations are supplied separately by the host.
func TimePackage ¶
func TimePackage() Package
TimePackage exposes time.Time and its native storage. It is linked automatically, so record fields and host methods share the same nominal type.
func WithTimePackage ¶
WithTimePackage puts the built-in time package first. A supplied package with path "time" extends it: its declarations join the built-in ones, so a host can add types, functions and further Time methods.
func WithoutRecords ¶
WithoutRecords returns p without the row types of the given models and without their methods. A host uses it for value models: scripts read those sub-objects as struct values and never as rows.
func (*Package) OwnsMethodReceiver ¶
OwnsMethodReceiver reports whether t is a named concrete type declared by p, or an explicitly declared pointer to one.
func (*Package) Record ¶
func (p *Package) Record(model *kvo.Model, mutable bool) *RecordType
Record returns the package's handle for the given model and access mode.
func (Package) Sources ¶
func (p Package) Sources() []SourceFile
Sources returns files in declaration order without sharing the input slice. Source, when set, precedes SourceFiles and is named after the package path.
type PanicError ¶
type PanicError struct {
Type *values.Type
Value values.Value
// contains filtered or unexported fields
}
PanicError exposes the concrete value of an uncaught explicit Go panic. Type is external metadata; Value is the unboxed payload belonging to this Program.
func (*PanicError) Error ¶
func (e *PanicError) Error() string
func (*PanicError) Unwrap ¶
func (e *PanicError) Unwrap() error
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is an immutable linked snapshot. Registration and symbol lookup stay outside the execution loop. Independent VMs may share a Program if its native wrappers support concurrent use.
func LinkWithHostData ¶
LinkWithHostData retains host-owned metadata for the lifetime of the linked program. There is no setter; derived runtimes can retain their compiled data without a separate program registry.
func (*Program) AssertValue ¶
AssertValue performs a Go type assertion on a program-local interface value. Concrete targets return their payload; interface targets retain the interface. It neither converts nor copies the underlying value.
func (*Program) DefaultLimits ¶
DefaultLimits returns the program's default per-VM execution limits.
func (*Program) DisassembleFloatLoops ¶
DisassembleFloatLoops lists the private execution plans chosen by Link. The module's source listing and instruction PCs remain valid.
func (*Program) EncodeJSON ¶
func (p *Program) EncodeJSON(ctx context.Context, v values.Value, limit int) (json.RawMessage, error)
EncodeJSON encodes a script's any value. Objects have string keys. Arrays and slices are JSON arrays. The byte limit also bounds expansion of shared subtrees. Unsupported types and cycles fail without exposing VM pointers.
func (*Program) HostData ¶
HostData returns the value supplied when linking. EVM does not interpret it. The linker owns this value and must publish any mutable contents safely.
func (*Program) JSONValue ¶
JSONValue projects a script's any value directly into an owned Go JSON tree. Numbers are json.Number, preserving the encoder's exact spelling and precision. The limit is the equivalent JSON byte length, including escaped strings.
func (*Program) LookupFunction ¶
LookupFunction resolves a named entry and checks its full signature when want is non-nil.
func (*Program) NativeFunction ¶
NativeFunction prepares a host-owned callable for an argument to Run. The caller owns allocation accounting for this input. Calls from the VM share its active execution limits; host code must honor cancellation and meter any work or result allocations it performs. Use VM.NativeFunction for values created during a VM invocation so the holder allocation is metered.
func (*Program) NativeFunctionData ¶
NativeFunctionData returns metadata attached to a native callable from this program. Guest callables and native functions without metadata return nil.
func (*Program) PackInterface ¶
PackInterface prepares a host input. The caller owns allocation limits and snapshots aggregate values before passing them here. Native results should use Call.SetInterface, which charges the active VM budget.
func (*Program) PointerInterface ¶
PointerInterface packs a trusted native pointer for an interface argument to Run. The type must be registered by the host and linked into this particular program.
type RecordScope ¶
type RecordScope struct {
// contains filtered or unexported fields
}
func WithRecords ¶
func WithRecords(ctx context.Context) (context.Context, *RecordScope)
WithRecords shares editor caches and local child slots during a call. Closing it releases those caches without invalidating held row handles.
func (*RecordScope) Close ¶
func (s *RecordScope) Close()
func (*RecordScope) EditRecord ¶
func (*RecordScope) MutableRecord ¶
func (*RecordScope) ReadRecord ¶
type RecordType ¶
type RecordType struct {
// NativeAllocation selects the native struct storage for guest-created
// collections of this row. Nil keeps generic record storage.
NativeAllocation reflect.Type
// SchemaView exposes the properties supported by the current KVO codec.
SchemaView bool
Name string
Model *kvo.Model
Mutable bool
Value *values.Type // guest Model value, distinct from its read handle
Pointer *values.Type // guest *Model: Pair for immutable cells and editable rows
}
func NewRecordType ¶
func NewRecordType(name string, model *kvo.Model, mutable bool) *RecordType
type ScopedCallback ¶
ScopedCallback is invoked synchronously inside a newly established scope; the host closes that scope after the callback returns or unwinds.
type SharedType ¶
type SharedType struct {
}
SharedType maps a host scalar to a type declared in package sources. Its methods are compiled from that same source.
type SourceBranch ¶
SourceBranch associates duplicated machine tests with one source condition. PC identifies its canonical instruction; Inverted reverses jump outcomes.
type SourceFile ¶
type SourceFile struct{ Name, Text string }
SourceFile is one Go source file in a virtual package. Imports are file-local.
type SourcePosition ¶
type TypeAlias ¶
TypeAlias gives an existing type another source name without new storage or runtime identity. The target must be declared in the same environment.
type TypeDecl ¶
type TypeDecl struct {
// NativeSlice describes a host representation without changing guest storage.
NativeSlice *NativeSliceDecl
TypeArgs []*values.Type
// SourceName identifies a type declared in package sources. TypeArgs
// instantiates it using existing native type identities.
SourceName string
NativeCodec *NativeValueCodec
// ScalarBase distinguishes Go int from int64 when their storage shapes match.
ScalarBase *values.Type
Name string
Shape *values.Shape
}
type VM ¶
type VM struct {
// Output receives fmt/log/debug output. Nil uses the normal Go logger.
Output func(string) error
Context context.Context
Position SourcePosition
R []uint64
P []unsafe.Pointer
// contains filtered or unexported fields
}
A VM executes one program on one goroutine. A Go binding may call Run again synchronously.
func (*VM) AllocatedBytes ¶
AllocatedBytes reports allocation charges since acquisition or SetBudget.
func (*VM) AnyValue ¶
AnyValue converts native Go data into a guest interface. Native reference values retain their backing storage; guest handles must belong to this program.
func (*VM) BorrowBytes ¶
BorrowBytes returns a transaction-scoped []byte. Declare the result in OwnershipEffects.Borrowed. Writes and escapes detach all its aliases.
func (*VM) CallArgument ¶
CallArgument reads an argument in the current Go binding.
func (*VM) CallbackError ¶
CallbackError preserves an in-flight guest panic across a native callback. Execution failures retain their trap behavior.
func (*VM) CallbackScope ¶
func (vm *VM) CallbackScope() *CallbackScope
CallbackScope returns the scope used by guest callbacks exported from this VM.
func (*VM) ChargeAllocation ¶
ChargeAllocation accounts for native result payloads retained by the VM.
func (*VM) CheckConcurrentBorrow ¶
CheckConcurrentBorrow checks the guest registration site. Checking only the method body would let an indirect registration reuse a proof from a different receiver without checking later writes to this one.
func (*VM) EncodeJSON ¶
EncodeJSON encodes an any argument from this invocation.
func (*VM) EncodeJSONObject ¶
EncodeJSONObject encodes a statically typed map[string]any argument.
func (*VM) ErrorValue ¶
ErrorValue preserves a native error's identity and optional error methods.
func (*VM) FlushMutableRecord ¶
FlushMutableRecord applies alias edits retained by this row handle.
func (*VM) FlushRecord ¶
FlushRecord applies edits made through Go map and slice aliases before the external database saves this one row. Repeated saves see subsequent edits.
func (*VM) IncreaseCPUBudget ¶
IncreaseCPUBudget adds wall time to the current scope, capped by the host.
func (*VM) IncreaseMemBudget ¶
IncreaseMemBudget raises the invocation allowance without resetting usage.
func (*VM) Interface ¶
Interface reads a native argument by ABI slot, preserving nil versus typed nil. Returned values and type identities belong to this Program.
func (*VM) JSONValue ¶
JSONValue also meters the materialized tree against this invocation's budget.
func (*VM) JSONValueWithSize ¶
JSONValueWithSize materializes an any value and reports its equivalent JSON byte length. Streaming output consumers can share one limit across values without serializing the materialized tree a second time.
func (*VM) LoadNative ¶
LoadNative copies a value from its declared native layout into VM registers. The caller keeps p alive for the call; reference fields retain their targets.
func (*VM) LookupMethod ¶
LookupMethod resolves a method on this receiver and checks its receiver-free signature.
func (*VM) MutableRecord ¶
MutableRecord resolves the native editor and backing without a session lookup.
func (*VM) NarrowBudget ¶
func (c *VM) NarrowBudget(steps uint64, duration time.Duration) *BudgetScope
NarrowBudget starts a scope at the current external call. Zero leaves that limit alone. All work still counts against the enclosing budgets.
func (*VM) NarrowCPUBudget ¶
func (c *VM) NarrowCPUBudget(soft, hard time.Duration) *BudgetScope
NarrowCPUBudget starts an adjustable time scope. Enclosing limits still apply. Memory is charged to the invocation, including across transaction scopes.
func (*VM) NativeAny ¶
NativeAny converts a guest interface to native Go. Registered native types keep their Go types and backing storage. Model row pointers return their live native pointer, or a kvo.Record for encoded data; native-backed row values return Go value copies. Guest-only types retain a handle.
func (*VM) NativeArguments ¶
NativeArguments converts ordinary Go values into arguments for parameters of the given types: scalars, strings, time values, pointers to bound native structs, registered interface implementations and guest values. A Go slice or map converts when a linked package binds its type. A values.Value passes through unchanged. Native references keep their backing storage. A value whose Go type does not correspond to its parameter type is an error; there are no implicit numeric conversions. Conversion charges this call's allocation budget, and the results are valid for this program only.
func (*VM) NativeError ¶
NativeError converts an error argument while preserving its identity. The second result reports conversion failure, not the argument's value.
func (*VM) NativeFunction ¶
NativeFunction binds a native closure to the current program. The closure may retain owned host state, and may borrow the VM only while the binding runs. Guest calls and nested VM.Run calls share the active execution budget. Host code remains responsible for validating captured transaction lifetimes.
func (*VM) NativeFunctionWithData ¶
func (c *VM) NativeFunctionWithData(typ *NativeFunctionType, fn Native, data any) (values.Value, error)
NativeFunctionWithData retains immutable host metadata with a callable. Bindings use it to preserve the original native function across round trips.
func (*VM) NativeSlice ¶
func (c *VM) NativeSlice(layout, element *values.NativeLayout, data unsafe.Pointer, length, capacity uint32) (values.Value, error)
NativeSlice retains native backing without changing the logical slice shape.
func (*VM) OpenCallbackScope ¶
func (vm *VM) OpenCallbackScope(limits Limits) (*CallbackScope, error)
OpenCallbackScope keeps exported Go adapters callable until Close. Each callback invoked outside an active host binding—whether the originating VM is idle or already released—runs on a fresh VM lease with the same program and Go context and a fresh per-call budget of limits (zero quotas are unlimited, matching VM.SetBudget; pass program.DefaultLimits() to reuse the program's default policy).
func (*VM) PackAggregate ¶
PackAggregate builds a guest struct, array, or slice from values in declaration or index order. Each input must match its declared field or element type.
func (*VM) PanicCallback ¶
PanicCallback propagates callback execution failure through a native function whose Go signature cannot return that failure. VM native dispatch recovers it.
func (*VM) Record ¶
Record reads a guest immutable row, including an explicit value copy. The returned record retains its existing native representation and lifetime. Both a nil row pointer and a zero row value have missing record contents. Callers needing pointer identity must also inspect the original argument.
func (*VM) RecordValue ¶
RecordValue returns the immutable row cell without allocating a handle.
func (*VM) Release ¶
func (vm *VM) Release()
Release returns this VM's cleared buffers to the shared pool.
func (*VM) Run ¶
Run calls a resolved function. Slots hold the arguments followed by room for its results.
func (*VM) SetBackedEditRecordResult ¶
SetBackedEditRecordResult keeps the native backing with the virtual row.
func (*VM) SetCallResult ¶
SetCallResult writes a result in the current Go binding.
func (*VM) SetCoverage ¶
SetCoverage changes instrumentation between runs. Nil disables collection.
func (*VM) SetEditRecordResult ¶
SetEditRecordResult returns a mutable KVO row with the editor's native lifetime.
func (*VM) SetInterface ¶
SetInterface writes an interface result by ABI slot. Dynamic types must be declared in the wrapper's DynamicTypes (or used by source) before linking. Boxing and value copies are charged to this execution's allocation budget.
func (*VM) SetReadRecordResult ¶
SetReadRecordResult returns one immutable KVO row from a host function. The compiler owns the payload when it escapes its borrowing boundary.
func (*VM) SetValue ¶
SetValue writes a V pair into a result slot whose external type uses both banks.
func (*VM) SliceElement ¶
SliceElement reads an element using the linked native or VM storage layout. Host callbacks must use their parameter shape rather than assume VM cells.
func (*VM) StoreNative ¶
StoreNative copies a VM value into caller-owned storage of the declared layout.
func (*VM) TypedInterfaceValue ¶
TypedInterfaceValue preserves the concrete identity promised by a typed native interface. AnyValue separately preserves native error adaptation.
func (*VM) UnpackAggregate ¶
UnpackAggregate returns guest struct fields in declaration order, or array or slice elements in index order. Nested values keep their EVM representation.
type ValueModel ¶
type ValueModel struct {
Model *kvo.Model
Type *values.Type
// Props are the property codes of the struct's two fields, in field order.
Props [2]uint64
}
ValueModel exposes the sub-objects of a KVO model as values of a struct type that the same package declares. A property of that model then reads as the struct, by value, on any read-only row, encoded or backed by a Go struct: the VM packs the two stored words into the struct's cell. Nothing is decoded into a Go struct and nothing is allocated, so the struct's methods, compiled from package source, run on stored data directly. A missing sub-object reads as the zero value.
The struct must keep its value copies in one cell (values.CellStruct), and each of its two fields must be a scalar property that fits one word. Editable rows do not expose such a property yet.
Source Files
¶
- budget_scope.go
- callback.go
- callback_scope.go
- coverage.go
- coverage_run.go
- defer.go
- defer_run.go
- disassemble.go
- environment.go
- evm.go
- extended.go
- extended_run.go
- floatloop.go
- floatloop_run.go
- function.go
- function_handle.go
- function_native.go
- guest_error.go
- hostcall.go
- instruction.go
- interface.go
- json.go
- link_environment.go
- link_methods.go
- link_shapes.go
- mutable_native.go
- mutable_native_fields.go
- native_any.go
- native_binding.go
- native_collections.go
- native_error.go
- native_fields.go
- native_function.go
- native_interface.go
- native_layout_validation.go
- native_maps.go
- native_model_layout.go
- native_models.go
- native_slice_views.go
- ownership.go
- pack.go
- panic.go
- position.go
- program.go
- program_listing.go
- rawinit.go
- record_json.go
- record_native_copy.go
- record_values.go
- records.go
- scalar.go
- slicestorage.go
- stdlib.go
- stdlib_format.go
- stdlib_math.go
- stdlib_signatures.go
- stdlib_strconv.go
- stdlib_strings.go
- time.go
- vm_pool.go
Directories
¶
| Path | Synopsis |
|---|---|
|
bench
|
|
|
internal/mathwork
Package mathwork holds the independent numeric workloads.
|
Package mathwork holds the independent numeric workloads. |
|
internal/optwork
Package optwork holds workloads compiled by both Go and EVM.
|
Package optwork holds workloads compiled by both Go and EVM. |
|
internal/workload
Package workload contains shared fixtures for the EVM and Lua benchmarks.
|
Package workload contains shared fixtures for the EVM and Lua benchmarks. |
|
cmd
|
|
|
gox
command
Command gox checks syntax and formats GoX source files.
|
Command gox checks syntax and formats GoX source files. |
|
Package evmasm assembles textual EVM code without a Go compiler.
|
Package evmasm assembles textual EVM code without a Go compiler. |
|
Package evmbind builds a reusable EVM host schema from Go declarations.
|
Package evmbind builds a reusable EVM host schema from Go declarations. |
|
cmd/evmbind
command
Command evmbind generates a package of native wrappers for an EVM API.
|
Command evmbind generates a package of native wrappers for an EVM API. |
|
internal/appfixture
Package appfixture is an ordinary Go package whose own source is bound whole.
|
Package appfixture is an ordinary Go package whose own source is bound whole. |
|
internal/methodfixture
Code generated by kvo.
|
Code generated by kvo. |
|
internal/methodfixture/gen
command
|
|
|
Package evmcompiler compiles sequential Go 1.23 to EVM bytecode.
|
Package evmcompiler compiles sequential Go 1.23 to EVM bytecode. |
|
concurrency
Package concurrency provides state that parallel callbacks can safely share.
|
Package concurrency provides state that parallel callbacks can safely share. |
|
Package evmstd offers general-purpose Go standard packages to scripts, beyond the few the VM implements itself.
|
Package evmstd offers general-purpose Go standard packages to scripts, beyond the few the VM implements itself. |
|
internal/cachecore
Package cachecore binds the guest cache to its host-owned storage.
|
Package cachecore binds the guest cache to its host-owned storage. |
|
Package evmtest provides named-entry fixtures for compiler and binding tests.
|
Package evmtest provides named-entry fixtures for compiler and binding tests. |
|
examples
|
|
|
evm-basic
command
Command evm-basic runs a plugin written in Go inside a Go program.
|
Command evm-basic runs a plugin written in Go inside a Go program. |
|
evm-basic/_plugin
A plugin: ordinary Go that the host compiles and runs inside EVM.
|
A plugin: ordinary Go that the host compiles and runs inside EVM. |
|
gox-basic
command
Command gox-basic renders a page with GoX templates that use an ordinary Go application directly: its types, methods, package functions and constants.
|
Command gox-basic renders a page with GoX templates that use an ordinary Go application directly: its types, methods, package functions and constants. |
|
kvo-basic
command
Command kvo-basic reads and edits the same records from Go and from a script, whether a record is a Go struct or an encoded row.
|
Command kvo-basic reads and edits the same records from Go and from a script, whether a record is a Go struct or an encoded row. |
|
kvo-basic/_script
A script: ordinary Go that the host compiles and runs inside EVM.
|
A script: ordinary Go that the host compiles and runs inside EVM. |
|
Package gox compiles GoX templates into typed EVM functions.
|
Package gox compiles GoX templates into typed EVM functions. |
|
internal
|
|
|
coveragegen
command
Command coveragegen derives the instrumented interpreter from execute.
|
Command coveragegen derives the instrumented interpreter from execute. |
|
genstd
command
Command genstd generates the declarations and bindings of the standard packages that evmstd binds natively, and the API report listing what each offered standard package exposes and what it leaves out, with the reason.
|
Command genstd generates the declarations and bindings of the standard packages that evmstd binds natively, and the API report listing what each offered standard package exposes and what it leaves out, with the reason. |
|
genstdlib
command
|
|
|
inlinerow
Code generated by kvo.
|
Code generated by kvo. |
|
inlinerow/gen
command
|
|
|
naming
Package naming defines identifier spelling rules for EVM frontends.
|
Package naming defines identifier spelling rules for EVM frontends. |
|
statrow
Code generated by kvo.
|
Code generated by kvo. |
|
statrow/gen
command
|
|
|
valuebench
Code generated by kvo.
|
Code generated by kvo. |
|
valuebench/gen
command
|
|
|
Package kvo defines logical models, typed properties, and record access and editing over MessagePack, Fast2, Compact2, native Go structs, and decoded memory.
|
Package kvo defines logical models, typed properties, and record access and editing over MessagePack, Fast2, Compact2, native Go structs, and decoded memory. |
|
codec/fast1
Package fast1 implements the original KVO word-map storage format.
|
Package fast1 implements the original KVO word-map storage format. |
|
codec/msgpack
Package msgpack implements EDB's MessagePack struct encoding.
|
Package msgpack implements EDB's MessagePack struct encoding. |
|
codec/row2
Package row2 reads and writes the Fast2 and Compact2 KVO row formats.
|
Package row2 reads and writes the Fast2 and Compact2 KVO row formats. |
|
Package nativebind selects native bindings once, when a schema is built.
|
Package nativebind selects native bindings once, when a schema is built. |
|
internal/fixture
Code generated by nativebind.
|
Code generated by nativebind. |
|
internal/generate
command
|
|
|
Package values defines two-word values shared by KVO adapters and EVM.
|
Package values defines two-word values shared by KVO adapters and EVM. |