vm

package
v0.0.0-...-92c1b66 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const GlobalsSize = 65536

GlobalsSize - The upper limit on the number of global bindings our VM supports

View Source
const MaxFrames = 1024

MaxFrames defines the maximum frames allowed in the VM

View Source
const StackSize = 2048

StackSize is an integer defining the size of our stack

Variables

View Source
var False = &object.Boolean{Value: false}

False - Pointer to a O Language object.Boolean of value false

View Source
var Null = &object.Null{}

Null - Pointer to a O Language object.Null

View Source
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

func NewFrame(cl *object.Closure, basePointer int) *Frame

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

func New(bytecode *compiler.Bytecode) *VM

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

func NewWithGlobalsState(bytecode *compiler.Bytecode, s []object.Object) *VM

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

func (vm *VM) LastPoppedStackElement() object.Object

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.

func (*VM) Run

func (vm *VM) Run() error

Run runs our VM and starts the fetch-decode-execute cycle

Jump to

Keyboard shortcuts

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