core

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Pos constants
	NoPos Pos = 0

	// Value type constants
	VT_UNDEFINED          = uint8(0) // must be first (zero)
	VT_VALUE_PTR          = uint8(1)
	VT_BUILTIN_FUNCTION   = uint8(2)
	VT_COMPILED_FUNCTION  = uint8(3)
	VT_ERROR              = uint8(4)
	VT_BOOL               = uint8(5)
	VT_BYTE               = uint8(6)
	VT_RUNE               = uint8(7)
	VT_INT                = uint8(8)
	VT_FLOAT              = uint8(9)
	VT_DECIMAL            = uint8(10)
	VT_TIME               = uint8(11)
	VT_STRING             = uint8(12)
	VT_RUNES              = uint8(13)
	VT_BYTES              = uint8(14)
	VT_ARRAY              = uint8(15)
	VT_RECORD             = uint8(16)
	VT_DICT               = uint8(17)
	VT_INT_RANGE          = uint8(18)
	VT_RUNES_ITERATOR     = uint8(19)
	VT_BYTES_ITERATOR     = uint8(20)
	VT_ARRAY_ITERATOR     = uint8(21)
	VT_DICT_ITERATOR      = uint8(22)
	VT_INT_RANGE_ITERATOR = uint8(23)
	VT_USER_DEFINED       = uint8(24) // must be last
)
View Source
const (
	OpConstant       = Opcode(0)  // Load constant
	OpBComplement    = Opcode(1)  // bitwise complement
	OpPop            = Opcode(2)  // Pop
	OpTrue           = Opcode(3)  // Push true
	OpFalse          = Opcode(4)  // Push false
	OpEqual          = Opcode(5)  // Equal ==
	OpNotEqual       = Opcode(6)  // Not equal !=
	OpMinus          = Opcode(7)  // Minus -
	OpLNot           = Opcode(8)  // Logical not !
	OpJumpFalsy      = Opcode(9)  // Jump if falsy
	OpAndJump        = Opcode(10) // Logical AND jump
	OpOrJump         = Opcode(11) // Logical OR jump
	OpJump           = Opcode(12) // Jump
	OpNull           = Opcode(13) // Push null
	OpArray          = Opcode(14) // Array object
	OpRecord         = Opcode(15) // Record object
	OpContains       = Opcode(16) // Contains operation (x in y)
	OpImmutable      = Opcode(17) // Immutable object
	OpIndex          = Opcode(18) // Index operation
	OpSliceIndex     = Opcode(19) // Slice operation
	OpCall           = Opcode(20) // Call function
	OpReturn         = Opcode(21) // Return
	OpGetGlobal      = Opcode(22) // Get global variable
	OpSetGlobal      = Opcode(23) // Set global variable
	OpSetSelGlobal   = Opcode(24) // Set global variable using selectors
	OpGetLocal       = Opcode(25) // Get local variable
	OpSetLocal       = Opcode(26) // Set local variable
	OpDefineLocal    = Opcode(27) // Define local variable
	OpSetSelLocal    = Opcode(28) // Set local variable using selectors
	OpGetFreePtr     = Opcode(29) // Get free variable pointer object
	OpGetFree        = Opcode(30) // Get free variables
	OpSetFree        = Opcode(31) // Set free variables
	OpGetLocalPtr    = Opcode(32) // Get local variable as a pointer
	OpSetSelFree     = Opcode(33) // Set free variables using selectors
	OpGetBuiltin     = Opcode(34) // Get builtin function
	OpClosure        = Opcode(35) // Push closure
	OpIteratorInit   = Opcode(36) // Iterator init
	OpIteratorNext   = Opcode(37) // Iterator next
	OpIteratorKey    = Opcode(38) // Iterator key
	OpIteratorValue  = Opcode(39) // Iterator value
	OpBinaryOp       = Opcode(40) // Binary operation
	OpSuspend        = Opcode(41) // Suspend VM
	OpSelect         = Opcode(42) // Select operation
	OpMethodCall     = Opcode(43) // Call method on object
	OpSliceIndexStep = Opcode(44) // Slice with step

)

List of opcodes

Variables

View Source
var (
	// Value shortcuts
	True      = BoolValue(true)
	False     = BoolValue(false)
	Undefined = UndefinedValue()
)
View Source
var OpcodeNames = [...]string{
	OpConstant:       "CONST",
	OpPop:            "POP",
	OpTrue:           "TRUE",
	OpFalse:          "FALSE",
	OpBComplement:    "NEG",
	OpEqual:          "EQL",
	OpNotEqual:       "NEQ",
	OpMinus:          "NEG",
	OpLNot:           "NOT",
	OpJumpFalsy:      "JMPF",
	OpAndJump:        "ANDJMP",
	OpOrJump:         "ORJMP",
	OpJump:           "JMP",
	OpNull:           "NULL",
	OpGetGlobal:      "GETG",
	OpSetGlobal:      "SETG",
	OpSetSelGlobal:   "SETSG",
	OpArray:          "ARR",
	OpRecord:         "RECORD",
	OpImmutable:      "IMMUT",
	OpIndex:          "INDEX",
	OpSliceIndex:     "SLICE",
	OpCall:           "CALL",
	OpSliceIndexStep: "SLICESTEP",
	OpReturn:         "RET",
	OpGetLocal:       "GETL",
	OpSetLocal:       "SETL",
	OpDefineLocal:    "DEFL",
	OpSetSelLocal:    "SETSL",
	OpGetBuiltin:     "BUILTIN",
	OpClosure:        "CLOSURE",
	OpGetFreePtr:     "GETFP",
	OpGetFree:        "GETF",
	OpSetFree:        "SETF",
	OpGetLocalPtr:    "GETLP",
	OpSetSelFree:     "SETSF",
	OpIteratorInit:   "ITER",
	OpIteratorNext:   "ITNXT",
	OpIteratorKey:    "ITKEY",
	OpIteratorValue:  "ITVAL",
	OpBinaryOp:       "BINARYOP",
	OpSuspend:        "SUSPEND",
	OpSelect:         "SELECT",
	OpMethodCall:     "MCALL",
	OpContains:       "CONTAINS",
}

OpcodeNames are string representation of opcodes.

View Source
var OpcodeOperands = [...][]int{
	OpConstant:       {2},
	OpPop:            {},
	OpTrue:           {},
	OpFalse:          {},
	OpBComplement:    {},
	OpEqual:          {},
	OpNotEqual:       {},
	OpMinus:          {},
	OpLNot:           {},
	OpJumpFalsy:      {4},
	OpAndJump:        {4},
	OpOrJump:         {4},
	OpJump:           {4},
	OpNull:           {},
	OpGetGlobal:      {2},
	OpSetGlobal:      {2},
	OpSetSelGlobal:   {2, 1},
	OpArray:          {2},
	OpRecord:         {2},
	OpImmutable:      {},
	OpIndex:          {},
	OpSliceIndex:     {},
	OpCall:           {1, 1},
	OpSliceIndexStep: {},
	OpReturn:         {1},
	OpGetLocal:       {1},
	OpSetLocal:       {1},
	OpDefineLocal:    {1},
	OpSetSelLocal:    {1, 1},
	OpGetBuiltin:     {1},
	OpClosure:        {2, 1},
	OpGetFreePtr:     {1},
	OpGetFree:        {1},
	OpSetFree:        {1},
	OpGetLocalPtr:    {1},
	OpSetSelFree:     {1, 1},
	OpIteratorInit:   {},
	OpIteratorNext:   {},
	OpIteratorKey:    {},
	OpIteratorValue:  {},
	OpBinaryOp:       {1},
	OpSuspend:        {},
	OpSelect:         {},
	OpMethodCall:     {2, 1, 1},
	OpContains:       {},
}

OpcodeOperands is the number of operands.

View Source
var ValueTypeDefaults = ValueType{
	Name:         defaultTypeName,
	String:       defaultTypeString,
	Interface:    defaultTypeInterface,
	EncodeJSON:   defaultTypeEncodeJSON,
	EncodeBinary: defaultTypeEncodeBinary,
	DecodeBinary: defaultTypeDecodeBinary,
	IsTrue:       defaultFalse,
	Copy:         defaultSelf,
	Equal:        defaultTypeEqualPrimitive,
	UnaryOp:      defaultTypeUnaryOp,
	BinaryOp:     defaultTypeBinaryOp,
	MethodCall:   defaultTypeMethodCall,

	IsIterable: defaultFalse,
	Contains:   defaultTypeContains,
	Len:        default0,
	Iterator:   defaultUndefined,
	Access:     defaultTypeAccess,
	Assign:     defaultTypeAssign,
	Append:     defaultTypeAppend,
	Slice:      defaultTypeSlice,
	Delete:     defaultTypeDelete,
	SliceStep:  defaultTypeSliceStep,

	IsCallable: defaultFalse,
	IsVariadic: defaultFalse,
	Arity:      defaultTypeArity,
	Call:       defaultTypeCall,

	Next:  defaultFalse,
	Key:   defaultUndefined,
	Value: defaultUndefined,

	AsBool:    defaultTypeAsBool,
	AsByte:    defaultTypeAsByte,
	AsRune:    defaultTypeAsRune,
	AsInt:     defaultTypeAsInt,
	AsFloat:   defaultTypeAsFloat,
	AsDecimal: defaultTypeAsDecimal,
	AsTime:    defaultTypeAsTime,
	AsString:  defaultTypeAsString,
	AsRunes:   defaultTypeAsRunes,
	AsBytes:   defaultTypeAsBytes,
	AsArray:   defaultTypeAsArray,
	AsDict:    defaultTypeAsDict,
}
View Source
var ValueTypes [256]ValueType

Functions

func EncodeString

func EncodeString(b []byte, val string) []byte

EncodeString encodes given string as JSON string according to https://www.json.org/img/string.png Implementation is inspired by https://github.com/json-iterator/go

func ReadOperands

func ReadOperands(numOperands []int, ins []byte) ([]int, int)

ReadOperands reads operands from the bytecode.

func SetValueType

func SetValueType(t uint8, f ValueType)

Types

type Arena added in v0.0.6

type Arena struct {
	// contains filtered or unexported fields
}

func NewArena added in v0.0.6

func NewArena(opts *ArenaOptions) *Arena

NewArena creates a new Arena with the given options. If opts is nil, it uses the default options.

func (*Arena) NewArray added in v0.0.6

func (a *Arena) NewArray(capacity int, sized bool) []Value

func (*Arena) NewArrayIteratorValue added in v0.0.6

func (a *Arena) NewArrayIteratorValue(arr []Value) Value

func (*Arena) NewArrayValue added in v0.0.6

func (a *Arena) NewArrayValue(arr []Value, immutable bool) Value

func (*Arena) NewBuiltinFunctionValue added in v0.0.6

func (a *Arena) NewBuiltinFunctionValue(name string, fn NativeFunc, arity int8, variadic bool) Value

func (*Arena) NewBytes added in v0.0.6

func (a *Arena) NewBytes(capacity int, sized bool) []byte

func (*Arena) NewBytesIteratorValue added in v0.0.6

func (a *Arena) NewBytesIteratorValue(b []byte) Value

func (*Arena) NewBytesValue added in v0.0.6

func (a *Arena) NewBytesValue(b []byte) Value

func (*Arena) NewCompiledFunctionValue added in v0.0.6

func (a *Arena) NewCompiledFunctionValue(instructions []byte, free []*Value, sourceMap map[int]Pos, numLocals int, numParameters int8, varArgs bool) Value

func (*Arena) NewDecimal added in v0.0.6

func (a *Arena) NewDecimal() *dec128.Dec128

func (*Arena) NewDict added in v0.0.8

func (a *Arena) NewDict(capacity int) map[string]Value

func (*Arena) NewDictIteratorValue added in v0.0.8

func (a *Arena) NewDictIteratorValue(m map[string]Value) Value

func (*Arena) NewDictValue added in v0.0.8

func (a *Arena) NewDictValue(m map[string]Value, immutable bool) Value

func (*Arena) NewErrorValue added in v0.0.6

func (a *Arena) NewErrorValue(e Value) Value

func (*Arena) NewIntRangeIteratorValue added in v0.0.6

func (a *Arena) NewIntRangeIteratorValue(start, stop, step int64) Value

func (*Arena) NewIntRangeValue added in v0.0.6

func (a *Arena) NewIntRangeValue(start, stop, step int64) Value

func (*Arena) NewRecordValue added in v0.0.6

func (a *Arena) NewRecordValue(m map[string]Value, immutable bool) Value

func (*Arena) NewRunes added in v0.0.6

func (a *Arena) NewRunes(capacity int, sized bool) []rune

func (*Arena) NewRunesIteratorValue added in v0.0.6

func (a *Arena) NewRunesIteratorValue(s []rune) Value

func (*Arena) NewRunesValue added in v0.0.6

func (a *Arena) NewRunesValue(r []rune) Value

func (*Arena) NewStringValue added in v0.0.6

func (a *Arena) NewStringValue(s string) Value

func (*Arena) NewTime added in v0.0.6

func (a *Arena) NewTime() *time.Time

func (*Arena) Payload added in v0.0.7

func (a *Arena) Payload() any

Payload returns the payload associated with the arena, which can be used to store any additional data or context used by user-defined types and functions.

func (*Arena) Reset added in v0.0.6

func (a *Arena) Reset()

func (*Arena) Stat added in v0.0.6

func (a *Arena) Stat() map[string]slab.Stats

type ArenaOptions added in v0.0.6

type ArenaOptions struct {
	Decimals int
	Times    int

	BytesNum int
	BytesCap int

	RunesNum int
	RunesCap int

	ArraysNum int
	ArraysCap int

	BuiltinFunctions  int
	CompiledFunctions int

	ErrorValues    int
	StringValues   int
	RunesValues    int
	BytesValues    int
	ArrayValues    int
	DictValues     int
	IntRangeValues int

	RunesIterators    int
	BytesIterators    int
	ArrayIterators    int
	DictIterators     int
	IntRangeIterators int

	Payload Resettable
}

func DefaultArenaOptions added in v0.0.6

func DefaultArenaOptions() *ArenaOptions

type Array

type Array struct {
	Elements []Value
}

func (*Array) Set

func (o *Array) Set(elements []Value)

type ArrayIterator

type ArrayIterator struct {
	Elements []Value
	// contains filtered or unexported fields
}

func (*ArrayIterator) Set

func (i *ArrayIterator) Set(v []Value)

type BuiltinFunction

type BuiltinFunction struct {
	Func     NativeFunc
	Name     string
	Arity    int8
	Variadic bool
}

func (*BuiltinFunction) Set

func (f *BuiltinFunction) Set(fn NativeFunc, name string, arity int8, variadic bool)

type Bytes

type Bytes struct {
	Elements []byte
}

func (*Bytes) Set

func (o *Bytes) Set(elements []byte)

type BytesIterator

type BytesIterator struct {
	Elements []byte
	// contains filtered or unexported fields
}

func (*BytesIterator) Set

func (o *BytesIterator) Set(vals []byte)

type CompiledFunction

type CompiledFunction struct {
	Instructions  []byte
	Free          []*Value
	SourceMap     map[int]Pos
	NumLocals     int // number of local variables (including function parameters)
	NumParameters int8
	VarArgs       bool
}

func (*CompiledFunction) Set

func (o *CompiledFunction) Set(instructions []byte, free []*Value, sourceMap map[int]Pos, numLocals int, numParameters int8, varArgs bool)

func (*CompiledFunction) Size

func (o *CompiledFunction) Size() int64

func (*CompiledFunction) SourcePos

func (o *CompiledFunction) SourcePos(ip int) Pos

type Dict added in v0.0.8

type Dict struct {
	Elements map[string]Value
}

func (*Dict) Set added in v0.0.8

func (o *Dict) Set(elements map[string]Value)

type DictIterator added in v0.0.8

type DictIterator struct {
	Elements map[string]Value
	Keys     []string
	// contains filtered or unexported fields
}

func (*DictIterator) Set added in v0.0.8

func (o *DictIterator) Set(m map[string]Value)

type Error

type Error struct {
	Payload Value
}

func (*Error) Set

func (o *Error) Set(payload Value)

type IntRange

type IntRange struct {
	Start int64
	Stop  int64
	Step  int64
}

func (*IntRange) Contains

func (o *IntRange) Contains(i int64) bool

func (*IntRange) Empty

func (o *IntRange) Empty() bool

func (*IntRange) Get

func (o *IntRange) Get(i int64) (int64, bool)

func (*IntRange) Len

func (o *IntRange) Len() int64

func (*IntRange) Set

func (o *IntRange) Set(start, stop, step int64)

type IntRangeIterator

type IntRangeIterator struct {
	// contains filtered or unexported fields
}

func (*IntRangeIterator) Set

func (i *IntRangeIterator) Set(start, stop, step int64)

type NativeFunc

type NativeFunc = func(VM, []Value) (Value, error)

type Opcode

type Opcode = byte

type Pos

type Pos int

func (Pos) IsValid

func (p Pos) IsValid() bool

type Resettable added in v0.0.7

type Resettable interface {
	Reset()
}

type Runes added in v0.0.6

type Runes struct {
	Elements []rune
}

func (*Runes) Set added in v0.0.6

func (o *Runes) Set(r []rune)

type RunesIterator added in v0.0.6

type RunesIterator struct {
	Elements []rune
	// contains filtered or unexported fields
}

func (*RunesIterator) Set added in v0.0.6

func (i *RunesIterator) Set(v []rune)

type String

type String struct {
	Value string
}

func (*String) Set

func (o *String) Set(s string)

type VM

type VM interface {
	Allocator() *Arena
	Abort()
	IsStackEmpty() bool
	Call(*CompiledFunction, []Value) (Value, error)
	Run() error
}

type Value

type Value struct {
	Type  uint8
	Const bool
	Data  uint64
	Ptr   unsafe.Pointer
}

The minimum required fields for Value are ptr, d64 and kind. This allow to store primitive types such as int, float, rune; and heap allocated objects. Due to padding, the size of such structure will be 24 bytes on 64-bit architectures. So we can add some d32, d16 and d8 extra fields for free.

func ArrayIteratorValue

func ArrayIteratorValue(v *ArrayIterator) Value

func ArrayValue

func ArrayValue(v *Array, immutable bool) Value

ArrayValue creates boxed array value.

func BoolValue

func BoolValue(b bool) Value

BoolValue creates new boxed bool value.

func BuiltinFunctionValue

func BuiltinFunctionValue(f *BuiltinFunction) Value

BuiltinFunctionValue creates new boxed builtin function value.

func ByteValue added in v0.0.10

func ByteValue(v byte) Value

ByteValue creates new boxed byte value.

func BytesIteratorValue

func BytesIteratorValue(v *BytesIterator) Value

func BytesValue

func BytesValue(v *Bytes) Value

BytesValue creates new boxed bytes value.

func CompiledFunctionValue

func CompiledFunctionValue(f *CompiledFunction) Value

CompiledFunctionValue creates new boxed compiled function value.

func DecimalValue

func DecimalValue(d *dec128.Dec128) Value

DecimalValue creates new boxed decimal value.

func DictIteratorValue added in v0.0.8

func DictIteratorValue(v *DictIterator) Value

func DictValue added in v0.0.8

func DictValue(v *Dict, immutable bool) Value

DictValue creates new boxed dict value.

func ErrorValue

func ErrorValue(v *Error) Value

ErrorValue creates new boxed error value.

func FloatValue

func FloatValue(f float64) Value

FloatValue creates new boxed float value.

func IntRangeIteratorValue

func IntRangeIteratorValue(v *IntRangeIterator) Value

func IntRangeValue

func IntRangeValue(v *IntRange) Value

IntRangeValue creates boxed int-range value.

func IntValue

func IntValue(i int64) Value

IntValue creates new boxed int value.

func NewArrayIteratorValue

func NewArrayIteratorValue(v []Value) Value

func NewArrayValue

func NewArrayValue(vals []Value, immutable bool) Value

NewArrayValue creates a new (heap-allocated) array value.

func NewBuiltinFunctionValue

func NewBuiltinFunctionValue(name string, fn NativeFunc, arity int8, variadic bool) Value

NewBuiltinFunctionValue creates new (heap-allocated) builtin function value.

func NewBytesIteratorValue

func NewBytesIteratorValue(vals []byte) Value

func NewBytesValue

func NewBytesValue(v []byte) Value

NewBytesValue creates new (heap-allocated) bytes value.

func NewCompiledFunctionValue

func NewCompiledFunctionValue(instructions []byte, free []*Value, sourceMap map[int]Pos, numLocals int, numParameters int8, varArgs bool) Value

NewCompiledFunctionValue creates new (heap-allocated) compiled function value.

func NewDecimalValue

func NewDecimalValue(d dec128.Dec128) Value

NewDecimalValue creates new (heap-allocated) boxed decimal value.

func NewDictIteratorValue added in v0.0.8

func NewDictIteratorValue(m map[string]Value) Value

func NewDictValue added in v0.0.8

func NewDictValue(vals map[string]Value, immutable bool) Value

NewDictValue creates new (heap-allocated) dict value.

func NewErrorValue

func NewErrorValue(payload Value) Value

NewErrorValue creates new (heap-allocated) error value.

func NewIntRangeIteratorValue

func NewIntRangeIteratorValue(start, stop, step int64) Value

func NewIntRangeValue

func NewIntRangeValue(start, stop, step int64) Value

NewIntRangeValue creates a new (heap-allocated) int-range value.

func NewRecordValue

func NewRecordValue(vals map[string]Value, immutable bool) Value

NewRecordValue creates new (heap-allocated) record value.

func NewRunesIteratorValue added in v0.0.6

func NewRunesIteratorValue(v []rune) Value

func NewRunesValue added in v0.0.6

func NewRunesValue(v []rune) Value

NewRunesValue creates new (heap-allocated) runes value.

func NewStringValue

func NewStringValue(v string) Value

NewStringValue creates new (heap-allocated) string value.

func NewTimeValue

func NewTimeValue(t time.Time) Value

NewTimeValue creates new (heap-allocated) boxed time value.

func RecordValue

func RecordValue(v *Dict, immutable bool) Value

RecordValue creates new boxed record value.

func RuneValue added in v0.0.6

func RuneValue(c rune) Value

RuneValue creates new rune value.

func RunesIteratorValue added in v0.0.6

func RunesIteratorValue(v *RunesIterator) Value

func RunesValue added in v0.0.6

func RunesValue(v *Runes) Value

RunesValue creates new boxed runes value.

func StringValue

func StringValue(v *String) Value

StringValue creates new boxed string value.

func TimeValue

func TimeValue(v *time.Time) Value

TimeValue creates new boxed time value.

func UndefinedValue

func UndefinedValue() Value

UndefinedValue creates new boxed undefined value.

func ValuePtrValue

func ValuePtrValue(p *Value) Value

ValuePtrValue creates new boxed value pointer value.

func (Value) Access

func (v Value) Access(vm VM, index Value, mode Opcode) (Value, error)

func (Value) Append

func (v Value) Append(a *Arena, args []Value) (Value, error)

func (Value) Arity

func (v Value) Arity() int8

func (Value) AsArray

func (v Value) AsArray(a *Arena) ([]Value, bool)

func (Value) AsBool

func (v Value) AsBool() (bool, bool)

func (Value) AsByte

func (v Value) AsByte() (byte, bool)

func (Value) AsBytes

func (v Value) AsBytes() ([]byte, bool)

func (Value) AsDecimal

func (v Value) AsDecimal() (dec128.Dec128, bool)

func (Value) AsDict added in v0.0.8

func (v Value) AsDict(a *Arena) (map[string]Value, bool)

func (Value) AsFloat

func (v Value) AsFloat() (float64, bool)

func (Value) AsInt

func (v Value) AsInt() (int64, bool)

func (Value) AsRune added in v0.0.6

func (v Value) AsRune() (rune, bool)

func (Value) AsRunes added in v0.0.6

func (v Value) AsRunes() ([]rune, bool)

func (Value) AsString

func (v Value) AsString() (string, bool)

func (Value) AsTime

func (v Value) AsTime() (time.Time, bool)

func (Value) Assign

func (v Value) Assign(idx Value, val Value) error

func (Value) BinaryOp

func (v Value) BinaryOp(a *Arena, op token.Token, rhs Value) (Value, error)

func (Value) Call

func (v Value) Call(vm VM, args []Value) (Value, error)

func (Value) Contains

func (v Value) Contains(e Value) bool

func (*Value) Copy

func (v *Value) Copy(a *Arena) (Value, error)

func (*Value) DecodeBinary

func (v *Value) DecodeBinary(data []byte) error

func (Value) Delete

func (v Value) Delete(key Value) (Value, error)

func (Value) EncodeBinary

func (v Value) EncodeBinary() ([]byte, error)

func (Value) EncodeJSON

func (v Value) EncodeJSON() ([]byte, error)

func (Value) Equal

func (v Value) Equal(rhs Value) bool

func (*Value) GobDecode

func (v *Value) GobDecode(data []byte) error

func (Value) GobEncode

func (v Value) GobEncode() ([]byte, error)

func (Value) Immutable

func (v Value) Immutable(a *Arena) (Value, error)

func (Value) Interface

func (v Value) Interface() any

func (Value) IsCallable

func (v Value) IsCallable() bool

func (Value) IsImmutable

func (v Value) IsImmutable() bool

func (Value) IsIterable

func (v Value) IsIterable() bool

func (Value) IsTrue

func (v Value) IsTrue() bool

func (Value) IsUserDefined

func (v Value) IsUserDefined() bool

func (Value) IsVariadic

func (v Value) IsVariadic() bool

func (Value) Iterator

func (v Value) Iterator(a *Arena) (Value, error)

func (Value) Key

func (v Value) Key(a *Arena) (Value, error)

func (Value) Len

func (v Value) Len() int64

func (Value) MethodCall

func (v Value) MethodCall(vm VM, name string, args []Value) (Value, error)

func (Value) Next

func (v Value) Next() bool

func (*Value) Set

func (v *Value) Set(val Value)

func (Value) Slice

func (v Value) Slice(a *Arena, s Value, e Value) (Value, error)

func (Value) SliceStep added in v0.0.10

func (v Value) SliceStep(a *Arena, s Value, e Value, step Value) (Value, error)

func (Value) String

func (v Value) String() string

func (Value) TypeName

func (v Value) TypeName() string

func (Value) UnaryOp

func (v Value) UnaryOp(a *Arena, op token.Token) (Value, error)

func (Value) Value

func (v Value) Value(a *Arena) (Value, error)

type ValueType

type ValueType struct {
	Name         func(v Value) string
	String       func(v Value) string
	Interface    func(v Value) any
	EncodeJSON   func(v Value) ([]byte, error)
	EncodeBinary func(v Value) ([]byte, error)
	DecodeBinary func(v *Value, data []byte) error
	IsTrue       func(v Value) bool
	Copy         func(v Value, a *Arena) (Value, error)
	Equal        func(v Value, r Value) bool
	UnaryOp      func(v Value, a *Arena, op token.Token) (Value, error)
	BinaryOp     func(v Value, a *Arena, op token.Token, r Value) (Value, error)
	MethodCall   func(v Value, vm VM, name string, args []Value) (Value, error)

	IsIterable func(v Value) bool
	Contains   func(v Value, e Value) bool
	Len        func(v Value) int64
	Iterator   func(v Value, a *Arena) (Value, error)
	Access     func(v Value, a *Arena, index Value, mode Opcode) (Value, error)
	Assign     func(v Value, index Value, r Value) error
	Append     func(v Value, a *Arena, args []Value) (Value, error)
	Slice      func(v Value, a *Arena, s Value, e Value) (Value, error)
	Delete     func(v Value, key Value) (Value, error)
	SliceStep  func(v Value, a *Arena, s Value, e Value, step Value) (Value, error)

	IsCallable func(v Value) bool
	IsVariadic func(v Value) bool
	Arity      func(v Value) int8
	Call       func(v Value, vm VM, args []Value) (Value, error)

	Next  func(v Value) bool
	Key   func(v Value, a *Arena) (Value, error)
	Value func(v Value, a *Arena) (Value, error)

	AsBool    func(v Value) (bool, bool)
	AsByte    func(v Value) (byte, bool)
	AsRune    func(v Value) (rune, bool)
	AsInt     func(v Value) (int64, bool)
	AsFloat   func(v Value) (float64, bool)
	AsDecimal func(v Value) (dec128.Dec128, bool)
	AsTime    func(v Value) (time.Time, bool)
	AsString  func(v Value) (string, bool)
	AsRunes   func(v Value) ([]rune, bool)
	AsBytes   func(v Value) ([]byte, bool)
	AsArray   func(v Value, a *Arena) ([]Value, bool)
	AsDict    func(v Value, a *Arena) (map[string]Value, bool)
}

Jump to

Keyboard shortcuts

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