Documentation ¶
Index ¶
Constants ¶
const GlobalsSize = 65536
GlobalsSize - The upper limit on the number of global bindings our VM supports
const MaxFrames = 1024
MaxFrames defines the maximum frames allowed in the VM
const StackSize = 2048
StackSize is an integer defining the size of our stack
Variables ¶
var False = &object.Boolean{Value: false}
False - Pointer to a O Language object.Boolean of value false
var Null = &object.Null{}
Null - Pointer to a O Language object.Null
var True = &object.Boolean{Value: true}
True - Pointer to a O Language object.Boolean with value true
Functions ¶
This section is empty.
Types ¶
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame - Data structure that holds execution-relevant information. Short for "call frame" or "stack frame" and sometimes "activation record". On real machines a frame is not something separate from, but a designated part of "the stack". It's where the return address, the arguments to the current function, and it's local variables are stored. In VM land we don't have to use the stack. We're not constrained by standardized calling conventions and other much too real things, like real memory addresses and locations. Since we can store frames anywhere we like. What's kept on the stack and what's not differs from VM to VM. Some keep everything on the stack, others only the return address, some only the local variables, some the local variables and the arguments of the function call. The implementation depends on the language being implemented, the requirements in regards to concurrency and performance, the host language, and more. We are choosing the way that is easiest to build, understand, extend, etc.
func NewFrame ¶
NewFrame takes a pointer to a compiled function, creates a frame with it, sets the instruction pointer to -1, and returns a pointer to the frame.
func (*Frame) Instructions ¶
func (f *Frame) Instructions() code.Instructions
Instructions returns the frame's function's instructions
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM defines our Virtual Machine. It holds our constant pool, instructions, a stack, and an integer (index) that points to the next free slot in the stack
func New ¶
New initializers and returns a pointer to a VM. It takes bytecode and sets the bytecode's instructions and constants to the VM, creates a new stack with StackSize number of elements, and initializes the ip to 0
func NewWithGlobalsState ¶
NewWithGlobalsState creates a new VM with a compiler's bytecode, sets the VMs globals and returns a pointer to the VM (used in REPL)
func (*VM) LastPoppedStackElement ¶
LastPoppedStackElement returns last popped element on the top of the stack. We do not explicitly set them to nil or remove them when calling pop so it will point to last popped.