Documentation
¶
Overview ¶
Package values defines two-word values shared by KVO adapters and EVM. Concrete types and presence are supplied separately; interface values encode their dynamic type using a program-local TypeTable.
Index ¶
- Constants
- Variables
- func CellAt(p unsafe.Pointer, n uint64) unsafe.Pointer
- type Codec
- func BoolCodec[T ~bool]() Codec[T]
- func BytesCodec[T ~[]byte]() Codec[T]
- func Float32Codec[T ~float32]() Codec[T]
- func Float64Codec[T ~float64]() Codec[T]
- func SignedCodec[T Signed]() Codec[T]
- func StringCodec[T ~string]() Codec[T]
- func TimeCodec() Codec[time.Time]
- func UnsignedCodec[T Unsigned]() Codec[T]
- type ComparisonError
- type DynamicType
- type Field
- type Kind
- type Map
- func (m *Map) Clear()
- func (m *Map) Delete(k Value, h uint64) error
- func (m *Map) DeleteContext(ctx context.Context, k Value, h uint64) error
- func (m *Map) Entries() []*MapEntry
- func (m *Map) EntryCount() uint64
- func (m *Map) Find(k Value, h uint64) (*MapEntry, bool, error)
- func (m *Map) FindContext(ctx context.Context, k Value, h uint64) (*MapEntry, bool, error)
- func (m *Map) Len() int
- func (m *Map) ProbeCount(hash uint64) uint64
- func (m *Map) Put(k, v Value, h uint64) error
- func (m *Map) PutContext(ctx context.Context, k, v Value, h uint64) error
- type MapEntry
- type Method
- type NativeField
- type NativeLayout
- type OwnFunc
- type OwnershipBudget
- type Repr
- type RepresentationID
- type Shape
- func (s *Shape) Aggregate() bool
- func (s *Shape) Comparable() bool
- func (s *Shape) Equal(a, b Value, ts *TypeTable) (bool, error)
- func (s *Shape) EqualContext(ctx context.Context, a, b Value, ts *TypeTable) (bool, error)
- func (s *Shape) GetField(p unsafe.Pointer, i int) Value
- func (s *Shape) Hash(v Value, ts *TypeTable) (uint64, error)
- func (s *Shape) HashContext(ctx context.Context, v Value, ts *TypeTable) (uint64, error)
- func (s *Shape) NativeStorage() bool
- func (s *Shape) New() unsafe.Pointer
- func (s *Shape) SetField(p unsafe.Pointer, i int, v Value)
- func (s *Shape) Store(p unsafe.Pointer, v Value)
- func (s *Shape) Stored(p unsafe.Pointer) Value
- func (s *Shape) Work(v Value, limit uint64, ts *TypeTable) (uint64, bool)
- type Signed
- type Type
- type TypeTable
- type Unsigned
- type Value
- func Bool(v bool) Value
- func Bytes(b []byte) Value
- func CellSlice(p unsafe.Pointer, n uint64) []Value
- func Float(v float64) Value
- func Float32(v float32) Value
- func Int(v int64) Value
- func SliceValue(p unsafe.Pointer, length, capacity uint32) Value
- func String(v string) Value
- func Time(t time.Time) Value
- func TypedPair(id RepresentationID, p unsafe.Pointer, aux uint32) Value
- func Uint(v uint64) Value
- func (v Value) AsBool() bool
- func (v Value) AsBytes() []byte
- func (v Value) AsFloat() float64
- func (v Value) AsFloat32() float32
- func (v Value) AsInt() int64
- func (v Value) AsString() string
- func (v Value) AsTime() time.Time
- func (v Value) AsUint() uint64
- func (v Value) Auxiliary() uint32
- func (v Value) Representation() RepresentationID
- func (v Value) SliceCap() uint32
- func (v Value) SliceLen() uint32
Constants ¶
const NativeAddress uint64 = 1
NativeAddress marks a pointer into live Go memory. A pointer with R=0 refers to VM cells. The pointer's static type determines whether it carries this discriminator; opaque interface receivers continue to use their own ABI.
Variables ¶
var ( IntType = NewType("int", Raw) UintType = NewType("uint", Raw) UintptrType = NewType("uintptr", Raw) Int8 = NewType("int8", Raw) Int16 = NewType("int16", Raw) Int32 = NewType("int32", Raw) Uint8 = NewType("uint8", Raw) Uint16 = NewType("uint16", Raw) Uint32 = NewType("uint32", Raw) Float32Type = NewType("float32", Raw) )
Functions ¶
Types ¶
type Codec ¶
Codec converts between a cell and a Go value. Its functions do not inspect runtime types. Type is declaration metadata, used only when binding a codec. Strings and bytes borrow their input storage in both directions.
func BytesCodec ¶
func Float32Codec ¶
func Float64Codec ¶
func SignedCodec ¶
func StringCodec ¶
func UnsignedCodec ¶
type ComparisonError ¶
ComparisonError is a Go language panic condition, distinct from corrupt interface storage. EVM may recover it; invalid type indexes stay fatal.
func (*ComparisonError) Error ¶
func (e *ComparisonError) Error() string
type DynamicType ¶
type Map ¶
Map stores immutable key/value snapshots. Mutable values inside them (pointers, maps and slices) retain Go aliasing. Deleted entries remain only in iterators.
func (*Map) DeleteContext ¶
func (*Map) Entries ¶
Entries snapshots the existing iteration range; insertions may be skipped. Updates are observed and deleted entries are skipped by the iterator.
func (*Map) EntryCount ¶
func (*Map) FindContext ¶
func (*Map) ProbeCount ¶
type Method ¶
Method is a receiver-free interface requirement. ID includes the defining package path for unexported methods.
type NativeField ¶
type NativeLayout ¶
type NativeLayout struct {
Size uint64
New func() unsafe.Pointer
Load func(unsafe.Pointer) Value
Store func(unsafe.Pointer, Value)
Fields []NativeField
}
NativeLayout supplies operations on Go memory, independently of VM cells. Load returns decoded scalars/strings, native pointer targets, or a borrowed native aggregate address. VM aggregate conversion remains an explicit step.
type OwnFunc ¶
type OwnFunc func(Value, OwnershipBudget) (Value, error)
OwnFunc discharges borrowed-storage dependencies while preserving the logical value. It may return already independent values unchanged. Mutable identity needs an explicit contract; a shallow copy is not generally sufficient.
type OwnershipBudget ¶
OwnershipBudget is supplied at ownership boundaries, never on ordinary reads. ChargeAllocation must succeed before allocating a clone's backing storage.
type RepresentationID ¶
type RepresentationID uint32
RepresentationID identifies immutable physical-layout metadata. Several representations may share a logical Type. IDs are process-local, never reused, and must not be persisted or allocated per value or transaction.
func RegisterRepresentation ¶
func RegisterRepresentation(shape *Shape) RepresentationID
RegisterRepresentation publishes a physical layout for a compact typed pair. The supplied shape and its reachable metadata must remain immutable.
func (RepresentationID) Shape ¶
func (id RepresentationID) Shape() *Shape
type Shape ¶
type Shape struct {
Native *NativeLayout // optional live Go representation, distinct from Cells
// DisplayName is optional source-language spelling, prepared at compile time.
DisplayName string
Methods []Method
Params, Results []*Shape
// PointerLike gives opaque typed pairs pointer nil semantics: P == nil is
// the zero value regardless of representation metadata. Other pairs may
// legitimately carry nonzero auxiliary data with a nil pointer.
PointerLike bool
Variadic bool
Type *Type
Kind Kind
Bits uint8
Elem, Key *Shape
Fields []Field
Len uint64
Cells uint64
}
Shape describes typed VM storage. Descriptors, including recursive graphs, are built before use and never mutated by execution. Link snapshots them. Scalar cells hold one Value. Structs/arrays flatten their members into cells; their register values point to immutable snapshots (nil means all zero).
func NewPointerShape ¶
NewPointerShape declares a pointer to VM cell storage. Reuse the result when declaring signatures and TypeDecls. Live native Go pointers instead use the NativeSchema produced by bindings, which supplies their native layout.
func NewStructShape ¶
NewStructShape declares a nominal VM struct using the same Shape and Field metadata as compiled structs. It copies the fields and computes cell offsets; supplied offsets are ignored. Child shapes must be fully laid out already. Build and retain shapes during setup. Type identity is by pointer, not name.
func (*Shape) Comparable ¶
func (*Shape) EqualContext ¶
EqualContext allows cancellation during traversal of compound values.
func (*Shape) GetField ¶
GetField borrows a field of VM cell storage. Aggregate fields point into that storage; use the field shape's Store to copy them. p must be nonnil storage for this struct shape, never a pointer to a native Go struct.
func (*Shape) HashContext ¶
HashContext allows cancellation during traversal of compound values.
func (*Shape) NativeStorage ¶
NativeStorage reports whether this shape supports live native allocation. VM collection and interface layouts remain distinct from Go storage.
func (*Shape) New ¶
New allocates zeroed VM cell storage for this shape, not a native Go object. The extra cell gives even a trailing zero-sized field an address in the allocation, matching VM allocations. All writes use Go write barriers.
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type is external metadata. Identity is by pointer, not by name.
type TypeTable ¶
type TypeTable struct {
// contains filtered or unexported fields
}
TypeTable owns the program-local identities and encoding of interface values. Entry zero is nil. The table and its descriptors are immutable after creation.
func NewTypeTable ¶
func NewTypeTable(types []DynamicType) *TypeTable
func (*TypeTable) Comparable ¶
func (*TypeTable) Index ¶
Index extracts the dynamic type ID; Unpack validates the payload. Scalar markers must be checked first: their R contains all 64 bits.
type Value ¶
func Bytes ¶
Bytes borrows an immutable byte span. R is its byte length, unlike a mutable VM slice whose header packs length and capacity. The external type distinguishes byte spans, strings and VM slices. The backing bytes must outlive this value.
func Time ¶
Time stores nanoseconds in one word when they fit, with zero reserved for time.Time{}. Dates outside that range use a 12-byte integer payload (uint32 nanoseconds, int64 Unix seconds, big endian). No precision or date range is lost. Like database timestamps, the value denotes an instant, without a monotonic clock reading or timezone. AsTime returns UTC.
func TypedPair ¶
func TypedPair(id RepresentationID, p unsafe.Pointer, aux uint32) Value
TypedPair keeps a real GC-visible pointer and a 32-bit auxiliary word in one cell. The ID must come from RegisterRepresentation. Auxiliary data commonly holds the length of an immutable byte span; it is not a second pointer.
func (Value) Representation ¶
func (v Value) Representation() RepresentationID
Representation returns zero for an untagged value. Concrete scalar callers must not interpret arbitrary numeric bits as tags: their external type wins.