memory

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package memory provides our memory model.

There are 3 main regions. Global, the closure stack and the normal stack.

Local and closure variables are accessed via symbol tbl index. Global variables are accessed using their name.

The global region is special, it's a map from variable names to values. This is because we can gradually parse more and more code that can define new global variables, so the symbol table phase can't work out a symbol tbl index for these variables.

The closure region is pointers to cloned slices of the normal stack. When a function returns a function we save the frame of the defining function in the returned function value. When a function is called apart from pushing the normal frame on the normal stack we need to push the closure frame from the function value on the closure stack.

Normal stack is an ever growing slice of values. The fp has a pair of pointers into the stack per frame: fp and le the frame pointer and local end. Local variables live on the normal stack. Function arguments count as local variables. Local variables of the frame are between fp and le . le points to the function return address. After le it's stack scratch area.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame = []value.Type

type Type

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

Memory holds all variables.

func New

func New() *Type

New creates a new memory, with an empty global frame and an empty stack.

func (*Type) CallDepth added in v1.5.0

func (m *Type) CallDepth() int

CallDepth is the number of call frames.

func (*Type) Clone

func (m *Type) Clone(reuse *Type) *Type

Clone does a memory copy for context switching.

The clone would point to the same global, same closure, and the last frame of the stack will be deep copied. reuse can be nil, when it's not it's resources are re-used to create a new memory.

func (*Type) DumpStack added in v1.4.0

func (m *Type) DumpStack(dbg *dbginfo.Type)

DumpStack is a debug dump of the stack.

func (*Type) IP

func (m *Type) IP() *value.Type

IP returns the function return address.

func (*Type) LookUpClosure

func (m *Type) LookUpClosure(symIdx int) value.Type

LookUpClosure looks up a closure variable. A variable that was local in the containing lexical scope.

func (*Type) LookUpGlobal

func (m *Type) LookUpGlobal(name string) value.Type

LookUpGlobal looks up a global variable.

func (*Type) LookUpLocal

func (m *Type) LookUpLocal(symIdx int) value.Type

LookUpLocal looks up a local variable.

func (*Type) Pop

func (m *Type) Pop() value.Type

Pop pops the last pushed value decrementing the stack pointer.

func (*Type) PopClosure

func (m *Type) PopClosure()

PopClosure pops a frame from the closure region.

func (*Type) PopFrame

func (m *Type) PopFrame()

PopFrame pops a stack frame.

func (*Type) Push

func (m *Type) Push(v value.Type)

Push pushes a value.

func (*Type) PushClosure

func (m *Type) PushClosure(f Frame)

PushClosure pushes the closure frame.

func (*Type) PushFrame

func (m *Type) PushFrame(argsCnt, localCnt int)

PushFrame pushes a stack frame.

func (*Type) Reset added in v1.4.0

func (m *Type) Reset()

Reset drops all stack local allocations.

func (*Type) ResetSP

func (m *Type) ResetSP()

ResetSP resets the stack pointer to 0.

func (*Type) Set

func (m *Type) Set(symIdx int, v value.Type)

Set sets a local variable.

func (*Type) SetGlobal

func (m *Type) SetGlobal(name string, v value.Type)

SetGlobal sets a global variable.

func (*Type) Top

func (m *Type) Top() Frame

Top is the last stack frame pushed.

Jump to

Keyboard shortcuts

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