objects

package
v0.4.24 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

pkg/objects/array.go

pkg/objects/builtin.go

pkg/objects/class.go

pkg/objects/float.go

pkg/objects/function.go

pkg/objects/int.go

pkg/objects/map.go

pkg/objects/methods.go

pkg/objects/module.go Module object type for runtime module representation.

pkg/objects/object.go

pkg/objects/string.go

pkg/objects/stringbuilder.go

Index

Constants

View Source
const IntCacheMax = 100000

IntCacheMax is the maximum cached integer value Extended to cover common loop indices and calculation results

View Source
const IntCacheMin = -1000

IntCacheMin is the minimum cached integer value

Variables

View Source
var (
	FLOAT_ZERO     = &Float{Value: 0.0}
	FLOAT_ONE      = &Float{Value: 1.0}
	FLOAT_NEG_ONE  = &Float{Value: -1.0}
	FLOAT_TWO      = &Float{Value: 2.0}
	FLOAT_HALF     = &Float{Value: 0.5}
	FLOAT_TEN      = &Float{Value: 10.0}
	FLOAT_HUNDRED  = &Float{Value: 100.0}
	FLOAT_THOUSAND = &Float{Value: 1000.0}
	FLOAT_PI       = &Float{Value: 3.14159265358979323846}
	FLOAT_E        = &Float{Value: 2.71828182845904523536}
)

Pre-cached common float values Unlike integers, we can only cache a small set due to the infinite nature of floats

View Source
var (
	TRUE  = &Bool{Value: true}
	FALSE = &Bool{Value: false}
)

TRUE and FALSE are singleton boolean values

View Source
var (
	STRING_EMPTY   = &String{Value: ""}
	STRING_TRUE    = &String{Value: "true"}
	STRING_FALSE   = &String{Value: "false"}
	STRING_NULL    = &String{Value: "null"}
	STRING_INT     = &String{Value: "INT"}
	STRING_FLOAT   = &String{Value: "FLOAT"}
	STRING_BOOL    = &String{Value: "BOOL"}
	STRING_STRING  = &String{Value: "STRING"}
	STRING_ARRAY   = &String{Value: "ARRAY"}
	STRING_MAP     = &String{Value: "MAP"}
	STRING_FUNC    = &String{Value: "FUNCTION"}
	STRING_BUILTIN = &String{Value: "BUILTIN"}
	STRING_ERROR   = &String{Value: "ERROR"}
	STRING_NIL     = &String{Value: "nil"}
	STRING_ZERO    = &String{Value: "0"}
	STRING_ONE     = &String{Value: "1"}
	STRING_SPACE   = &String{Value: " "}
	STRING_NEWLINE = &String{Value: "\n"}
)

Pre-cached common string values

View Source
var Builtins = map[string]*Builtin{}/* 108 elements not displayed */

Builtins contains all built-in functions

View Source
var EMPTY_ARRAY = &Array{Elements: emptyElements}

Pre-cached empty array

View Source
var EMPTY_MAP = &Map{Pairs: emptyPairs}

Pre-cached empty map

View Source
var NULL = &Null{}

NULL is the singleton null value

View Source
var TypeMethods = map[ObjectType]map[string]*Builtin{
	IntType:           intMethods,
	FloatType:         floatMethods,
	StringType:        stringMethods,
	ArrayType:         arrayMethods,
	MapType:           mapMethods,
	BoolType:          boolMethods,
	NullType:          nullMethods,
	StringBuilderType: stringBuilderMethods,
}

TypeMethods maps ObjectType -> methodName -> *Builtin

Functions

func ClearInternCache added in v0.4.23

func ClearInternCache()

ClearInternCache clears the string intern cache Use with caution - this will cause all interned strings to be re-allocated

func IsCachedInt added in v0.4.23

func IsCachedInt(val int64) bool

IsCachedInt returns true if the given value is within the cached range

func IsTruthy

func IsTruthy(obj Object) bool

IsTruthy checks if an object is truthy

func PutBufferedFloat added in v0.4.23

func PutBufferedFloat(obj *Float)

PutBufferedFloat returns a temporary Float to the global buffer

func PutBufferedInt added in v0.4.23

func PutBufferedInt(obj *Int)

PutBufferedInt returns a temporary Int to the global buffer

func PutBufferedString added in v0.4.23

func PutBufferedString(obj *String)

PutBufferedString returns a temporary String to the global buffer

func ReleaseArray added in v0.4.23

func ReleaseArray(obj *Array)

ReleaseArray returns an Array object to the pool

func ReleaseArraySlice added in v0.4.23

func ReleaseArraySlice(objs []*Array)

ReleaseArraySlice returns multiple Array objects to the pool

func ReleaseFloat added in v0.4.23

func ReleaseFloat(obj *Float)

ReleaseFloat returns a Float object to the pool if it's not a cached value This should be called when the object is no longer needed

func ReleaseFloatSlice added in v0.4.23

func ReleaseFloatSlice(objs []*Float)

ReleaseFloatSlice returns multiple Float objects to the pool This is more efficient than calling ReleaseFloat multiple times

func ReleaseInt added in v0.4.23

func ReleaseInt(obj *Int)

ReleaseInt returns an Int object to the pool if it's outside the cache range This should be called when the object is no longer needed

func ReleaseIntSlice added in v0.4.23

func ReleaseIntSlice(objs []*Int)

ReleaseIntSlice returns multiple Int objects to the pool This is more efficient than calling ReleaseInt multiple times

func ReleaseMap added in v0.4.23

func ReleaseMap(obj *Map)

ReleaseMap returns a Map object to the pool

func ReleaseMapSlice added in v0.4.23

func ReleaseMapSlice(objs []*Map)

ReleaseMapSlice returns multiple Map objects to the pool

func ReleaseString added in v0.4.23

func ReleaseString(obj *String)

ReleaseString returns a String object to the pool if it's not a cached value This should be called when the object is no longer needed

func ReleaseStringSlice added in v0.4.23

func ReleaseStringSlice(objs []*String)

ReleaseStringSlice returns multiple String objects to the pool This is more efficient than calling ReleaseString multiple times

func ResetArrayPoolStats added in v0.4.23

func ResetArrayPoolStats()

ResetArrayPoolStats resets the pool statistics counters

func ResetFloatPoolStats added in v0.4.23

func ResetFloatPoolStats()

ResetFloatPoolStats resets the pool statistics counters

func ResetIntPoolStats added in v0.4.23

func ResetIntPoolStats()

ResetIntPoolStats resets the pool statistics counters

func ResetMapPoolStats added in v0.4.23

func ResetMapPoolStats()

ResetMapPoolStats resets the pool statistics counters

func ResetStringPoolStats added in v0.4.23

func ResetStringPoolStats()

ResetStringPoolStats resets the pool statistics counters

func SetLoadPluginImpl added in v0.4.19

func SetLoadPluginImpl(fn func(path string) (Object, error)) func(path string) (Object, error)

SetLoadPluginImpl registers the loadPlugin implementation and returns the previous value

func SetRunCodeImpl added in v0.4.19

func SetRunCodeImpl(fn func(code string, args *Map) (Object, error)) func(code string, args *Map) (Object, error)

SetRunCodeImpl registers the runCode implementation and returns the previous value

func WarmArrayPool added in v0.4.23

func WarmArrayPool(count int)

WarmArrayPool pre-allocates Array objects into the pool

func WarmFloatPool added in v0.4.23

func WarmFloatPool(count int)

WarmFloatPool pre-allocates a number of Float objects into the pool This can improve performance by reducing allocations during hot paths

func WarmIntPool added in v0.4.23

func WarmIntPool(count int)

WarmIntPool pre-allocates a number of Int objects into the pool This can improve performance by reducing allocations during hot paths

func WarmMapPool added in v0.4.23

func WarmMapPool(count int)

WarmMapPool pre-allocates Map objects into the pool

func WarmStringPool added in v0.4.23

func WarmStringPool(count int)

WarmStringPool pre-allocates a number of String objects into the pool This can improve performance by reducing allocations during hot paths

Types

type Array

type Array struct {
	Elements   []Object
	LastPopped Object // Used by pop() to return the popped value
}

Array represents an array value

func NewArray added in v0.4.23

func NewArray(elements []Object) *Array

NewArray creates a new Array object with the given elements

func NewArrayWithCapacity added in v0.4.23

func NewArrayWithCapacity(capacity int) *Array

NewArrayWithCapacity creates a new Array with pre-allocated capacity

func (*Array) HashKey

func (a *Array) HashKey() HashKey

HashKey returns the hash key for map operations

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect returns the string representation

func (*Array) ToBool

func (a *Array) ToBool() *Bool

ToBool converts the array to a boolean

func (*Array) Type

func (a *Array) Type() ObjectType

Type returns the object type

func (*Array) TypeTag

func (a *Array) TypeTag() TypeTag

TypeTag returns the type tag for fast type checking

type ArrayPoolStats added in v0.4.23

type ArrayPoolStats struct {
	CacheHits int64
	PoolHits  int64
	Created   int64
	Released  int64
}

ArrayPoolStats tracks statistics about array pool usage

func GetArrayPoolStats added in v0.4.23

func GetArrayPoolStats() ArrayPoolStats

GetArrayPoolStats returns current statistics about array pool usage

type Bool

type Bool struct {
	Value bool
}

Bool represents a boolean value

func (*Bool) HashKey

func (b *Bool) HashKey() HashKey

func (*Bool) Inspect

func (b *Bool) Inspect() string

func (*Bool) ToBool

func (b *Bool) ToBool() *Bool

func (*Bool) Type

func (b *Bool) Type() ObjectType

func (*Bool) TypeTag

func (b *Bool) TypeTag() TypeTag

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

Builtin represents a built-in function

func GetMethod

func GetMethod(objType ObjectType, name string) (*Builtin, bool)

GetMethod returns the builtin method for the given object type and method name

func (*Builtin) HashKey

func (b *Builtin) HashKey() HashKey

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) ToBool

func (b *Builtin) ToBool() *Bool

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

func (*Builtin) TypeTag

func (b *Builtin) TypeTag() TypeTag

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

BuiltinFunction is the type for built-in functions

type Class

type Class struct {
	Name       string
	SuperClass *Class
	Methods    map[string]Object // methods are CompiledFunction objects
	InitMethod Object            // constructor method
	Fields     map[string]Object // default field values
}

Class represents a class definition

func (*Class) HashKey

func (c *Class) HashKey() HashKey

func (*Class) Inspect

func (c *Class) Inspect() string

func (*Class) ToBool

func (c *Class) ToBool() *Bool

func (*Class) Type

func (c *Class) Type() ObjectType

func (*Class) TypeTag

func (c *Class) TypeTag() TypeTag

type CompiledFunction

type CompiledFunction struct {
	Instructions  []byte
	NumLocals     int
	NumParameters int
	Name          string
}

CompiledFunction represents a compiled function for the VM

func (*CompiledFunction) HashKey

func (cf *CompiledFunction) HashKey() HashKey

func (*CompiledFunction) Inspect

func (cf *CompiledFunction) Inspect() string

func (*CompiledFunction) ToBool

func (cf *CompiledFunction) ToBool() *Bool

func (*CompiledFunction) Type

func (cf *CompiledFunction) Type() ObjectType

func (*CompiledFunction) TypeTag

func (cf *CompiledFunction) TypeTag() TypeTag

type Environment

type Environment struct {
	Store map[string]Object
	Outer *Environment
}

Environment represents a variable scope

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment creates a new environment with an outer scope

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates a new environment

func (*Environment) Get

func (e *Environment) Get(name string) (Object, bool)

Get retrieves a variable from the environment

func (*Environment) Set

func (e *Environment) Set(name string, val Object) Object

Set sets a variable in the environment

type Error

type Error struct {
	Message string
}

Error represents a runtime error

func (*Error) HashKey

func (e *Error) HashKey() HashKey

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) ToBool

func (e *Error) ToBool() *Bool

func (*Error) Type

func (e *Error) Type() ObjectType

func (*Error) TypeTag

func (e *Error) TypeTag() TypeTag

type Float

type Float struct {
	Value float64
}

Float represents a floating-point value

func GetBufferedFloat added in v0.4.23

func GetBufferedFloat(val float64) *Float

GetBufferedFloat gets a temporary Float using the global buffer

func NewFloat added in v0.4.23

func NewFloat(val float64) *Float

NewFloat creates a new Float object, using cached values for common floats

func NewFloatSlice added in v0.4.23

func NewFloatSlice(values []float64) []*Float

NewFloatSlice creates multiple Float objects efficiently This is optimized for batch operations

func (*Float) HashKey

func (f *Float) HashKey() HashKey

HashKey returns the hash key for map operations

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect returns the string representation

func (*Float) ToBool

func (f *Float) ToBool() *Bool

ToBool converts the float to a boolean

func (*Float) Type

func (f *Float) Type() ObjectType

Type returns the object type

func (*Float) TypeTag

func (f *Float) TypeTag() TypeTag

TypeTag returns the type tag for fast type checking

type FloatPoolStats added in v0.4.23

type FloatPoolStats struct {
	// CacheHits is the number of times a cached float was returned
	CacheHits int64
	// PoolHits is the number of times a pooled float was reused
	PoolHits int64
	// Created is the number of new floats allocated by the pool
	Created int64
	// Released is the number of floats returned to the pool
	Released int64
}

FloatPoolStats tracks statistics about float pool usage

func GetFloatPoolStats added in v0.4.23

func GetFloatPoolStats() FloatPoolStats

GetFloatPoolStats returns current statistics about float pool usage

type Function

type Function struct {
	Parameters []*Identifier
	Body       interface{} // Will be *ast.BlockStatement, using interface{} to avoid import cycle
	Env        *Environment
	Name       string // Optional: for named functions
}

Function represents a user-defined function

func (*Function) HashKey

func (f *Function) HashKey() HashKey

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) ToBool

func (f *Function) ToBool() *Bool

func (*Function) Type

func (f *Function) Type() ObjectType

func (*Function) TypeTag

func (f *Function) TypeTag() TypeTag

type HashKey

type HashKey struct {
	Type  ObjectType
	Value uint64
}

HashKey is used for map keys

type Identifier

type Identifier struct {
	Value string
}

Identifier represents an identifier (used in function parameters)

func (*Identifier) String

func (i *Identifier) String() string

type Instance

type Instance struct {
	Class  *Class
	Fields map[string]Object
}

Instance represents an instance of a class

func (*Instance) HashKey

func (i *Instance) HashKey() HashKey

func (*Instance) Inspect

func (i *Instance) Inspect() string

func (*Instance) ToBool

func (i *Instance) ToBool() *Bool

func (*Instance) Type

func (i *Instance) Type() ObjectType

func (*Instance) TypeTag

func (i *Instance) TypeTag() TypeTag

type Int

type Int struct {
	Value int64
}

Int represents an integer value

func GetBufferedInt added in v0.4.23

func GetBufferedInt(val int64) *Int

GetBufferedInt gets a temporary Int using the global buffer

func NewInt

func NewInt(val int64) *Int

NewInt creates a new Int object, using cache for small values

func NewIntSlice added in v0.4.23

func NewIntSlice(values []int64) []*Int

NewIntSlice creates multiple Int objects efficiently This is optimized for batch operations

func (*Int) HashKey

func (i *Int) HashKey() HashKey

HashKey returns the hash key for map operations

func (*Int) Inspect

func (i *Int) Inspect() string

Inspect returns the string representation

func (*Int) ToBool

func (i *Int) ToBool() *Bool

ToBool converts the integer to a boolean

func (*Int) Type

func (i *Int) Type() ObjectType

Type returns the object type

func (*Int) TypeTag

func (i *Int) TypeTag() TypeTag

TypeTag returns the type tag for fast type checking

type IntPoolStats added in v0.4.23

type IntPoolStats struct {
	// CacheHits is the number of times a cached integer was returned
	CacheHits int64
	// PoolHits is the number of times a pooled integer was reused
	PoolHits int64
	// PoolMisses is the number of times a new integer had to be allocated
	PoolMisses int64
	// Created is the number of new integers allocated by the pool
	Created int64
	// Released is the number of integers returned to the pool
	Released int64
}

IntPoolStats tracks statistics about integer pool usage

func GetIntPoolStats added in v0.4.23

func GetIntPoolStats() IntPoolStats

GetIntPoolStats returns current statistics about integer pool usage

type Map

type Map struct {
	Pairs map[HashKey]MapPair
	// contains filtered or unexported fields
}

Map represents a map value

func NewMap added in v0.4.23

func NewMap(pairs map[HashKey]MapPair) *Map

NewMap creates a new Map object with the given pairs

func NewMapWithCapacity added in v0.4.23

func NewMapWithCapacity(capacity int) *Map

NewMapWithCapacity creates a new Map with pre-allocated capacity

func (*Map) GetSortedKeys added in v0.4.23

func (m *Map) GetSortedKeys() []Object

GetSortedKeys returns the keys in sorted order, caching the result

func (*Map) HashKey

func (m *Map) HashKey() HashKey

HashKey returns the hash key for map operations

func (*Map) Inspect

func (m *Map) Inspect() string

Inspect returns the string representation

func (*Map) InvalidateKeysCache added in v0.4.23

func (m *Map) InvalidateKeysCache()

InvalidateKeysCache marks the sorted keys cache as invalid Call this when the map is modified

func (*Map) ToBool

func (m *Map) ToBool() *Bool

ToBool converts the map to a boolean

func (*Map) Type

func (m *Map) Type() ObjectType

Type returns the object type

func (*Map) TypeTag

func (m *Map) TypeTag() TypeTag

TypeTag returns the type tag for fast type checking

type MapPair

type MapPair struct {
	Key   Object
	Value Object
}

MapPair represents a key-value pair in a map

type MapPoolStats added in v0.4.23

type MapPoolStats struct {
	CacheHits int64
	PoolHits  int64
	Created   int64
	Released  int64
}

MapPoolStats tracks statistics about map pool usage

func GetMapPoolStats added in v0.4.23

func GetMapPoolStats() MapPoolStats

GetMapPoolStats returns current statistics about map pool usage

type Module

type Module struct {
	// Name is the module's identifier (typically the file path)
	Name string

	// Exports maps exported symbol names to their values
	Exports map[string]Object

	// Globals holds the module's global variables state.
	// This is needed so exported functions can access module-level variables.
	Globals []Object
}

Module represents a loaded module with its exported symbols. Modules are created when a source file is imported and compiled, and they hold all exported values accessible to importers.

func (*Module) HashKey

func (m *Module) HashKey() HashKey

HashKey returns a hash key for the module. Modules are not hashable in a meaningful way, so we return a constant.

func (*Module) Inspect

func (m *Module) Inspect() string

Inspect returns a string representation of the module.

func (*Module) ToBool

func (m *Module) ToBool() *Bool

ToBool converts the module to a boolean (always true).

func (*Module) Type

func (m *Module) Type() ObjectType

Type returns the object type.

func (*Module) TypeTag

func (m *Module) TypeTag() TypeTag

TypeTag returns the type tag for fast type checking.

type Null

type Null struct{}

Null represents the null value

func (*Null) HashKey

func (n *Null) HashKey() HashKey

func (*Null) Inspect

func (n *Null) Inspect() string

func (*Null) ToBool

func (n *Null) ToBool() *Bool

func (*Null) Type

func (n *Null) Type() ObjectType

func (*Null) TypeTag

func (n *Null) TypeTag() TypeTag

type Object

type Object interface {
	Type() ObjectType
	TypeTag() TypeTag // Fast type check without string comparison
	Inspect() string
	ToBool() *Bool
	HashKey() HashKey
}

Object is the base interface for all values in Xxlang

type ObjectType

type ObjectType string

ObjectType represents the type of an object

const (
	NullType          ObjectType = "NULL"
	IntType           ObjectType = "INT"
	FloatType         ObjectType = "FLOAT"
	StringType        ObjectType = "STRING"
	BoolType          ObjectType = "BOOL"
	ArrayType         ObjectType = "ARRAY"
	MapType           ObjectType = "MAP"
	FunctionType      ObjectType = "FUNCTION"
	BuiltinType       ObjectType = "BUILTIN"
	BytesType         ObjectType = "BYTES"
	ClassType         ObjectType = "CLASS"
	InstanceType      ObjectType = "INSTANCE"
	ErrorType         ObjectType = "ERROR"
	ReturnType        ObjectType = "RETURN"
	ClosureType       ObjectType = "CLOSURE"
	ModuleType        ObjectType = "MODULE"
	StringBuilderType ObjectType = "STRING_BUILDER"
)

Object types

const CompiledFunctionType ObjectType = "COMPILED_FUNCTION"

CompiledFunctionType is the type for compiled functions

type Return

type Return struct {
	Value Object
}

Return represents a return value (used internally)

func (*Return) HashKey

func (r *Return) HashKey() HashKey

func (*Return) Inspect

func (r *Return) Inspect() string

func (*Return) ToBool

func (r *Return) ToBool() *Bool

func (*Return) Type

func (r *Return) Type() ObjectType

func (*Return) TypeTag

func (r *Return) TypeTag() TypeTag

type String

type String struct {
	Value string
}

String represents a string value

func GetBufferedString added in v0.4.23

func GetBufferedString(val string) *String

GetBufferedString gets a temporary String using the global buffer

func InternBatch

func InternBatch(strings []string) []*String

InternBatch pre-interns a batch of strings

func InternString

func InternString(val string) *String

InternString returns a cached *String for the given value This provides permanent caching for strings that are used often Use this for strings that will be reused many times (e.g., identifiers, keywords)

func NewString added in v0.4.23

func NewString(val string) *String

NewString creates a new String object, using cached values for common strings

func NewStringSlice added in v0.4.23

func NewStringSlice(values []string) []*String

NewStringSlice creates multiple String objects efficiently This is optimized for batch operations

func (*String) HashKey

func (s *String) HashKey() HashKey

HashKey returns the hash key for map operations

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns the string representation

func (*String) ToBool

func (s *String) ToBool() *Bool

ToBool converts the string to a boolean

func (*String) Type

func (s *String) Type() ObjectType

Type returns the object type

func (*String) TypeTag

func (s *String) TypeTag() TypeTag

TypeTag returns the type tag for fast type checking

type StringBuilder added in v0.4.19

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

StringBuilder is a mutable string builder for efficient string concatenation. Unlike regular string concatenation which creates a new string each time, StringBuilder uses an internal buffer to accumulate strings efficiently.

func NewStringBuilder added in v0.4.19

func NewStringBuilder() *StringBuilder

NewStringBuilder creates a new StringBuilder instance.

func (*StringBuilder) Cap added in v0.4.19

func (sb *StringBuilder) Cap() int

Cap returns the current capacity of the builder's internal buffer.

func (*StringBuilder) Clear added in v0.4.19

func (sb *StringBuilder) Clear()

Clear resets the builder, removing all content.

func (*StringBuilder) Grow added in v0.4.19

func (sb *StringBuilder) Grow(n int)

Grow grows the builder's capacity to hold at least n more bytes.

func (*StringBuilder) HashKey added in v0.4.19

func (sb *StringBuilder) HashKey() HashKey

HashKey returns a hash key for the StringBuilder.

func (*StringBuilder) Inspect added in v0.4.19

func (sb *StringBuilder) Inspect() string

Inspect returns a string representation.

func (*StringBuilder) Len added in v0.4.19

func (sb *StringBuilder) Len() int

Len returns the current length of the accumulated string.

func (*StringBuilder) Reset added in v0.4.19

func (sb *StringBuilder) Reset()

Reset is an alias for Clear.

func (*StringBuilder) String added in v0.4.19

func (sb *StringBuilder) String() string

String returns the accumulated string.

func (*StringBuilder) ToBool added in v0.4.19

func (sb *StringBuilder) ToBool() *Bool

ToBool returns true (StringBuilder is always truthy).

func (*StringBuilder) Type added in v0.4.19

func (sb *StringBuilder) Type() ObjectType

Type returns the object type.

func (*StringBuilder) TypeTag added in v0.4.19

func (sb *StringBuilder) TypeTag() TypeTag

TypeTag returns the fast type tag.

func (*StringBuilder) Write added in v0.4.19

func (sb *StringBuilder) Write(s string) int

Write appends a string to the builder.

func (*StringBuilder) WriteLine added in v0.4.19

func (sb *StringBuilder) WriteLine(s string) int

WriteLine appends a string followed by a newline to the builder.

type StringPoolStats added in v0.4.23

type StringPoolStats struct {
	// CacheHits is the number of times a cached string was returned
	CacheHits int64
	// InternHits is the number of times an interned string was returned
	InternHits int64
	// PoolHits is the number of times a pooled string was reused
	PoolHits int64
	// Created is the number of new strings allocated by the pool
	Created int64
	// Released is the number of strings returned to the pool
	Released int64
	// Interned is the number of strings currently in the intern cache
	Interned int64
}

StringPoolStats tracks statistics about string pool usage

func GetStringPoolStats added in v0.4.23

func GetStringPoolStats() StringPoolStats

GetStringPoolStats returns current statistics about string pool usage

type TypeTag

type TypeTag uint8

TypeTag is a fast integer type identifier for hot path checks

const (
	TagNull TypeTag = iota
	TagInt
	TagFloat
	TagString
	TagBool
	TagArray
	TagMap
	TagFunction
	TagBuiltin
	TagBytes
	TagClass
	TagInstance
	TagError
	TagReturn
	TagClosure
	TagModule
	TagStringBuilder
	TagUnknown
)

Type tags for fast type checking (must match ObjectType order)

const TagCompiledFunction TypeTag = TagClosure // Use same tag as Closure

TagCompiledFunction is the type tag for compiled functions

Jump to

Keyboard shortcuts

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