Documentation ¶
Overview ¶
Package vm contains the Elk Virtual Machine. It interprets Elk Bytecode produced by the Elk compiler.
Index ¶
- Constants
- Variables
- func Accessor(container *value.MethodContainer, attrName string)
- func Alias(container *value.MethodContainer, newName, oldName string)
- func ArrayListContains(vm *VM, list *value.ArrayList, val value.Value) (bool, value.Value)
- func ArrayListEqual(vm *VM, x, y *value.ArrayList) (bool, value.Value)
- func ArrayTupleContains(vm *VM, tuple *value.ArrayTuple, val value.Value) (bool, value.Value)
- func ArrayTupleEqual(vm *VM, x, y *value.ArrayTuple) (bool, value.Value)
- func BeginlessClosedRangeContains(vm *VM, r *value.BeginlessClosedRange, val value.Value) (bool, value.Value)
- func BeginlessClosedRangeEqual(vm *VM, x, y *value.BeginlessClosedRange) (bool, value.Value)
- func BeginlessOpenRangeContains(vm *VM, r *value.BeginlessOpenRange, val value.Value) (bool, value.Value)
- func BeginlessOpenRangeEqual(vm *VM, x, y *value.BeginlessOpenRange) (bool, value.Value)
- func ClosedRangeContains(vm *VM, r *value.ClosedRange, val value.Value) (bool, value.Value)
- func ClosedRangeEqual(vm *VM, x *value.ClosedRange, y *value.ClosedRange) (bool, value.Value)
- func ClosedRangeIteratorNext(vm *VM, i *value.ClosedRangeIterator) (value.Value, value.Value)
- func Decrement(vm *VM, val value.Value) (value.Value, value.Value)
- func Def(container *value.MethodContainer, name string, function NativeFunction, ...)
- func DefineAccessor(container *value.MethodContainer, attrName value.Symbol)
- func DefineGetter(container *value.MethodContainer, name value.Symbol)
- func DefineNativeMethod(container *value.MethodContainer, name value.Symbol, params int, optParams int, ...) (err value.Value)
- func DefineSetter(container *value.MethodContainer, attrName value.Symbol)
- func EndlessClosedRangeContains(vm *VM, r *value.EndlessClosedRange, val value.Value) (bool, value.Value)
- func EndlessClosedRangeEqual(vm *VM, x *value.EndlessClosedRange, y *value.EndlessClosedRange) (bool, value.Value)
- func EndlessClosedRangeIteratorNext(vm *VM, i *value.EndlessClosedRangeIterator) (value.Value, value.Value)
- func EndlessOpenRangeContains(vm *VM, r *value.EndlessOpenRange, val value.Value) (bool, value.Value)
- func EndlessOpenRangeEqual(vm *VM, x, y *value.EndlessOpenRange) (bool, value.Value)
- func EndlessOpenRangeIteratorNext(vm *VM, i *value.EndlessOpenRangeIterator) (value.Value, value.Value)
- func Equal(vm *VM, left, right value.Value) (value.Value, value.Value)
- func Getter(container *value.MethodContainer, name string)
- func GreaterThan(vm *VM, left, right value.Value) (value.Value, value.Value)
- func GreaterThanEqual(vm *VM, left, right value.Value) (value.Value, value.Value)
- func Hash(vm *VM, key value.Value) (value.UInt64, value.Value)
- func HashMapConcat(vm *VM, x *value.HashMap, y *value.HashMap) (*value.HashMap, value.Value)
- func HashMapContains(vm *VM, hashMap *value.HashMap, pair *value.Pair) (bool, value.Value)
- func HashMapContainsKey(vm *VM, hashMap *value.HashMap, key value.Value) (bool, value.Value)
- func HashMapContainsValue(vm *VM, hashMap *value.HashMap, val value.Value) (bool, value.Value)
- func HashMapCopy(vm *VM, target *value.HashMap, source *value.HashMap) value.Value
- func HashMapCopyTable(vm *VM, target *value.HashMap, source []value.Pair) value.Value
- func HashMapDelete(vm *VM, hashMap *value.HashMap, key value.Value) (bool, value.Value)
- func HashMapEqual(vm *VM, x *value.HashMap, y *value.HashMap) (bool, value.Value)
- func HashMapGet(vm *VM, hashMap *value.HashMap, key value.Value) (value.Value, value.Value)
- func HashMapGrow(vm *VM, hashMap *value.HashMap, newSlots int) value.Value
- func HashMapIndex(vm *VM, hashMap *value.HashMap, key value.Value) (int, value.Value)
- func HashMapLaxEqual(vm *VM, x *value.HashMap, y *value.HashMap) (bool, value.Value)
- func HashMapSet(vm *VM, hashMap *value.HashMap, key, val value.Value) value.Value
- func HashMapSetCapacity(vm *VM, hashMap *value.HashMap, capacity int) value.Value
- func HashMapSetWithMaxLoad(vm *VM, hashMap *value.HashMap, key, val value.Value, maxLoad float64) value.Value
- func HashRecordConcat(vm *VM, x *value.HashRecord, y *value.HashRecord) (*value.HashMap, value.Value)
- func HashRecordContains(vm *VM, hrec *value.HashRecord, pair *value.Pair) (bool, value.Value)
- func HashRecordContainsKey(vm *VM, hrec *value.HashRecord, key value.Value) (bool, value.Value)
- func HashRecordContainsValue(vm *VM, hrec *value.HashRecord, val value.Value) (bool, value.Value)
- func HashRecordCopy(vm *VM, target *value.HashRecord, source *value.HashRecord) value.Value
- func HashRecordCopyTable(vm *VM, target *value.HashRecord, source []value.Pair) value.Value
- func HashRecordDelete(vm *VM, hashRecord *value.HashRecord, key value.Value) (bool, value.Value)
- func HashRecordEqual(vm *VM, x *value.HashRecord, y *value.HashRecord) (bool, value.Value)
- func HashRecordGet(vm *VM, hashRecord *value.HashRecord, key value.Value) (value.Value, value.Value)
- func HashRecordGrow(vm *VM, hashRecord *value.HashRecord, newSlots int) value.Value
- func HashRecordLaxEqual(vm *VM, x *value.HashRecord, y *value.HashRecord) (bool, value.Value)
- func HashRecordSet(vm *VM, hashRecord *value.HashRecord, key, val value.Value) value.Value
- func HashRecordSetCapacity(vm *VM, hashRecord *value.HashRecord, capacity int) value.Value
- func HashRecordSetWithMaxLoad(vm *VM, hashRecord *value.HashRecord, key, val value.Value, maxLoad float64) value.Value
- func HashSetAppend(vm *VM, set *value.HashSet, val value.Value) value.Value
- func HashSetAppendWithMaxLoad(vm *VM, set *value.HashSet, val value.Value, maxLoad float64) value.Value
- func HashSetContains(vm *VM, set *value.HashSet, val value.Value) (bool, value.Value)
- func HashSetCopy(vm *VM, target *value.HashSet, source *value.HashSet) value.Value
- func HashSetCopyTable(vm *VM, target *value.HashSet, source []value.Value) value.Value
- func HashSetDelete(vm *VM, hashSet *value.HashSet, val value.Value) (bool, value.Value)
- func HashSetEqual(vm *VM, x *value.HashSet, y *value.HashSet) (bool, value.Value)
- func HashSetGrow(vm *VM, set *value.HashSet, newSlots int) value.Value
- func HashSetIndex(vm *VM, set *value.HashSet, val value.Value) (int, value.Value)
- func HashSetIntersection(vm *VM, x *value.HashSet, y *value.HashSet) (*value.HashSet, value.Value)
- func HashSetSetCapacity(vm *VM, set *value.HashSet, capacity int) value.Value
- func HashSetUnion(vm *VM, x *value.HashSet, y *value.HashSet) (*value.HashSet, value.Value)
- func Increment(vm *VM, val value.Value) (value.Value, value.Value)
- func InitGlobalEnvironment()
- func LaxEqual(vm *VM, left, right value.Value) (value.Value, value.Value)
- func LeftOpenRangeContains(vm *VM, r *value.LeftOpenRange, val value.Value) (bool, value.Value)
- func LeftOpenRangeEqual(vm *VM, x, y *value.LeftOpenRange) (bool, value.Value)
- func LeftOpenRangeIteratorNext(vm *VM, i *value.LeftOpenRangeIterator) (value.Value, value.Value)
- func LessThan(vm *VM, left, right value.Value) (value.Value, value.Value)
- func LessThanEqual(vm *VM, left, right value.Value) (value.Value, value.Value)
- func MustNewHashMapWithCapacityAndElements(vm *VM, capacity int, elements ...value.Pair) *value.HashMap
- func MustNewHashMapWithElements(vm *VM, elements ...value.Pair) *value.HashMap
- func MustNewHashRecordWithCapacityAndElements(vm *VM, capacity int, elements ...value.Pair) *value.HashRecord
- func MustNewHashRecordWithElements(vm *VM, elements ...value.Pair) *value.HashRecord
- func MustNewHashSetWithCapacityAndElements(vm *VM, capacity int, elements ...value.Value) *value.HashSet
- func MustNewHashSetWithCapacityAndElementsMaxLoad(vm *VM, capacity int, maxLoad float64, elements ...value.Value) *value.HashSet
- func MustNewHashSetWithElements(vm *VM, elements ...value.Value) *value.HashSet
- func NewHashMapComparer(opts *cmp.Options) cmp.Option
- func NewHashMapWithCapacityAndElements(vm *VM, capacity int, elements ...value.Pair) (*value.HashMap, value.Value)
- func NewHashMapWithElements(vm *VM, elements ...value.Pair) (*value.HashMap, value.Value)
- func NewHashRecordComparer(opts *cmp.Options) cmp.Option
- func NewHashRecordWithCapacityAndElements(vm *VM, capacity int, elements ...value.Pair) (*value.HashRecord, value.Value)
- func NewHashRecordWithElements(vm *VM, elements ...value.Pair) (*value.HashRecord, value.Value)
- func NewHashSetComparer(opts *cmp.Options) cmp.Option
- func NewHashSetWithCapacityAndElements(vm *VM, capacity int, elements ...value.Value) (*value.HashSet, value.Value)
- func NewHashSetWithCapacityAndElementsMaxLoad(vm *VM, capacity int, maxLoad float64, elements ...value.Value) (*value.HashSet, value.Value)
- func NewHashSetWithElements(vm *VM, elements ...value.Value) (*value.HashSet, value.Value)
- func NewNativeMethodComparer() cmp.Option
- func ObjectHash(val value.Value) value.UInt64
- func OpenRangeContains(vm *VM, r *value.OpenRange, val value.Value) (bool, value.Value)
- func OpenRangeEqual(vm *VM, x *value.OpenRange, y *value.OpenRange) (bool, value.Value)
- func OpenRangeIteratorNext(vm *VM, i *value.OpenRangeIterator) (value.Value, value.Value)
- func PairEqual(vm *VM, x *value.Pair, y *value.Pair) (bool, value.Value)
- func RightOpenRangeContains(vm *VM, r *value.RightOpenRange, val value.Value) (bool, value.Value)
- func RightOpenRangeEqual(vm *VM, x, y *value.RightOpenRange) (bool, value.Value)
- func RightOpenRangeIteratorNext(vm *VM, i *value.RightOpenRangeIterator) (value.Value, value.Value)
- func Setter(container *value.MethodContainer, attrName string)
- type BytecodeFunction
- func NewBytecodeFunction(name value.Symbol, instruct []byte, loc *position.Location, ...) *BytecodeFunction
- func NewBytecodeFunctionNoParams(name value.Symbol, instruct []byte, loc *position.Location, ...) *BytecodeFunction
- func NewBytecodeFunctionSimple(name value.Symbol, instruct []byte, loc *position.Location) *BytecodeFunction
- func NewBytecodeFunctionWithCatchEntries(name value.Symbol, instruct []byte, loc *position.Location, ...) *BytecodeFunction
- func NewBytecodeFunctionWithOptions(opts ...BytecodeFunctionOption) *BytecodeFunction
- func NewBytecodeFunctionWithUpvalues(name value.Symbol, instruct []byte, loc *position.Location, ...) *BytecodeFunction
- func (f *BytecodeFunction) AddBytes(bytes ...byte)
- func (f *BytecodeFunction) AddInstruction(lineNumber int, op bytecode.OpCode, bytes ...byte)
- func (f *BytecodeFunction) AddParameter()
- func (f *BytecodeFunction) AddValue(obj value.Value) (int, IntSize)
- func (f *BytecodeFunction) AppendUint16(n uint16)
- func (f *BytecodeFunction) AppendUint32(n uint32)
- func (*BytecodeFunction) Class() *value.Class
- func (b *BytecodeFunction) Copy() value.Reference
- func (*BytecodeFunction) DirectClass() *value.Class
- func (f *BytecodeFunction) Disassemble(output io.Writer) error
- func (f *BytecodeFunction) DisassembleInstruction(output io.Writer, offset int) (int, error)
- func (f *BytecodeFunction) DisassembleStdout()
- func (f *BytecodeFunction) DisassembleString() (string, error)
- func (b *BytecodeFunction) Error() string
- func (b *BytecodeFunction) FileName() string
- func (b *BytecodeFunction) GetLineNumber(ip int) int
- func (b *BytecodeFunction) IncrementOptionalParameterCount()
- func (b *BytecodeFunction) Inspect() string
- func (*BytecodeFunction) InstanceVariables() value.SymbolMap
- func (b *BytecodeFunction) Name() value.Symbol
- func (b *BytecodeFunction) OptionalParameterCount() int
- func (b *BytecodeFunction) ParameterCount() int
- func (f *BytecodeFunction) RemoveByte()
- func (b *BytecodeFunction) SetOptionalParameterCount(optParamCount int)
- func (b *BytecodeFunction) SetParameterCount(paramCount int)
- func (*BytecodeFunction) SingletonClass() *value.Class
- type BytecodeFunctionOption
- func BytecodeFunctionWithInstructions(instructs []byte) BytecodeFunctionOption
- func BytecodeFunctionWithLineInfoList(lineInfo bytecode.LineInfoList) BytecodeFunctionOption
- func BytecodeFunctionWithLocation(loc *position.Location) BytecodeFunctionOption
- func BytecodeFunctionWithName(name value.Symbol) BytecodeFunctionOption
- func BytecodeFunctionWithOptionalParameters(optParams int) BytecodeFunctionOption
- func BytecodeFunctionWithParameters(params int) BytecodeFunctionOption
- func BytecodeFunctionWithStringName(name string) BytecodeFunctionOption
- type CallFrame
- type CatchEntry
- type Closure
- type DefOption
- type DeletedHashSetValueType
- func (DeletedHashSetValueType) Class() *value.Class
- func (e DeletedHashSetValueType) Copy() value.Reference
- func (DeletedHashSetValueType) DirectClass() *value.Class
- func (e DeletedHashSetValueType) Error() string
- func (DeletedHashSetValueType) Inspect() string
- func (DeletedHashSetValueType) InstanceVariables() value.SymbolMap
- func (DeletedHashSetValueType) SingletonClass() *value.Class
- type GetterMethod
- func (g *GetterMethod) Call(self value.Value) (value.Value, value.Value)
- func (*GetterMethod) Class() *value.Class
- func (g *GetterMethod) Copy() value.Reference
- func (*GetterMethod) DirectClass() *value.Class
- func (g *GetterMethod) Error() string
- func (g *GetterMethod) Inspect() string
- func (*GetterMethod) InstanceVariables() value.SymbolMap
- func (g *GetterMethod) Name() value.Symbol
- func (*GetterMethod) NamedRestParameter() bool
- func (*GetterMethod) OptionalParameterCount() int
- func (*GetterMethod) ParameterCount() int
- func (*GetterMethod) Parameters() []value.Symbol
- func (*GetterMethod) PostRestParameterCount() int
- func (*GetterMethod) SingletonClass() *value.Class
- type IntSize
- type NativeFunction
- type NativeMethod
- func (*NativeMethod) Class() *value.Class
- func (n *NativeMethod) Copy() value.Reference
- func (*NativeMethod) DirectClass() *value.Class
- func (n *NativeMethod) Error() string
- func (n *NativeMethod) Inspect() string
- func (*NativeMethod) InstanceVariables() value.SymbolMap
- func (n *NativeMethod) Name() value.Symbol
- func (n *NativeMethod) OptionalParameterCount() int
- func (n *NativeMethod) ParameterCount() int
- func (*NativeMethod) SingletonClass() *value.Class
- type Option
- type SetterMethod
- func (s *SetterMethod) Call(self value.Value, val value.Value) (value.Value, value.Value)
- func (*SetterMethod) Class() *value.Class
- func (s *SetterMethod) Copy() value.Reference
- func (*SetterMethod) DirectClass() *value.Class
- func (s *SetterMethod) Error() string
- func (s *SetterMethod) Inspect() string
- func (*SetterMethod) InstanceVariables() value.SymbolMap
- func (s *SetterMethod) Name() value.Symbol
- func (*SetterMethod) NamedRestParameter() bool
- func (*SetterMethod) OptionalParameterCount() int
- func (*SetterMethod) ParameterCount() int
- func (*SetterMethod) Parameters() []value.Symbol
- func (*SetterMethod) PostRestParameterCount() int
- func (*SetterMethod) SingletonClass() *value.Class
- type Upvalue
- type VM
- func (vm *VM) BuildStackTrace() string
- func (vm *VM) CallCallable(args ...value.Value) (value.Value, value.Value)
- func (vm *VM) CallClosure(closure *Closure, args ...value.Value) (value.Value, value.Value)
- func (vm *VM) CallMethod(method value.Method, args ...value.Value) (value.Value, value.Value)
- func (vm *VM) CallMethodByName(name value.Symbol, args ...value.Value) (value.Value, value.Value)
- func (vm *VM) Err() value.Value
- func (vm *VM) ErrStackTrace() string
- func (vm *VM) InspectStack()
- func (vm *VM) InterpretREPL(fn *BytecodeFunction) (value.Value, value.Value)
- func (vm *VM) InterpretTopLevel(fn *BytecodeFunction) (value.Value, value.Value)
- func (vm *VM) PrintError()
- func (vm *VM) ResetError()
- func (vm *VM) Stack() []value.Value
- func (vm *VM) StackTop() value.Value
Constants ¶
const ( UpvalueLongIndexFlag bitfield.BitFlag8 = 1 << iota UpvalueLocalFlag )
const CallFrameSize = unsafe.Sizeof(CallFrame{})
const ClosureTerminatorFlag byte = 0xff
Variables ¶
var CALL_STACK_SIZE int
var DeletedHashSetValue value.Value = value.Ref(DeletedHashSetValueType{})
var VALUE_STACK_SIZE int
Functions ¶
func Accessor ¶
func Accessor( container *value.MethodContainer, attrName string, )
Utility method that creates a new setter and getter method and attaches them as methods to the given container. Panics when the methods cannot be defined.
func Alias ¶
func Alias(container *value.MethodContainer, newName, oldName string)
Utility method that defines an alternative name for an existing method.
func ArrayListContains ¶
func ArrayTupleContains ¶
func ArrayTupleEqual ¶
func BeginlessClosedRangeContains ¶
func BeginlessClosedRangeContains(vm *VM, r *value.BeginlessClosedRange, val value.Value) (bool, value.Value)
Checks whether a value is contained in the beginless closed range
func BeginlessClosedRangeEqual ¶
Checks whether two beginless closed ranges are equal
func BeginlessOpenRangeContains ¶
func BeginlessOpenRangeContains(vm *VM, r *value.BeginlessOpenRange, val value.Value) (bool, value.Value)
Checks whether a value is contained in the open range
func BeginlessOpenRangeEqual ¶
Checks whether two open ranges are equal
func ClosedRangeContains ¶
Checks whether a value is contained in the closed range
func ClosedRangeEqual ¶
func ClosedRangeEqual(vm *VM, x *value.ClosedRange, y *value.ClosedRange) (bool, value.Value)
Checks whether two closed ranges are equal
func ClosedRangeIteratorNext ¶
Get the next element of the range
func Def ¶
func Def( container *value.MethodContainer, name string, function NativeFunction, opts ...DefOption, )
Utility method that creates a new native method and attaches it to the given container.
Panics when the method cannot be defined.
func DefineAccessor ¶
func DefineAccessor( container *value.MethodContainer, attrName value.Symbol, )
Utility method that creates a new setter and getter method and attaches them as methods to the given method map.
func DefineGetter ¶
func DefineGetter( container *value.MethodContainer, name value.Symbol, )
Creates a getter method and attaches it to the given container.
func DefineNativeMethod ¶
func DefineNativeMethod( container *value.MethodContainer, name value.Symbol, params int, optParams int, function NativeFunction, ) (err value.Value)
Define a native method in the given container. Returns an error when the method couldn't be defined.
func DefineSetter ¶
func DefineSetter( container *value.MethodContainer, attrName value.Symbol, )
Creates a setter method and attaches it to the given container.
func EndlessClosedRangeContains ¶
func EndlessClosedRangeContains(vm *VM, r *value.EndlessClosedRange, val value.Value) (bool, value.Value)
Checks whether a value is contained in the closed range
func EndlessClosedRangeEqual ¶
func EndlessClosedRangeEqual(vm *VM, x *value.EndlessClosedRange, y *value.EndlessClosedRange) (bool, value.Value)
Checks whether two closed ranges are equal
func EndlessClosedRangeIteratorNext ¶
func EndlessClosedRangeIteratorNext(vm *VM, i *value.EndlessClosedRangeIterator) (value.Value, value.Value)
Get the next element of the range
func EndlessOpenRangeContains ¶
func EndlessOpenRangeContains(vm *VM, r *value.EndlessOpenRange, val value.Value) (bool, value.Value)
Checks whether a value is contained in the endless open range
func EndlessOpenRangeEqual ¶
Checks whether two Endless open ranges are equal
func EndlessOpenRangeIteratorNext ¶
func EndlessOpenRangeIteratorNext(vm *VM, i *value.EndlessOpenRangeIterator) (value.Value, value.Value)
Get the next element of the range
func Getter ¶
func Getter( container *value.MethodContainer, name string, )
Utility method that creates a new getter method and attaches it as a method to the given container. It panics when the method cannot be defined.
func GreaterThan ¶
Check whether the left value is greater than the right
func GreaterThanEqual ¶
Check whether the left value is greater than or equal to the right
func HashMapConcat ¶
Create a new map containing the pairs of both maps.
func HashMapContains ¶
Check if the given pair is present in the map
func HashMapContainsKey ¶
Check if the given key is present in the map
func HashMapContainsValue ¶
Check if the given value is present in the map
func HashMapCopy ¶
Copy the pairs of one hashmap to the other.
func HashMapCopyTable ¶
func HashMapDelete ¶
Delete the given key from the hashMap
func HashMapEqual ¶
Checks whether two hash maps are equal
func HashMapGet ¶
Get the element under the given key. Returns (value, undefined) when the value has been found. Returns (undefined, undefined) when the key is not present. Returns (undefined, err) when there was an error.
func HashMapGrow ¶
Add additional n empty slots for new elements.
func HashMapIndex ¶
Get the index that the key should be inserted into. Returns (nil, err) when an error has been encountered. Returns (-1, nil) when there's no room for new values.
func HashMapLaxEqual ¶
Checks whether two hash maps are equal (lax)
func HashMapSet ¶
Set a value under the given key.
func HashMapSetCapacity ¶
Resize the given hashmap to the desired capacity.
func HashMapSetWithMaxLoad ¶
func HashRecordConcat ¶
func HashRecordConcat(vm *VM, x *value.HashRecord, y *value.HashRecord) (*value.HashMap, value.Value)
Create a new map containing the pairs of both maps.
func HashRecordContains ¶
Check if the given pair is present in the record
func HashRecordContainsKey ¶
Check if the given key is present in the record
func HashRecordContainsValue ¶
Check if the given value is present in the record
func HashRecordCopy ¶
func HashRecordCopy(vm *VM, target *value.HashRecord, source *value.HashRecord) value.Value
Copy the pairs of one hash record to the other.
func HashRecordCopyTable ¶
func HashRecordDelete ¶
Delete the given key from the hashMap
func HashRecordEqual ¶
func HashRecordEqual(vm *VM, x *value.HashRecord, y *value.HashRecord) (bool, value.Value)
Checks whether two hash records are equal
func HashRecordGet ¶
func HashRecordGet(vm *VM, hashRecord *value.HashRecord, key value.Value) (value.Value, value.Value)
Get the element under the given key.
func HashRecordGrow ¶
Add additional n empty slots for new elements.
func HashRecordLaxEqual ¶
func HashRecordLaxEqual(vm *VM, x *value.HashRecord, y *value.HashRecord) (bool, value.Value)
Checks whether two hash records are equal (lax)
func HashRecordSet ¶
Set a value under the given key.
func HashRecordSetCapacity ¶
Resize the given hash record to the desired capacity.
func HashSetAppend ¶
Set a value under the given key.
func HashSetContains ¶
Check whether the given value is contained within the set.
func HashSetCopy ¶
Copy the pairs of one hashmap to the other.
func HashSetCopyTable ¶
func HashSetDelete ¶
Delete the given value from the hash set
func HashSetEqual ¶
Checks whether two hash sets are equal
func HashSetGrow ¶
Add additional n empty slots for new elements.
func HashSetIndex ¶
Get the index that the value should be inserted into. Returns (0, err) when an error has been encountered. Returns (-1, undefined) when there's no room for new values.
func HashSetIntersection ¶
Create a new set that is the intersection of the given two sets
func HashSetSetCapacity ¶
Resize the given set to the desired capacity.
func HashSetUnion ¶
Create a new set that is the union of the given two sets
func InitGlobalEnvironment ¶
func InitGlobalEnvironment()
func LeftOpenRangeContains ¶
Checks whether a value is contained in the left open range
func LeftOpenRangeEqual ¶
Checks whether two left open ranges are equal
func LeftOpenRangeIteratorNext ¶
Get the next element of the range
func LessThanEqual ¶
Check whether the left value is less than or equal to the right
func MustNewHashMapWithElements ¶
Create a new hashmap with the given entries.
func MustNewHashRecordWithElements ¶
func MustNewHashRecordWithElements(vm *VM, elements ...value.Pair) *value.HashRecord
Create a new hash record with the given entries.
func MustNewHashSetWithElements ¶
Create a new hash set with the given entries.
func NewHashMapWithElements ¶
Create a new hashmap with the given entries.
func NewHashRecordWithElements ¶
Create a new hash record with the given entries.
func NewHashSetWithElements ¶
Create a new hash set with the given entries.
func NewNativeMethodComparer ¶
func OpenRangeContains ¶
Checks whether a value is contained in the open range
func OpenRangeEqual ¶
Checks whether two open ranges are equal
func OpenRangeIteratorNext ¶
Get the next element of the range
func RightOpenRangeContains ¶
Checks whether a value is contained in the range
func RightOpenRangeEqual ¶
Checks whether two right open ranges are equal
func RightOpenRangeIteratorNext ¶
Get the next element of the range
func Setter ¶
func Setter( container *value.MethodContainer, attrName string, )
Utility method that creates a new setter method and attaches it as a method to the given container. Panics when the method cannot be defined.
Types ¶
type BytecodeFunction ¶
type BytecodeFunction struct { Instructions []byte Values []value.Value // The value pool LineInfoList bytecode.LineInfoList Location *position.Location Doc value.Value CatchEntries []*CatchEntry UpvalueCount int // contains filtered or unexported fields }
A single unit of Elk bytecode.
func NewBytecodeFunction ¶
func NewBytecodeFunction( name value.Symbol, instruct []byte, loc *position.Location, lineInfo bytecode.LineInfoList, paramCount int, optParamCount int, values []value.Value, ) *BytecodeFunction
Create a new bytecode method.
func NewBytecodeFunctionNoParams ¶
func NewBytecodeFunctionNoParams( name value.Symbol, instruct []byte, loc *position.Location, lineInfo bytecode.LineInfoList, values []value.Value, ) *BytecodeFunction
Create a new bytecode method.
func NewBytecodeFunctionSimple ¶
func NewBytecodeFunctionSimple(name value.Symbol, instruct []byte, loc *position.Location) *BytecodeFunction
Create a new bytecode method.
func NewBytecodeFunctionWithCatchEntries ¶
func NewBytecodeFunctionWithCatchEntries( name value.Symbol, instruct []byte, loc *position.Location, lineInfo bytecode.LineInfoList, params int, optParamCount int, values []value.Value, catchEntries []*CatchEntry, ) *BytecodeFunction
Create a new bytecode method.
func NewBytecodeFunctionWithOptions ¶
func NewBytecodeFunctionWithOptions(opts ...BytecodeFunctionOption) *BytecodeFunction
Create a new bytecode method with options.
func NewBytecodeFunctionWithUpvalues ¶
func NewBytecodeFunctionWithUpvalues( name value.Symbol, instruct []byte, loc *position.Location, lineInfo bytecode.LineInfoList, params int, optParamCount int, values []value.Value, upvalueCount int, ) *BytecodeFunction
Create a new bytecode method.
func (*BytecodeFunction) AddBytes ¶
func (f *BytecodeFunction) AddBytes(bytes ...byte)
Add bytes to the bytecode chunk.
func (*BytecodeFunction) AddInstruction ¶
func (f *BytecodeFunction) AddInstruction(lineNumber int, op bytecode.OpCode, bytes ...byte)
Add an instruction to the bytecode chunk.
func (*BytecodeFunction) AddParameter ¶
func (f *BytecodeFunction) AddParameter()
Add a parameter to the method.
func (*BytecodeFunction) AddValue ¶
func (f *BytecodeFunction) AddValue(obj value.Value) (int, IntSize)
Add a value to the value pool. Returns the index of the constant.
func (*BytecodeFunction) AppendUint16 ¶
func (f *BytecodeFunction) AppendUint16(n uint16)
Append two bytes to the bytecode chunk.
func (*BytecodeFunction) AppendUint32 ¶
func (f *BytecodeFunction) AppendUint32(n uint32)
Append four bytes to the bytecode chunk.
func (*BytecodeFunction) Class ¶
func (*BytecodeFunction) Class() *value.Class
func (*BytecodeFunction) Copy ¶
func (b *BytecodeFunction) Copy() value.Reference
func (*BytecodeFunction) DirectClass ¶
func (*BytecodeFunction) DirectClass() *value.Class
func (*BytecodeFunction) Disassemble ¶
func (f *BytecodeFunction) Disassemble(output io.Writer) error
Disassemble the bytecode chunk and write the output to a writer.
func (*BytecodeFunction) DisassembleInstruction ¶
func (*BytecodeFunction) DisassembleStdout ¶
func (f *BytecodeFunction) DisassembleStdout()
Disassemble the bytecode chunk and write the output to stdout.
func (*BytecodeFunction) DisassembleString ¶
func (f *BytecodeFunction) DisassembleString() (string, error)
Disassemble the bytecode chunk and return a string containing the result.
func (*BytecodeFunction) Error ¶
func (b *BytecodeFunction) Error() string
func (*BytecodeFunction) FileName ¶
func (b *BytecodeFunction) FileName() string
func (*BytecodeFunction) GetLineNumber ¶
func (b *BytecodeFunction) GetLineNumber(ip int) int
func (*BytecodeFunction) IncrementOptionalParameterCount ¶
func (b *BytecodeFunction) IncrementOptionalParameterCount()
func (*BytecodeFunction) Inspect ¶
func (b *BytecodeFunction) Inspect() string
func (*BytecodeFunction) InstanceVariables ¶
func (*BytecodeFunction) InstanceVariables() value.SymbolMap
func (*BytecodeFunction) Name ¶
func (b *BytecodeFunction) Name() value.Symbol
func (*BytecodeFunction) OptionalParameterCount ¶
func (b *BytecodeFunction) OptionalParameterCount() int
func (*BytecodeFunction) ParameterCount ¶
func (b *BytecodeFunction) ParameterCount() int
func (*BytecodeFunction) RemoveByte ¶
func (f *BytecodeFunction) RemoveByte()
Add an instruction to the bytecode chunk.
func (*BytecodeFunction) SetOptionalParameterCount ¶
func (b *BytecodeFunction) SetOptionalParameterCount(optParamCount int)
func (*BytecodeFunction) SetParameterCount ¶
func (b *BytecodeFunction) SetParameterCount(paramCount int)
func (*BytecodeFunction) SingletonClass ¶
func (*BytecodeFunction) SingletonClass() *value.Class
type BytecodeFunctionOption ¶
type BytecodeFunctionOption func(*BytecodeFunction)
func BytecodeFunctionWithInstructions ¶
func BytecodeFunctionWithInstructions(instructs []byte) BytecodeFunctionOption
func BytecodeFunctionWithLineInfoList ¶
func BytecodeFunctionWithLineInfoList(lineInfo bytecode.LineInfoList) BytecodeFunctionOption
func BytecodeFunctionWithLocation ¶
func BytecodeFunctionWithLocation(loc *position.Location) BytecodeFunctionOption
func BytecodeFunctionWithName ¶
func BytecodeFunctionWithName(name value.Symbol) BytecodeFunctionOption
func BytecodeFunctionWithOptionalParameters ¶
func BytecodeFunctionWithOptionalParameters(optParams int) BytecodeFunctionOption
func BytecodeFunctionWithParameters ¶
func BytecodeFunctionWithParameters(params int) BytecodeFunctionOption
func BytecodeFunctionWithStringName ¶
func BytecodeFunctionWithStringName(name string) BytecodeFunctionOption
type CallFrame ¶
type CallFrame struct {
// contains filtered or unexported fields
}
Contains the data of a single function call.
func (CallFrame) LineNumber ¶
type CatchEntry ¶
type CatchEntry struct { From int // index of the first instruction that can be handled by this catch To int // index of the last instruction that can be handled by this catch JumpAddress int // index of the byte that the VM should jump to Finally bool // whether this entry is for a finally clause }
func NewCatchEntry ¶
func NewCatchEntry(from, to, jumpAddress int, finally bool) *CatchEntry
func (*CatchEntry) ByteRange ¶
func (c *CatchEntry) ByteRange() int
Number of bytes this catch covers
type Closure ¶
type Closure struct { Bytecode *BytecodeFunction Self value.Value Upvalues []*Upvalue }
Wraps a bytecode function with associated local variables from the outer context
func NewClosure ¶
func NewClosure(bytecode *BytecodeFunction, self value.Value) *Closure
Create a new closure
func (*Closure) DirectClass ¶
func (*Closure) InstanceVariables ¶
func (*Closure) SingletonClass ¶
type DefOption ¶
type DefOption func(*NativeMethod)
func DefWithOptionalParameters ¶
Define how many parameters are optional (have default values). Optional arguments will be populated with `undefined` when no value was given in the call.
func DefWithParameters ¶
Define parameters used by the method
type DeletedHashSetValueType ¶
type DeletedHashSetValueType struct{}
func (DeletedHashSetValueType) Class ¶
func (DeletedHashSetValueType) Class() *value.Class
func (DeletedHashSetValueType) Copy ¶
func (e DeletedHashSetValueType) Copy() value.Reference
func (DeletedHashSetValueType) DirectClass ¶
func (DeletedHashSetValueType) DirectClass() *value.Class
func (DeletedHashSetValueType) Error ¶
func (e DeletedHashSetValueType) Error() string
func (DeletedHashSetValueType) Inspect ¶
func (DeletedHashSetValueType) Inspect() string
func (DeletedHashSetValueType) InstanceVariables ¶
func (DeletedHashSetValueType) InstanceVariables() value.SymbolMap
func (DeletedHashSetValueType) SingletonClass ¶
func (DeletedHashSetValueType) SingletonClass() *value.Class
type GetterMethod ¶
A simple getter method.
func NewGetterMethod ¶
func NewGetterMethod(attrName value.Symbol) *GetterMethod
Create a new getter method.
func (*GetterMethod) Class ¶
func (*GetterMethod) Class() *value.Class
func (*GetterMethod) Copy ¶
func (g *GetterMethod) Copy() value.Reference
func (*GetterMethod) DirectClass ¶
func (*GetterMethod) DirectClass() *value.Class
func (*GetterMethod) Error ¶
func (g *GetterMethod) Error() string
func (*GetterMethod) Inspect ¶
func (g *GetterMethod) Inspect() string
func (*GetterMethod) InstanceVariables ¶
func (*GetterMethod) InstanceVariables() value.SymbolMap
func (*GetterMethod) Name ¶
func (g *GetterMethod) Name() value.Symbol
func (*GetterMethod) NamedRestParameter ¶
func (*GetterMethod) NamedRestParameter() bool
func (*GetterMethod) OptionalParameterCount ¶
func (*GetterMethod) OptionalParameterCount() int
func (*GetterMethod) ParameterCount ¶
func (*GetterMethod) ParameterCount() int
func (*GetterMethod) Parameters ¶
func (*GetterMethod) Parameters() []value.Symbol
func (*GetterMethod) PostRestParameterCount ¶
func (*GetterMethod) PostRestParameterCount() int
func (*GetterMethod) SingletonClass ¶
func (*GetterMethod) SingletonClass() *value.Class
type NativeFunction ¶
An implementation of a native Elk method.
type NativeMethod ¶
type NativeMethod struct { Function NativeFunction Doc value.Value // contains filtered or unexported fields }
A native Elk method
func NewNativeMethod ¶
func NewNativeMethod( name value.Symbol, params int, optParams int, function NativeFunction, ) *NativeMethod
Create a new native method.
func (*NativeMethod) Class ¶
func (*NativeMethod) Class() *value.Class
func (*NativeMethod) Copy ¶
func (n *NativeMethod) Copy() value.Reference
func (*NativeMethod) DirectClass ¶
func (*NativeMethod) DirectClass() *value.Class
func (*NativeMethod) Error ¶
func (n *NativeMethod) Error() string
func (*NativeMethod) Inspect ¶
func (n *NativeMethod) Inspect() string
func (*NativeMethod) InstanceVariables ¶
func (*NativeMethod) InstanceVariables() value.SymbolMap
func (*NativeMethod) Name ¶
func (n *NativeMethod) Name() value.Symbol
func (*NativeMethod) OptionalParameterCount ¶
func (n *NativeMethod) OptionalParameterCount() int
func (*NativeMethod) ParameterCount ¶
func (n *NativeMethod) ParameterCount() int
func (*NativeMethod) SingletonClass ¶
func (*NativeMethod) SingletonClass() *value.Class
type Option ¶
type Option func(*VM) // constructor option function
func WithStderr ¶
Assign the given io.Writer as the Stderr of the VM.
func WithStdout ¶
Assign the given io.Writer as the Stdout of the VM.
type SetterMethod ¶
type SetterMethod struct { Doc value.Value AttributeName value.Symbol // contains filtered or unexported fields }
A simple setter method.
func NewSetterMethod ¶
func NewSetterMethod(attrName value.Symbol) *SetterMethod
Create a new getter method.
func (*SetterMethod) Class ¶
func (*SetterMethod) Class() *value.Class
func (*SetterMethod) Copy ¶
func (s *SetterMethod) Copy() value.Reference
func (*SetterMethod) DirectClass ¶
func (*SetterMethod) DirectClass() *value.Class
func (*SetterMethod) Error ¶
func (s *SetterMethod) Error() string
func (*SetterMethod) Inspect ¶
func (s *SetterMethod) Inspect() string
func (*SetterMethod) InstanceVariables ¶
func (*SetterMethod) InstanceVariables() value.SymbolMap
func (*SetterMethod) Name ¶
func (s *SetterMethod) Name() value.Symbol
func (*SetterMethod) NamedRestParameter ¶
func (*SetterMethod) NamedRestParameter() bool
func (*SetterMethod) OptionalParameterCount ¶
func (*SetterMethod) OptionalParameterCount() int
func (*SetterMethod) ParameterCount ¶
func (*SetterMethod) ParameterCount() int
func (*SetterMethod) Parameters ¶
func (*SetterMethod) Parameters() []value.Symbol
func (*SetterMethod) PostRestParameterCount ¶
func (*SetterMethod) PostRestParameterCount() int
func (*SetterMethod) SingletonClass ¶
func (*SetterMethod) SingletonClass() *value.Class
type Upvalue ¶
type Upvalue struct {
// contains filtered or unexported fields
}
Represents a captured variable from an outer context
func NewUpvalue ¶
func (*Upvalue) DirectClass ¶
func (*Upvalue) InstanceVariables ¶
func (*Upvalue) SingletonClass ¶
type VM ¶
type VM struct { Stdin io.Reader // standard output used by the VM Stdout io.Writer // standard input used by the VM Stderr io.Writer // standard error used by the VM // contains filtered or unexported fields }
A single instance of the Elk Virtual Machine.
func (*VM) BuildStackTrace ¶
func (*VM) CallCallable ¶
Call a callable value from Go code, preserving the state of the VM.
func (*VM) CallClosure ¶
Call an Elk closure from Go code, preserving the state of the VM.
func (*VM) CallMethod ¶
func (*VM) CallMethodByName ¶
Call an Elk method from Go code, preserving the state of the VM.
func (*VM) InspectStack ¶
func (vm *VM) InspectStack()
func (*VM) InterpretREPL ¶
Execute the given bytecode chunk.
func (*VM) InterpretTopLevel ¶
Execute the given bytecode chunk.
func (*VM) PrintError ¶
func (vm *VM) PrintError()
func (*VM) ResetError ¶
func (vm *VM) ResetError()
Source Files ¶
- alias.go
- array_list.go
- array_tuple.go
- beginless_closed_range.go
- beginless_open_range.go
- big_float.go
- bytecode_function.go
- call_frame.go
- catch_entry.go
- char.go
- class.go
- closed_range.go
- closure.go
- comparable.go
- debug.go
- duration.go
- endless_closed_range.go
- endless_open_range.go
- float.go
- getter_method.go
- hash_map.go
- hash_record.go
- hash_set.go
- init.go
- int.go
- interface.go
- kernel.go
- left_open_range.go
- method.go
- mixin.go
- module.go
- native_method.go
- open_range.go
- pair.go
- regex.go
- right_open_range.go
- setter_method.go
- string.go
- symbol.go
- time.go
- timezone.go
- upvalue.go
- value.go
- vm.go