vm

package
v0.0.0-...-8c2d49f Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TRUE is shared boolean object that represents true
	TRUE = BooleanObject(true)
	// FALSE is shared boolean object that represents false
	FALSE = BooleanObject(false)
)
View Source
const FileExt = "lito"

FileExt stores the default extension

View Source
const Version = "0.2.1"

Version stores current Lito version

Variables

View Source
var DefaultLibPath string

DefaultLibPath is used for overriding vm.libpath build-time.

View Source
var MachineConfigs = map[string]ConfigFunc{
	"standard": standard,
	"sandbox":  sandbox,
}

MachineConfigs a list of different machine configurations

Functions

func RegisterExternalClass

func RegisterExternalClass(path string, c ...ClassLoader)

RegisterExternalClass will add the given class to the global registery of available classes

Types

type ArrayObject

type ArrayObject struct {
	BaseObj
	Elements []Object
	// contains filtered or unexported fields
}

ArrayObject represents an instance of Array class.

func InitArrayObject

func InitArrayObject(elements []Object) *ArrayObject

InitArrayObject returns a new object with the given elemnts

func StringObjectSplit

func StringObjectSplit(vm *VM, s string, sep string) *ArrayObject

StringObjectSplit returns an ArrayObject with the split strings

func (*ArrayObject) EqualTo

func (a *ArrayObject) EqualTo(compared Object) bool

EqualTo returns if the ArrayObject is equal to another object

func (*ArrayObject) Inspect

func (a *ArrayObject) Inspect(t *Thread) string

Inspect returns the inspection of the Array

func (*ArrayObject) Len

func (a *ArrayObject) Len() int

Len returns the length of array's elements

func (*ArrayObject) Less

func (a *ArrayObject) Less(i, j int) bool

Less is one of the required method to fulfill sortable interface

func (*ArrayObject) Swap

func (a *ArrayObject) Swap(i, j int)

Swap is one of the required method to fulfill sortable interface

func (*ArrayObject) ToJSON

func (a *ArrayObject) ToJSON(t *Thread) string

ToJSON returns the object's elements as the JSON string format

func (*ArrayObject) ToString

func (a *ArrayObject) ToString(t *Thread) string

ToString returns the object's elements as the string format

func (*ArrayObject) Value

func (a *ArrayObject) Value() interface{}

Value returns the elements from the object

type BaseObj

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

BaseObj ...

func BaseObject

func BaseObject(c *RClass) BaseObj

BaseObject returns a base obj with the given class

func (*BaseObj) Class

func (b *BaseObj) Class() *RClass

Class will return object's class

func (*BaseObj) EqualTo

func (b *BaseObj) EqualTo(with Object) bool

EqualTo returns true if the two objects are equivalent

func (*BaseObj) FindLookup

func (b *BaseObj) FindLookup(searchAncestor bool) (method Object)

FindLookup ...

func (*BaseObj) FindMethod

func (b *BaseObj) FindMethod(methodName string, super bool) (method Object)

FindMethod returns the method with the corresponding name

func (*BaseObj) GetVariable

func (b *BaseObj) GetVariable(name string) (Object, bool)

GetVariable gets an instance variable from the object

func (*BaseObj) Inspect

func (b *BaseObj) Inspect(t *Thread) string

Inspect ...

func (*BaseObj) IsTruthy

func (b *BaseObj) IsTruthy() bool

IsTruthy returns the boolean representation of the object

func (*BaseObj) SetVariable

func (b *BaseObj) SetVariable(name string, value Object) Object

SetVariable sets an instance variable on the object

func (*BaseObj) SetVariables

func (b *BaseObj) SetVariables(e Environment)

SetVariables sets the variables in the supplied environment

func (*BaseObj) ToJSON

func (b *BaseObj) ToJSON(t *Thread) string

ToJSON ...

func (*BaseObj) ToString

func (b *BaseObj) ToString(t *Thread) string

ToString ...

func (*BaseObj) Value

func (b *BaseObj) Value() interface{}

Value ...

func (*BaseObj) Variables

func (b *BaseObj) Variables() Environment

Variables returns the current Environment for the object

type BlockObject

type BlockObject struct {
	BaseObj
	// contains filtered or unexported fields
}

BlockObject represents an instance of `Block` class.

func (*BlockObject) Inspect

func (bo *BlockObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*BlockObject) ToJSON

func (bo *BlockObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*BlockObject) ToString

func (bo *BlockObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*BlockObject) Value

func (bo *BlockObject) Value() interface{}

Value returns the object

type BooleanObject

type BooleanObject bool

BooleanObject represents boolean object in Lito. `Boolean` class is just a dummy to hold logical `true` and `false` representation and no other active usage.

func (BooleanObject) Class

func (b BooleanObject) Class() *RClass

Class returns the built-in Boolean class

func (BooleanObject) EqualTo

func (b BooleanObject) EqualTo(with Object) bool

EqualTo returns if the BooleanObject is equal to another object

func (BooleanObject) FindLookup

func (b BooleanObject) FindLookup(searchAncestor bool) (method Object)

FindLookup ...

func (BooleanObject) FindMethod

func (b BooleanObject) FindMethod(methodName string, super bool) Object

FindMethod ...

func (BooleanObject) GetVariable

func (b BooleanObject) GetVariable(string) (Object, bool)

GetVariable does nothing as Booleans cannot have variables

func (BooleanObject) Inspect

func (b BooleanObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (BooleanObject) IsTruthy

func (b BooleanObject) IsTruthy() bool

IsTruthy returns the boolean value of the object

func (BooleanObject) SetVariable

func (b BooleanObject) SetVariable(n string, o Object) Object

SetVariable does nothing as Booleans cannot have variables

func (BooleanObject) SetVariables

func (b BooleanObject) SetVariables(Environment)

SetVariables ...

func (BooleanObject) ToJSON

func (b BooleanObject) ToJSON(t *Thread) string

ToJSON just delegates to `ToString`

func (BooleanObject) ToString

func (b BooleanObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (BooleanObject) Value

func (b BooleanObject) Value() interface{}

Value returns the object

func (BooleanObject) Variables

func (b BooleanObject) Variables() Environment

Variables ...

type BuiltinMethodObject

type BuiltinMethodObject struct {
	BaseObj
	Name      string
	Fn        Method
	Primitive bool
}

BuiltinMethodObject represents methods defined in go.

func ExternalBuiltinMethod

func ExternalBuiltinMethod(name string, m Method) *BuiltinMethodObject

ExternalBuiltinMethod is a function that builds a BuiltinMethodObject from an external function

func (*BuiltinMethodObject) Inspect

func (bim *BuiltinMethodObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*BuiltinMethodObject) ToJSON

func (bim *BuiltinMethodObject) ToJSON(t *Thread) string

ToJSON just delegates to `ToString`

func (*BuiltinMethodObject) ToString

func (bim *BuiltinMethodObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*BuiltinMethodObject) Value

func (bim *BuiltinMethodObject) Value() interface{}

Value returns builtin method object's function

type CallFrame

type CallFrame struct {
	sync.Mutex
	// contains filtered or unexported fields
}

CallFrame structure to hold a callframe

func (*CallFrame) BlockFrame

func (cf *CallFrame) BlockFrame() *CallFrame

func (*CallFrame) FileName

func (cf *CallFrame) FileName() string

func (*CallFrame) IsBlock

func (cf *CallFrame) IsBlock() bool

func (*CallFrame) IsEmpty

func (cf *CallFrame) IsEmpty() bool

IsEmpty returns true if there are no instructions in the callframe

func (*CallFrame) IsRemoved

func (cf *CallFrame) IsRemoved() bool

func (*CallFrame) Self

func (cf *CallFrame) Self() Object

func (*CallFrame) SourceLine

func (cf *CallFrame) SourceLine() int

type ChannelObject

type ChannelObject struct {
	BaseObj
	Chan         chan *Object
	ChannelState int
}

ChannelObject represents a Golang channel.

func (*ChannelObject) Inspect

func (co *ChannelObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*ChannelObject) ToJSON

func (co *ChannelObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*ChannelObject) ToString

func (co *ChannelObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*ChannelObject) Value

func (co *ChannelObject) Value() interface{}

Value returns the object

type ClassInitFunc

type ClassInitFunc func(vm *VM) *RClass

ClassInitFunc initialises a class for the vm

type ClassLoader

type ClassLoader = func(vm *VM) error

ClassLoader can be registered with a vm so that it can load this library at vm creation

func ExternalClass

func ExternalClass(name, path string, classMethods, instanceMethods map[string]Method) ClassLoader

ExternalClass helps define external go classes

type ConfigFunc

type ConfigFunc = func(vm *VM) error

ConfigFunc can be registered with a vm so that it can load this library at vm creation

func LibraryPath

func LibraryPath(path string) ConfigFunc

LibraryPath set the path to the libraries

func Mode

func Mode(mode parser.Mode) ConfigFunc

Mode sets the mode of the vm

type Environment

type Environment map[string]Object

Environment stores a set of Objects addressable by name

func (Environment) EqualTo

func (e Environment) EqualTo(other Environment) bool

EqualTo returns if the Environment is equal to another Environment

type Error

type Error struct {
	BaseObj

	Type   string
	Ignore bool
	Raised bool
	// contains filtered or unexported fields
}

Error class is a struct to hold internal error types with messages.

func (*Error) Inspect

func (e *Error) Inspect(t *Thread) string

Inspect delegates to ToString

func (*Error) Message

func (e *Error) Message() string

Message prints the error's message and its stack traces

func (*Error) ToJSON

func (e *Error) ToJSON(t *Thread) string

ToJSON just delegates to `ToString`

func (*Error) ToString

func (e *Error) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*Error) Value

func (e *Error) Value() interface{}

Value returns the message associated with the error

type FileObject

type FileObject struct {
	BaseObj
	File *os.File
}

FileObject is a special type that contains file pointer so we can keep track on target file. Using `File.open` with block is recommended because the instance (block variable) automatically closes.

func (*FileObject) Inspect

func (f *FileObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*FileObject) ToJSON

func (f *FileObject) ToJSON(t *Thread) string

ToJSON just delegates to `ToString`

func (*FileObject) ToString

func (f *FileObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*FileObject) Value

func (f *FileObject) Value() interface{}

Value returns file object's string format

type FloatObject

type FloatObject float64

FloatObject represents a real number

func (FloatObject) Class

func (f FloatObject) Class() *RClass

Class ...

func (FloatObject) EqualTo

func (f FloatObject) EqualTo(rightObject Object) bool

EqualTo apply an equality test, returning true if the objects are considered equal, and false otherwise.

func (FloatObject) FindLookup

func (f FloatObject) FindLookup(searchAncestor bool) (method Object)

FindLookup ...

func (FloatObject) FindMethod

func (f FloatObject) FindMethod(methodName string, super bool) (method Object)

FindMethod ...

func (FloatObject) GetVariable

func (f FloatObject) GetVariable(string) (Object, bool)

GetVariable ...

func (FloatObject) Inspect

func (f FloatObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (FloatObject) IsTruthy

func (f FloatObject) IsTruthy() bool

IsTruthy ...

func (FloatObject) SetVariable

func (f FloatObject) SetVariable(string, Object) Object

SetVariable ...

func (FloatObject) SetVariables

func (f FloatObject) SetVariables(Environment)

SetVariables ...

func (FloatObject) ToJSON

func (f FloatObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString Converts NaN and Inf to null, as these are not supported in the JSON spec

func (FloatObject) ToString

func (f FloatObject) ToString(t *Thread) string

ToString returns the object's value as the string format

func (FloatObject) Value

func (f FloatObject) Value() interface{}

Value returns the object

func (FloatObject) Variables

func (f FloatObject) Variables() Environment

Variables ...

type GoObject

type GoObject struct {
	BaseObj
	// contains filtered or unexported fields
}

GoObject is used to hold opaque Golang values that cannot be converted to Objects

func (*GoObject) Inspect

func (s *GoObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*GoObject) ToJSON

func (s *GoObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*GoObject) ToString

func (s *GoObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*GoObject) Value

func (s *GoObject) Value() interface{}

Value returns the object

type HashObject

type HashObject struct {
	BaseObj
	Pairs map[string]Object
}

HashObject represents a map instance. TODO: Think about a new representation for this

func InitHashObject

func InitHashObject(pairs map[string]Object) *HashObject

InitHashObject initialise the HashObject

func (*HashObject) EqualTo

func (h *HashObject) EqualTo(with Object) bool

EqualTo returns true if the HashObject is equal to the given Object

func (*HashObject) Inspect

func (h *HashObject) Inspect(t *Thread) string

Inspect returns the inspection of the object

func (*HashObject) ToJSON

func (h *HashObject) ToJSON(t *Thread) string

ToJSON returns the object's name as the JSON string format

func (*HashObject) ToString

func (h *HashObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*HashObject) Value

func (h *HashObject) Value() interface{}

Value returns the object

type IntegerObject

type IntegerObject int

IntegerObject represents number objects which can bring into mathematical calculations.

func (IntegerObject) Class

func (i IntegerObject) Class() *RClass

Class ...

func (IntegerObject) EqualTo

func (i IntegerObject) EqualTo(rightObject Object) bool

EqualTo apply an equality test, returning true if the objects are considered equal, and false otherwise.

func (IntegerObject) FindLookup

func (i IntegerObject) FindLookup(searchAncestor bool) (method Object)

FindLookup ...

func (IntegerObject) FindMethod

func (i IntegerObject) FindMethod(methodName string, super bool) Object

FindMethod ...

func (IntegerObject) GetVariable

func (i IntegerObject) GetVariable(string) (Object, bool)

GetVariable ...

func (IntegerObject) Inspect

func (i IntegerObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (IntegerObject) IsTruthy

func (i IntegerObject) IsTruthy() bool

IsTruthy ...

func (IntegerObject) SetVariable

func (i IntegerObject) SetVariable(n string, o Object) Object

SetVariable ...

func (IntegerObject) SetVariables

func (i IntegerObject) SetVariables(Environment)

SetVariables ...

func (IntegerObject) ToJSON

func (i IntegerObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (IntegerObject) ToString

func (i IntegerObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (IntegerObject) Value

func (i IntegerObject) Value() interface{}

Value returns the object

func (IntegerObject) Variables

func (i IntegerObject) Variables() Environment

Variables ...

type LockObject

type LockObject struct {
	BaseObj
	// contains filtered or unexported fields
}

LockObject is a Golang Lock.

func (*LockObject) Inspect

func (lock *LockObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*LockObject) ToJSON

func (lock *LockObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*LockObject) ToString

func (lock *LockObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*LockObject) Value

func (lock *LockObject) Value() interface{}

Value returns the object

type Method

type Method = func(receiver Object, t *Thread, args []Object) Object

Method is a callable function

func NoSuchMethod

func NoSuchMethod(name string) Method

NoSuchMethod convenience function for when the method does not exist

type MethodObject

type MethodObject struct {
	BaseObj
	Name string
	// contains filtered or unexported fields
}

MethodObject represents methods defined using Lito.

func (*MethodObject) Inspect

func (m *MethodObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*MethodObject) ToJSON

func (m *MethodObject) ToJSON(t *Thread) string

ToJSON returns the method as a JSON string

func (*MethodObject) ToString

func (m *MethodObject) ToString(t *Thread) string

ToString returns a string representation of the method

func (*MethodObject) Value

func (m *MethodObject) Value() interface{}

Value returns method object's string format

type NilObject

type NilObject struct {
	BaseObj
}

NilObject (`nil`) represents the nil value in Lito. `nil` is converted into `null` when exported to JSON format.

var (
	// NIL represents Lito's nil object. This is a singleton value
	// and can be compared using ==.
	NIL *NilObject
)

func (*NilObject) EqualTo

func (n *NilObject) EqualTo(compared Object) bool

EqualTo returns if the NilObject is equal to another object. This will only return true if the other object is NIL

func (*NilObject) Inspect

func (n *NilObject) Inspect(t *Thread) string

Inspect returns string "nil" instead of "" like ToString

func (*NilObject) IsTruthy

func (n *NilObject) IsTruthy() bool

IsTruthy ...

func (*NilObject) ToJSON

func (n *NilObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*NilObject) ToString

func (n *NilObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*NilObject) Value

func (n *NilObject) Value() interface{}

Value returns the object

type Numeric

type Numeric interface {
	// contains filtered or unexported methods
}

Numeric represents a class that support numeric conversion to float.

type Object

type Object interface {
	Class() *RClass
	Value() interface{}
	FindMethod(string, bool) Object
	FindLookup(bool) Object
	ToString(t *Thread) string
	Inspect(t *Thread) string
	ToJSON(t *Thread) string
	GetVariable(string) (Object, bool)
	SetVariable(string, Object) Object
	Variables() Environment
	SetVariables(Environment)
	IsTruthy() bool
	EqualTo(Object) bool
}

Object represents all objects in Lito, including Array, Integer or even Method and Error.

type Pointer

type Pointer struct {
	Target Object
}

Pointer is used to point to an object. Variables should hold pointer instead of holding a object directly.

type RClass

type RClass struct {
	BaseObj
	// Name is the class's name
	Name string
	// Methods contains its instances' methods
	Methods Environment
	// contains filtered or unexported fields
}

RClass represents normal (not built in) class object

func (*RClass) ClassMethods

func (c *RClass) ClassMethods(methodList []*BuiltinMethodObject) *RClass

ClassMethods adds the class methods to the class's metaclass

func (*RClass) EqualTo

func (c *RClass) EqualTo(with Object) bool

EqualTo returns true if the class is equal to the given object

func (*RClass) FindLookup

func (c *RClass) FindLookup(searchAncestor bool) (method Object)

FindLookup ...

func (*RClass) FindMethod

func (c *RClass) FindMethod(methodName string, super bool) (method Object)

FindMethod ...

func (*RClass) Inspect

func (c *RClass) Inspect(t *Thread) string

Inspect delegates to ToString

func (*RClass) InstanceMethods

func (c *RClass) InstanceMethods(methodList []*BuiltinMethodObject) *RClass

InstanceMethods adds the instance methods to the class

func (*RClass) MetaClass

func (c *RClass) MetaClass() *RClass

MetaClass returns the metaclass of the given class

func (*RClass) SetClassConstant

func (c *RClass) SetClassConstant(constant *RClass)

SetClassConstant adds a class to the class's constants. Name is take from the class name of the supplied parameter.

func (*RClass) SetConstant

func (c *RClass) SetConstant(name string, constant Object) *RClass

SetConstant adds the constant to the class's constants, with the given name.

func (*RClass) SetMetaClass

func (c *RClass) SetMetaClass(m *RClass)

SetMetaClass sets object's metaclass

func (*RClass) ToJSON

func (c *RClass) ToJSON(t *Thread) string

ToJSON just delegates to `ToString`

func (*RClass) ToString

func (c *RClass) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*RClass) Value

func (c *RClass) Value() interface{}

Value returns class itself

type RObject

type RObject struct {
	BaseObj
}

RObject represents any non built-in class's instance.

func (*RObject) EqualTo

func (ro *RObject) EqualTo(with Object) bool

EqualTo returns if the RObject is equal to another object

func (*RObject) Inspect

func (ro *RObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*RObject) ToJSON

func (ro *RObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*RObject) ToString

func (ro *RObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*RObject) Value

func (ro *RObject) Value() interface{}

Value returns object's string format

type RangeObject

type RangeObject struct {
	BaseObj
	Start     int
	End       int
	Exclusive bool
}

RangeObject is the built in range class Range represents an interval: a set of values from the beginning to the end specified. Currently, only Integer objects or integer literal are supported.

func (*RangeObject) EqualTo

func (ro *RangeObject) EqualTo(with Object) bool

EqualTo returns if the RangeObject is equal to another object

func (*RangeObject) Inspect

func (ro *RangeObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*RangeObject) ToJSON

func (ro *RangeObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*RangeObject) ToString

func (ro *RangeObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*RangeObject) Value

func (ro *RangeObject) Value() interface{}

Value returns range object's string format

type Regexp

type Regexp = regexp.Regexp

Regexp type alias for regexp

type RegexpObject

type RegexpObject struct {
	BaseObj
	// contains filtered or unexported fields
}

RegexpObject represents regexp instances, which of the type is actually string.

func (*RegexpObject) EqualTo

func (r *RegexpObject) EqualTo(with Object) bool

EqualTo returns true if the RegexpObject is equal to the other object

func (*RegexpObject) Inspect

func (r *RegexpObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*RegexpObject) ToJSON

func (r *RegexpObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*RegexpObject) ToString

func (r *RegexpObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*RegexpObject) Value

func (r *RegexpObject) Value() interface{}

Value returns the object

type Stack

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

Stack is a basic stack implementation

func (*Stack) Discard

func (s *Stack) Discard()

Discard discard the top of the stack

func (*Stack) Pop

func (s *Stack) Pop() Object

Pop an element off the top of the stack

func (*Stack) Push

func (s *Stack) Push(v Object)

Push an element to the top of the stack

func (*Stack) PushFlags

func (s *Stack) PushFlags(v bits)

PushFlags an element to the top of the stack

func (*Stack) Set

func (s *Stack) Set(index int, o Object)

Set a value at a given index in the stack. TODO: Maybe we should be checking for size before we do this. Seems to be safe, but should probably not be exported.

type StringObject

type StringObject string

StringObject represents string instances.

func (StringObject) Class

func (s StringObject) Class() *RClass

Class ...

func (StringObject) EqualTo

func (s StringObject) EqualTo(compared Object) bool

EqualTo returns if the StringObject is equal to another object

func (StringObject) FindLookup

func (s StringObject) FindLookup(searchAncestor bool) (method Object)

FindLookup returns the lookup! method for a StringObject, if any

func (StringObject) FindMethod

func (s StringObject) FindMethod(methodName string, super bool) (method Object)

FindMethod ...

func (StringObject) GetVariable

func (s StringObject) GetVariable(string) (Object, bool)

GetVariable does nothing as Strings cannot have variables

func (StringObject) Inspect

func (s StringObject) Inspect(t *Thread) string

Inspect wraps ToString with double quotes

func (StringObject) IsTruthy

func (s StringObject) IsTruthy() bool

IsTruthy ...

func (StringObject) SetVariable

func (s StringObject) SetVariable(n string, o Object) Object

SetVariable does nothing as Strings cannot have variables

func (StringObject) SetVariables

func (s StringObject) SetVariables(Environment)

SetVariables ...

func (StringObject) ToJSON

func (s StringObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (StringObject) ToString

func (s StringObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (StringObject) Value

func (s StringObject) Value() interface{}

Value returns the object

func (StringObject) Variables

func (s StringObject) Variables() Environment

Variables ...

type Thread

type Thread struct {

	// data Stack
	Stack Stack
	// contains filtered or unexported fields
}

Thread is the context needed for a single thread of execution

func (*Thread) BlockGiven

func (t *Thread) BlockGiven() bool

BlockGiven returns whether or not we have a block frame below us in the stack

func (*Thread) FindAndExecute

func (t *Thread) FindAndExecute(receiver Object, methodName string, super bool, receiverPr int, argPr int, argCount int, argSet *bytecode.ArgSet, blockFrame *CallFrame, fileName string)

FindAndExecute finds and executes a method

func (*Thread) GetBlock

func (t *Thread) GetBlock() *CallFrame

GetBlock returns the current block

func (*Thread) GetSourceLine

func (t *Thread) GetSourceLine() int

GetSourceLine returns the current source line

func (*Thread) VM

func (t *Thread) VM() *VM

VM returns the VM associated with the thread

func (*Thread) Yield

func (t *Thread) Yield(blockFrame *CallFrame, args ...Object) Object

Yield executes a block frame and returns the result

func (*Thread) YieldWithBlockArgument

func (t *Thread) YieldWithBlockArgument(blockFrame *CallFrame, block *CallFrame, args ...Object) Object

YieldWithBlockArgument executes a block frame and returns the result

type VM

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

VM represents a stack based virtual machine.

func New

func New(fileDir string, args []string, configs ...ConfigFunc) (vm *VM, err error)

New initialises a vm to initial state and returns it.

func (*VM) AddLibrary

func (vm *VM) AddLibrary(libs ...string)

AddLibrary adds library files to be loaded by the VM

func (*VM) CurrentFilePath

func (vm *VM) CurrentFilePath() string

CurrentFilePath returns the current file name

func (*VM) ExecInstructions

func (vm *VM) ExecInstructions(sets []*bytecode.InstructionSet, fn string)

ExecInstructions accepts a sequence of bytecodes and use vm to evaluate them. We also pass in the file name for use in stack traces

func (*VM) GetBaseFrame

func (vm *VM) GetBaseFrame() *CallFrame

GetBaseFrame returns the bottom frame for use by the REPL

func (*VM) GetExecResult

func (vm *VM) GetExecResult() Object

GetExecResult returns stack's top most value. Normally it's used in tests.

func (*VM) GetREPLResult

func (vm *VM) GetREPLResult() string

GetREPLResult returns a string that should be shown after each evaluation.

func (*VM) InitClass

func (vm *VM) InitClass(name string) *RClass

InitClass is a common function for vm, which initialises and returns a class instance with given class name.

func (*VM) InitErrorObject

func (vm *VM) InitErrorObject(t *Thread, errorType string, format string, args ...interface{}) *Error

InitErrorObject is to initialise and return an error object.

func (*VM) InitForREPL

func (vm *VM) InitForREPL()

InitForREPL does following things: - Set vm to REPL mode - Create and push main object frame

func (*VM) InitGoTypeFromObject

func (vm *VM) InitGoTypeFromObject(value Object) interface{}

InitGoTypeFromObject returns an object that can be used from Lito

func (*VM) InitModule

func (vm *VM) InitModule(name string) *RClass

InitModule creates a new module with the given name

func (*VM) InitNoMethodError

func (vm *VM) InitNoMethodError(t *Thread, methodName string, receiver Object) *Error

InitNoMethodError is to print unsupported method errors. This is exported for using from sub-packages.

func (*VM) InitObjectFromGoType

func (vm *VM) InitObjectFromGoType(value interface{}) Object

InitObjectFromGoType returns an object that can be used from Lito

func (*VM) REPLExec

func (vm *VM) REPLExec(sets []*bytecode.InstructionSet)

REPLExec executes instructions differently from normal program execution.

func (*VM) TopLevelClass

func (vm *VM) TopLevelClass(cn string) *RClass

TopLevelClass returns the class for a given name

type WaitGroupObject

type WaitGroupObject struct {
	BaseObj
	WaitGroup sync.WaitGroup
}

WaitGroupObject represents a Golang WaitGroup.

func (*WaitGroupObject) Inspect

func (co *WaitGroupObject) Inspect(t *Thread) string

Inspect delegates to ToString

func (*WaitGroupObject) ToJSON

func (co *WaitGroupObject) ToJSON(t *Thread) string

ToJSON just delegates to ToString

func (*WaitGroupObject) ToString

func (co *WaitGroupObject) ToString(t *Thread) string

ToString returns the object's name as the string format

func (*WaitGroupObject) Value

func (co *WaitGroupObject) Value() interface{}

Value returns the object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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