types

package
v0.0.0-...-cd7e48c Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BoolType = TypeInfo{
		Kind: KindBool,
		Name: "bool",
		Size: 1,
	}

	IntType = TypeInfo{
		Kind: KindInt64,
		Name: "int",
		Size: 8,
	}

	FloatType = TypeInfo{
		Kind: KindFloat64,
		Name: "float",
		Size: 8,
	}

	StringType = TypeInfo{
		Kind: KindString,
		Name: "string",
		Size: -1,
	}

	NilType = TypeInfo{
		Kind: KindNil,
		Name: "nil",
		Size: 0,
	}
)

Predefined type info instances

Functions

func CanConvert

func CanConvert(sourceType, targetType TypeInfo) bool

CanConvert returns true if a value can be converted to the target type

func ConvertToGo

func ConvertToGo(value Value) interface{}

ConvertToGo converts a Value to a native Go value

Types

type BoolValue

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

BoolValue represents a boolean value

func NewBool

func NewBool(v bool) *BoolValue

func (*BoolValue) Equal

func (b *BoolValue) Equal(other Value) bool

func (*BoolValue) Hash

func (b *BoolValue) Hash() uint64

func (*BoolValue) String

func (b *BoolValue) String() string

func (*BoolValue) Type

func (b *BoolValue) Type() TypeInfo

func (*BoolValue) Value

func (b *BoolValue) Value() bool

type FieldInfo

type FieldInfo struct {
	Name   string
	Type   TypeInfo
	Index  int
	Offset int
}

FieldInfo contains information about a field

type FloatValue

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

FloatValue represents a floating-point value (float64)

func NewFloat

func NewFloat(v float64) *FloatValue

func (*FloatValue) Equal

func (f *FloatValue) Equal(other Value) bool

func (*FloatValue) Hash

func (f *FloatValue) Hash() uint64

func (*FloatValue) String

func (f *FloatValue) String() string

func (*FloatValue) Type

func (f *FloatValue) Type() TypeInfo

func (*FloatValue) Value

func (f *FloatValue) Value() float64

type FuncValue

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

FuncValue represents a function/lambda value

func NewFunc

func NewFunc(parameters []string, body interface{}, closure map[string]Value, name string) *FuncValue

func (*FuncValue) Body

func (f *FuncValue) Body() interface{}

func (*FuncValue) Closure

func (f *FuncValue) Closure() map[string]Value

func (*FuncValue) Equal

func (f *FuncValue) Equal(other Value) bool

func (*FuncValue) Hash

func (f *FuncValue) Hash() uint64

func (*FuncValue) Name

func (f *FuncValue) Name() string

func (*FuncValue) Parameters

func (f *FuncValue) Parameters() []string

func (*FuncValue) String

func (f *FuncValue) String() string

func (*FuncValue) Type

func (f *FuncValue) Type() TypeInfo

type IntValue

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

IntValue represents an integer value (int64)

func NewInt

func NewInt(v int64) *IntValue

func (*IntValue) Equal

func (i *IntValue) Equal(other Value) bool

func (*IntValue) Hash

func (i *IntValue) Hash() uint64

func (*IntValue) String

func (i *IntValue) String() string

func (*IntValue) Type

func (i *IntValue) Type() TypeInfo

func (*IntValue) Value

func (i *IntValue) Value() int64

type MapValue

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

MapValue represents a map value

func NewMap

func NewMap(values map[string]Value, keyType, valType TypeInfo) *MapValue

func (*MapValue) Equal

func (m *MapValue) Equal(other Value) bool

func (*MapValue) Get

func (m *MapValue) Get(key string) (Value, bool)

Get returns the value for a key and whether the key exists

func (*MapValue) Has

func (m *MapValue) Has(key string) bool

func (*MapValue) Hash

func (m *MapValue) Hash() uint64

func (*MapValue) Keys

func (m *MapValue) Keys() []string

Keys returns all keys in the map

func (*MapValue) Len

func (m *MapValue) Len() int

func (*MapValue) String

func (m *MapValue) String() string

func (*MapValue) Type

func (m *MapValue) Type() TypeInfo

func (*MapValue) ValueType

func (m *MapValue) ValueType() TypeInfo

ValueType returns the value type of the map

func (*MapValue) Values

func (m *MapValue) Values() map[string]Value

type MethodInfo

type MethodInfo struct {
	Name     string
	Params   []TypeInfo
	Returns  []TypeInfo
	Variadic bool
}

MethodInfo contains information about a method

type NilValue

type NilValue struct{}

NilValue represents a nil/null value

func NewNil

func NewNil() *NilValue

func (*NilValue) Equal

func (n *NilValue) Equal(other Value) bool

func (*NilValue) Hash

func (n *NilValue) Hash() uint64

func (*NilValue) String

func (n *NilValue) String() string

func (*NilValue) Type

func (n *NilValue) Type() TypeInfo

type OptimizedValue

type OptimizedValue struct {
	Type      ValueType
	IntVal    int64
	FloatVal  float64
	StringVal string
	BoolVal   bool

	// For complex types, we use a pointer to avoid copying large data
	ComplexVal unsafe.Pointer
}

OptimizedValue is a union type that eliminates interface overhead This is the P0 optimization suggested in PERFORMANCE_SUMMARY.md

func AddOptimized

func AddOptimized(left, right *OptimizedValue) (OptimizedValue, error)

AddOptimized performs optimized addition for union types

func CompareOptimized

func CompareOptimized(left, right *OptimizedValue, op string) (OptimizedValue, error)

CompareOptimized performs optimized comparison for union types

func NewOptimizedBool

func NewOptimizedBool(v bool) OptimizedValue

NewOptimizedBool creates an optimized boolean value

func NewOptimizedFloat

func NewOptimizedFloat(v float64) OptimizedValue

NewOptimizedFloat creates an optimized float value

func NewOptimizedInt

func NewOptimizedInt(v int64) OptimizedValue

NewOptimizedInt creates an optimized integer value

func NewOptimizedNil

func NewOptimizedNil() OptimizedValue

NewOptimizedNil creates an optimized nil value

func NewOptimizedString

func NewOptimizedString(v string) OptimizedValue

NewOptimizedString creates an optimized string value

func (*OptimizedValue) Equal

func (v *OptimizedValue) Equal(other *OptimizedValue) bool

Equal compares two optimized values for equality

func (*OptimizedValue) GetBool

func (v *OptimizedValue) GetBool() bool

GetBool returns the boolean value (assumes IsBool() is true)

func (*OptimizedValue) GetFloat

func (v *OptimizedValue) GetFloat() float64

GetFloat returns the float value (assumes IsFloat() is true)

func (*OptimizedValue) GetInt

func (v *OptimizedValue) GetInt() int64

GetInt returns the integer value (assumes IsInt() is true)

func (*OptimizedValue) GetString

func (v *OptimizedValue) GetString() string

GetString returns the string value (assumes IsString() is true)

func (*OptimizedValue) GetType

func (v *OptimizedValue) GetType() TypeInfo

GetType returns the TypeInfo for this value

func (*OptimizedValue) Hash

func (v *OptimizedValue) Hash() uint64

Hash returns a hash value for this value

func (*OptimizedValue) IsBool

func (v *OptimizedValue) IsBool() bool

IsBool returns true if this is a boolean value

func (*OptimizedValue) IsFloat

func (v *OptimizedValue) IsFloat() bool

IsFloat returns true if this is a float value

func (*OptimizedValue) IsInt

func (v *OptimizedValue) IsInt() bool

IsInt returns true if this is an integer value

func (*OptimizedValue) IsNil

func (v *OptimizedValue) IsNil() bool

IsNil returns true if this is a nil value

func (*OptimizedValue) IsNumeric

func (v *OptimizedValue) IsNumeric() bool

IsNumeric returns true if this value is numeric (int or float)

func (*OptimizedValue) IsString

func (v *OptimizedValue) IsString() bool

IsString returns true if this is a string value

func (*OptimizedValue) String

func (v *OptimizedValue) String() string

String returns string representation

func (*OptimizedValue) ToBool

func (v *OptimizedValue) ToBool() bool

ToBool converts an optimized value to boolean for truthiness testing

func (*OptimizedValue) ToFloat64

func (v *OptimizedValue) ToFloat64() (float64, bool)

ToFloat64 converts numeric values to float64

func (*OptimizedValue) ToInt64

func (v *OptimizedValue) ToInt64() (int64, bool)

ToInt64 converts numeric values to int64

type PlaceholderExprValue

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

PlaceholderExprValue represents a compiled placeholder expression that can be evaluated later

func NewPlaceholderExpr

func NewPlaceholderExpr(instructions []byte, constants []Value, operator string, operand Value) *PlaceholderExprValue

func (*PlaceholderExprValue) Constants

func (p *PlaceholderExprValue) Constants() []Value

func (*PlaceholderExprValue) Equal

func (p *PlaceholderExprValue) Equal(other Value) bool

func (*PlaceholderExprValue) Hash

func (p *PlaceholderExprValue) Hash() uint64

func (*PlaceholderExprValue) Instructions

func (p *PlaceholderExprValue) Instructions() []byte

func (*PlaceholderExprValue) Operand

func (p *PlaceholderExprValue) Operand() Value

func (*PlaceholderExprValue) Operator

func (p *PlaceholderExprValue) Operator() string

func (*PlaceholderExprValue) String

func (p *PlaceholderExprValue) String() string

func (*PlaceholderExprValue) Type

func (p *PlaceholderExprValue) Type() TypeInfo

type SliceValue

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

SliceValue represents a slice/array value

func NewSlice

func NewSlice(values []Value, elemType TypeInfo) *SliceValue

func (*SliceValue) ElementType

func (s *SliceValue) ElementType() TypeInfo

ElementType returns the element type of the slice

func (*SliceValue) Equal

func (s *SliceValue) Equal(other Value) bool

func (*SliceValue) Get

func (s *SliceValue) Get(index int) Value

func (*SliceValue) Hash

func (s *SliceValue) Hash() uint64

func (*SliceValue) Len

func (s *SliceValue) Len() int

func (*SliceValue) String

func (s *SliceValue) String() string

func (*SliceValue) Type

func (s *SliceValue) Type() TypeInfo

func (*SliceValue) Values

func (s *SliceValue) Values() []Value

type StringValue

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

StringValue represents a string value

func NewString

func NewString(v string) *StringValue

func (*StringValue) Equal

func (s *StringValue) Equal(other Value) bool

func (*StringValue) Hash

func (s *StringValue) Hash() uint64

func (*StringValue) String

func (s *StringValue) String() string

func (*StringValue) Type

func (s *StringValue) Type() TypeInfo

func (*StringValue) Value

func (s *StringValue) Value() string

type TypeInfo

type TypeInfo struct {
	Kind     TypeKind
	Name     string
	Size     int // -1 for variable size
	Methods  []MethodInfo
	Fields   []FieldInfo
	ElemType *TypeInfo // for arrays, slices, pointers
	KeyType  *TypeInfo // for maps
	ValType  *TypeInfo // for maps
}

TypeInfo contains static information about a type

func (TypeInfo) Assignable

func (t TypeInfo) Assignable(other TypeInfo) bool

Assignable returns true if a value of 'other' type can be assigned to this type

func (TypeInfo) Compatible

func (t TypeInfo) Compatible(other TypeInfo) bool

Compatible returns true if this type is compatible with another type

func (TypeInfo) IsComparable

func (t TypeInfo) IsComparable() bool

IsComparable returns true if values of this type can be compared

func (TypeInfo) IsFloat

func (t TypeInfo) IsFloat() bool

IsFloat returns true if the type is a floating-point type

func (TypeInfo) IsInteger

func (t TypeInfo) IsInteger() bool

IsInteger returns true if the type is an integer type

func (TypeInfo) IsNumeric

func (t TypeInfo) IsNumeric() bool

IsNumeric returns true if the type is numeric

func (TypeInfo) IsOrdered

func (t TypeInfo) IsOrdered() bool

IsOrdered returns true if values of this type can be ordered (support <, >, etc.)

func (TypeInfo) String

func (t TypeInfo) String() string

String returns the string representation of TypeInfo

type TypeKind

type TypeKind uint8

TypeKind represents the kind of a type

const (
	KindBool TypeKind = iota
	KindInt
	KindInt8
	KindInt16
	KindInt32
	KindInt64
	KindUint
	KindUint8
	KindUint16
	KindUint32
	KindUint64
	KindFloat32
	KindFloat64
	KindString
	KindArray
	KindSlice
	KindMap
	KindStruct
	KindInterface
	KindPointer
	KindFunc
	KindNil
	KindUnknown // Added for type inference when type cannot be determined
)

func (TypeKind) String

func (k TypeKind) String() string

String returns the string representation of TypeKind

type Value

type Value interface {
	Type() TypeInfo
	String() string
	Equal(other Value) bool
	Hash() uint64
}

Value represents any value that can be processed by expressions

func ConvertFromGo

func ConvertFromGo(v interface{}) Value

ConvertFromGo converts a native Go value to a Value

func ConvertValue

func ConvertValue(value Value, targetType TypeInfo) (Value, error)

ConvertValue converts a value from one type to another

type ValueType

type ValueType uint8

ValueType represents the type of a value in the union

const (
	TypeBool ValueType = iota
	TypeInt64
	TypeFloat64
	TypeString
	TypeSlice
	TypeMap
	TypeNil
	TypeFunc
	TypePlaceholder
)

Jump to

Keyboard shortcuts

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