Documentation ¶
Overview ¶
Package vm contains the Elk Virtual Machine. It interprets Elk Bytecode produced by the Elk compiler.
Index ¶
- Variables
- func Accessor(container *value.MethodContainer, attrName string, sealed bool)
- 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, sealed bool) *value.Error
- func DefineGetter(container *value.MethodContainer, name value.Symbol, sealed bool) *value.Error
- func DefineNativeMethod(container *value.MethodContainer, name value.Symbol, params []value.Symbol, ...) *value.Error
- func DefineSetter(container *value.MethodContainer, attrName value.Symbol, sealed bool) *value.Error
- 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, opts ...GetterOption)
- 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 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 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 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 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, opts ...SetterOption)
- 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 (f *BytecodeFunction) AddBytes(bytes ...byte)
- func (f *BytecodeFunction) AddInstruction(lineNumber int, op bytecode.OpCode, bytes ...byte)
- func (f *BytecodeFunction) AddParameter(name value.Symbol)
- func (f *BytecodeFunction) AddParameterString(name string)
- 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.Value
- func (*BytecodeFunction) DirectClass() *value.Class
- func (f *BytecodeFunction) Disassemble(output io.Writer) error
- func (f *BytecodeFunction) DisassembleInstruction(output io.Writer, offset, instructionIndex int) (int, error)
- func (f *BytecodeFunction) DisassembleStdout()
- func (f *BytecodeFunction) DisassembleString() (string, error)
- func (b *BytecodeFunction) FileName() string
- func (b *BytecodeFunction) GetLineNumber(ip int) int
- func (b *BytecodeFunction) IncrementOptionalParameterCount()
- func (b *BytecodeFunction) IncrementPostRestParameterCount()
- func (b *BytecodeFunction) Inspect() string
- func (*BytecodeFunction) InstanceVariables() value.SymbolMap
- func (b *BytecodeFunction) IsSealed() bool
- func (b *BytecodeFunction) Name() value.Symbol
- func (b *BytecodeFunction) NamedRestParameter() bool
- func (b *BytecodeFunction) OptionalParameterCount() int
- func (b *BytecodeFunction) ParameterCount() int
- func (b *BytecodeFunction) Parameters() []value.Symbol
- func (b *BytecodeFunction) PostRestParameterCount() int
- func (b *BytecodeFunction) SetNamedRestParameter(present bool)
- func (b *BytecodeFunction) SetOptionalParameterCount(optParamCount int)
- func (b *BytecodeFunction) SetParameters(params []value.Symbol)
- func (b *BytecodeFunction) SetPostRestParameterCount(postParamCount int)
- func (b *BytecodeFunction) SetSealed()
- 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 BytecodeFunctionWithNamedRestParameter() BytecodeFunctionOption
- func BytecodeFunctionWithOptionalParameters(optParams int) BytecodeFunctionOption
- func BytecodeFunctionWithParameters(params []value.Symbol) BytecodeFunctionOption
- func BytecodeFunctionWithPositionalRestParameter() BytecodeFunctionOption
- func BytecodeFunctionWithPostParameters(postParams int) BytecodeFunctionOption
- func BytecodeFunctionWithSealed() BytecodeFunctionOption
- func BytecodeFunctionWithStringName(name string) BytecodeFunctionOption
- type CallFrame
- type CatchEntry
- type Closure
- type DefOption
- type GetterMethod
- func (g *GetterMethod) Call(self value.Value) (value.Value, value.Value)
- func (*GetterMethod) Class() *value.Class
- func (g *GetterMethod) Copy() value.Value
- func (*GetterMethod) DirectClass() *value.Class
- func (g *GetterMethod) Inspect() string
- func (*GetterMethod) InstanceVariables() value.SymbolMap
- func (g *GetterMethod) IsSealed() bool
- 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 (g *GetterMethod) SetSealed()
- func (*GetterMethod) SingletonClass() *value.Class
- type GetterOption
- type IntSize
- type NativeFunction
- type NativeMethod
- func (*NativeMethod) Class() *value.Class
- func (n *NativeMethod) Copy() value.Value
- func (*NativeMethod) DirectClass() *value.Class
- func (n *NativeMethod) Inspect() string
- func (*NativeMethod) InstanceVariables() value.SymbolMap
- func (n *NativeMethod) IsSealed() bool
- func (n *NativeMethod) Name() value.Symbol
- func (n *NativeMethod) NamedRestParameter() bool
- func (n *NativeMethod) OptionalParameterCount() int
- func (n *NativeMethod) ParameterCount() int
- func (n *NativeMethod) Parameters() []value.Symbol
- func (n *NativeMethod) PostRestParameterCount() int
- func (n *NativeMethod) SetSealed()
- 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.Value
- func (*SetterMethod) DirectClass() *value.Class
- func (s *SetterMethod) Inspect() string
- func (*SetterMethod) InstanceVariables() value.SymbolMap
- func (s *SetterMethod) IsSealed() bool
- 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 (s *SetterMethod) SetSealed()
- func (*SetterMethod) SingletonClass() *value.Class
- type SetterOption
- 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(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 ¶
This section is empty.
Variables ¶
var CALL_STACK_SIZE int
var VALUE_STACK_SIZE int
BENCHMARK: compare with a dynamically allocated array
Functions ¶
func Accessor ¶
func Accessor( container *value.MethodContainer, attrName string, sealed bool, )
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. Panics when the method cannot be defined.
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, sealed bool, ) *value.Error
Utility method that creates a new setter and getter method and attaches them as methods to the given method map.
func DefineGetter ¶
Creates a getter method and attaches it to the given container.
func DefineNativeMethod ¶
func DefineNativeMethod( container *value.MethodContainer, name value.Symbol, params []value.Symbol, optParams int, postParams int, namedRestParam bool, sealed bool, function NativeFunction, ) *value.Error
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, sealed bool, ) *value.Error
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, opts ...GetterOption, )
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 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, nil) when the value has been found. Returns (nil, nil) when the key is not present. Returns (nil, 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 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 (nil, err) when an error has been encountered. Returns (-1, nil) 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 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, opts ...SetterOption, )
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 // 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, params []value.Symbol, optParamCount int, postRestParamCount int, namedRestParam bool, sealed bool, 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 []value.Symbol, optParamCount int, postRestParamCount int, namedRestParam bool, sealed bool, 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 (*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(name value.Symbol)
Add a parameter to the method.
func (*BytecodeFunction) AddParameterString ¶
func (f *BytecodeFunction) AddParameterString(name string)
Add a parameter to the method.
func (*BytecodeFunction) AddValue ¶
func (f *BytecodeFunction) AddValue(obj value.Value) (int, IntSize)
Add a constant to the constant 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.Value
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) 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) IncrementPostRestParameterCount ¶
func (b *BytecodeFunction) IncrementPostRestParameterCount()
func (*BytecodeFunction) Inspect ¶
func (b *BytecodeFunction) Inspect() string
func (*BytecodeFunction) InstanceVariables ¶
func (*BytecodeFunction) InstanceVariables() value.SymbolMap
func (*BytecodeFunction) IsSealed ¶
func (b *BytecodeFunction) IsSealed() bool
func (*BytecodeFunction) Name ¶
func (b *BytecodeFunction) Name() value.Symbol
func (*BytecodeFunction) NamedRestParameter ¶
func (b *BytecodeFunction) NamedRestParameter() bool
func (*BytecodeFunction) OptionalParameterCount ¶
func (b *BytecodeFunction) OptionalParameterCount() int
func (*BytecodeFunction) ParameterCount ¶
func (b *BytecodeFunction) ParameterCount() int
func (*BytecodeFunction) Parameters ¶
func (b *BytecodeFunction) Parameters() []value.Symbol
func (*BytecodeFunction) PostRestParameterCount ¶
func (b *BytecodeFunction) PostRestParameterCount() int
func (*BytecodeFunction) SetNamedRestParameter ¶
func (b *BytecodeFunction) SetNamedRestParameter(present bool)
func (*BytecodeFunction) SetOptionalParameterCount ¶
func (b *BytecodeFunction) SetOptionalParameterCount(optParamCount int)
func (*BytecodeFunction) SetParameters ¶
func (b *BytecodeFunction) SetParameters(params []value.Symbol)
func (*BytecodeFunction) SetPostRestParameterCount ¶
func (b *BytecodeFunction) SetPostRestParameterCount(postParamCount int)
func (*BytecodeFunction) SetSealed ¶
func (b *BytecodeFunction) SetSealed()
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 BytecodeFunctionWithNamedRestParameter ¶
func BytecodeFunctionWithNamedRestParameter() BytecodeFunctionOption
func BytecodeFunctionWithOptionalParameters ¶
func BytecodeFunctionWithOptionalParameters(optParams int) BytecodeFunctionOption
func BytecodeFunctionWithParameters ¶
func BytecodeFunctionWithParameters(params []value.Symbol) BytecodeFunctionOption
func BytecodeFunctionWithPositionalRestParameter ¶
func BytecodeFunctionWithPositionalRestParameter() BytecodeFunctionOption
func BytecodeFunctionWithPostParameters ¶
func BytecodeFunctionWithPostParameters(postParams int) BytecodeFunctionOption
func BytecodeFunctionWithSealed ¶
func BytecodeFunctionWithSealed() 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 }
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 DefWithNamedRestParameter ¶
func DefWithNamedRestParameter() DefOption
Set the last parameter as a named rest parameter eg. `**rest`
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
func DefWithPositionalRestParameter ¶
func DefWithPositionalRestParameter() DefOption
Set the last parameter as a positional rest parameter eg. `*rest`
func DefWithPostParameters ¶
Define the number of parameters that appear after the positional rest parameter eg. 2 for `a, *b, c, d`
type GetterMethod ¶
type GetterMethod struct { AttributeName value.Symbol Doc value.Value // contains filtered or unexported fields }
A simple getter method.
func NewGetterMethod ¶
func NewGetterMethod(attrName value.Symbol, sealed bool) *GetterMethod
Create a new getter method.
func (*GetterMethod) Class ¶
func (*GetterMethod) Class() *value.Class
func (*GetterMethod) Copy ¶
func (g *GetterMethod) Copy() value.Value
func (*GetterMethod) DirectClass ¶
func (*GetterMethod) DirectClass() *value.Class
func (*GetterMethod) Inspect ¶
func (g *GetterMethod) Inspect() string
func (*GetterMethod) InstanceVariables ¶
func (*GetterMethod) InstanceVariables() value.SymbolMap
func (*GetterMethod) IsSealed ¶
func (g *GetterMethod) IsSealed() bool
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) SetSealed ¶
func (g *GetterMethod) SetSealed()
func (*GetterMethod) SingletonClass ¶
func (*GetterMethod) SingletonClass() *value.Class
type GetterOption ¶
type GetterOption func(*GetterMethod)
func GetterWithSealed ¶
func GetterWithSealed(sealed bool) GetterOption
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 []value.Symbol, optParams int, postParams int, namedRestParam bool, sealed bool, function NativeFunction, ) *NativeMethod
Create a new native method.
func (*NativeMethod) Class ¶
func (*NativeMethod) Class() *value.Class
func (*NativeMethod) Copy ¶
func (n *NativeMethod) Copy() value.Value
func (*NativeMethod) DirectClass ¶
func (*NativeMethod) DirectClass() *value.Class
func (*NativeMethod) Inspect ¶
func (n *NativeMethod) Inspect() string
func (*NativeMethod) InstanceVariables ¶
func (*NativeMethod) InstanceVariables() value.SymbolMap
func (*NativeMethod) IsSealed ¶
func (n *NativeMethod) IsSealed() bool
func (*NativeMethod) Name ¶
func (n *NativeMethod) Name() value.Symbol
func (*NativeMethod) NamedRestParameter ¶
func (n *NativeMethod) NamedRestParameter() bool
func (*NativeMethod) OptionalParameterCount ¶
func (n *NativeMethod) OptionalParameterCount() int
func (*NativeMethod) ParameterCount ¶
func (n *NativeMethod) ParameterCount() int
func (*NativeMethod) Parameters ¶
func (n *NativeMethod) Parameters() []value.Symbol
func (*NativeMethod) PostRestParameterCount ¶
func (n *NativeMethod) PostRestParameterCount() int
func (*NativeMethod) SetSealed ¶
func (n *NativeMethod) SetSealed()
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, sealed bool) *SetterMethod
Create a new getter method.
func (*SetterMethod) Class ¶
func (*SetterMethod) Class() *value.Class
func (*SetterMethod) Copy ¶
func (s *SetterMethod) Copy() value.Value
func (*SetterMethod) DirectClass ¶
func (*SetterMethod) DirectClass() *value.Class
func (*SetterMethod) Inspect ¶
func (s *SetterMethod) Inspect() string
func (*SetterMethod) InstanceVariables ¶
func (*SetterMethod) InstanceVariables() value.SymbolMap
func (*SetterMethod) IsSealed ¶
func (s *SetterMethod) IsSealed() bool
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) SetSealed ¶
func (s *SetterMethod) SetSealed()
func (*SetterMethod) SingletonClass ¶
func (*SetterMethod) SingletonClass() *value.Class
type SetterOption ¶
type SetterOption func(*SetterMethod)
func SetterWithSealed ¶
func SetterWithSealed(sealed bool) SetterOption
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 ¶
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
- bytecode_function.go
- call_frame.go
- catch_entry.go
- char.go
- class.go
- closed_range.go
- closure.go
- comparable.go
- endless_closed_range.go
- endless_open_range.go
- float.go
- function.go
- getter_method.go
- hash_map.go
- hash_record.go
- hash_set.go
- int.go
- left_open_range.go
- method.go
- mixin.go
- module.go
- native_method.go
- object.go
- open_range.go
- pair.go
- regex.go
- right_open_range.go
- setter_method.go
- string.go
- symbol.go
- time.go
- value.go
- vm.go