Documentation ¶
Index ¶
Constants ¶
const ( // RuntimeError is used for an error of unknown/generic nature. RuntimeError = "Runtime" // TypeError is used for an error where types are incompatible or wrong. TypeError = "Type" // InternalError is used for internal errors, and when something is wrong with the bytecode. InternalError = "Internal" // NameError is used for undefined variables, functions, and other names. NameError = "Name" // ArgumentError is used for invalid arguments to a function or model. ArgumentError = "Argument" // StructureError is used for a structure error, such as a break outside a loop. StructureError = "Structure" // IndexError is used when an invalid index/key is used. IndexError = "Index" )
Variables ¶
var ( // MaxDataStackSize is the maximum amount of objects which are allowed to // be inside the data stack. MaxDataStackSize = 100000 // DefaultDataStackCapacity is the capacity initially allocated to the stack. A // higher value will possibly increase performance, but use more RAM. DefaultDataStackCapacity = 32 // ErrDataStackOverflow tells the user that too many objects were pushed to // the data stack. ErrDataStackOverflow = makeError(InternalError, "too many objects on the data stack") // ErrDataStackUnderflow tells the user that a pop was attempted but no objects // were on the stack. ErrDataStackUnderflow = makeError(InternalError, "no objects to pop from the data stack") )
var Effectors [256]Effector
Effectors stores the effector function for each instruction. The effector for an instruction n can be accessed via Effectors[n].
var (
// InterruptQueueSize specifies the buffer size of the interrupt queue.
InterruptQueueSize = 64
)
Functions ¶
This section is empty.
Types ¶
type Error ¶
An Error represents any type of runtime error (not just RuntimeError), and implements the error interface.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
A Frame is created for each function call, and also one for the main program. It contains the bytecode to execute, along with the frame's constants and names, and other data.
type Interrupt ¶
type Interrupt int
Interrupt defines the type of an interrupt which, when sent to the virtual machine through the Interrupts chan, stops the fetch-decode-execute cycle and does something.
const ( // Stop stops the execution Stop Interrupt // Pause pauses the execution until Resume is sent. All other interrupts are ignored until // Resume is sent. Pause // Resume resumes a paused virtual machine. Resume )
type Stack ¶
A Stack is created for each frame in the virtual machine, and stores a stack of objects which can be popped or pushed.
func NewStack ¶
func NewStack() *Stack
NewStack makes a new empty Stack, with capacity equal to DefaultStackCapacity.
func (*Stack) Pop ¶
Pop pops an Object from the Stack, returning it. If it returns an error, it will be ErrDataStackUnderflow.
type Store ¶
A Store contains all the variables defined in a particular scope. A Store also has a pointer to the enclosing scope.
type StorePool ¶
type StorePool struct {
// contains filtered or unexported fields
}
A StorePool contains a number of Stores, which can be released quickly. This avoids creating stores, which is slower than just reusing existing ones.
func NewStorePool ¶
func NewStorePool() *StorePool
NewStorePool makes a new store pool with initialStorePoolSize stores.
type VM ¶
type VM struct { // Interrupts is a queue (in the form of a channel) which, when an interrupt is added, // will stop the virtual machine and do something based on the nature of the interrupt. Interrupts chan Interrupt // Out is the io.Writer to which the virtual machine outputs to. This includes functions // like print, but also errors and various messages. Out io.Writer // contains filtered or unexported fields }
A VM (for Virtual Machine), interprets bytecode. It's a stack machine, so operates by pushing to and popping from data stacks, instead of using registers like a computer.
func (*VM) ExtractValue ¶
ExtractValue returns the top value from the top frame, if both those things exist.
func (*VM) MakeFrame ¶
func (v *VM) MakeFrame(code bytecode.Code, args, store *Store, constants []object.Object, names []string, jumps []int) *Frame
MakeFrame makes a Frame instance with the given parameters. offset is set to 0 and a new data stack is created. The variables in args, if it's non-nil, are declared in the Frame's store (note: declared, not assigned).