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 ¶
- type Frame
- type Type
- func (m *Type) CallDepth() int
- func (m *Type) Clone(reuse *Type) *Type
- func (m *Type) DumpStack(dbg *dbginfo.Type)
- func (m *Type) IP() *value.Type
- func (m *Type) LookUpClosure(symIdx int) value.Type
- func (m *Type) LookUpGlobal(name string) value.Type
- func (m *Type) LookUpLocal(symIdx int) value.Type
- func (m *Type) Pop() value.Type
- func (m *Type) PopClosure()
- func (m *Type) PopFrame()
- func (m *Type) Push(v value.Type)
- func (m *Type) PushClosure(f Frame)
- func (m *Type) PushFrame(argsCnt, localCnt int)
- func (m *Type) Reset()
- func (m *Type) ResetSP()
- func (m *Type) Set(symIdx int, v value.Type)
- func (m *Type) SetGlobal(name string, v value.Type)
- func (m *Type) Top() Frame
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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) Clone ¶
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) LookUpClosure ¶
LookUpClosure looks up a closure variable. A variable that was local in the containing lexical scope.
func (*Type) LookUpGlobal ¶
LookUpGlobal looks up a global variable.
func (*Type) LookUpLocal ¶
LookUpLocal looks up a local variable.
func (*Type) PopClosure ¶
func (m *Type) PopClosure()
PopClosure pops a frame from the closure region.
func (*Type) PushClosure ¶
PushClosure pushes the closure frame.
func (*Type) Reset ¶ added in v1.4.0
func (m *Type) Reset()
Reset drops all stack local allocations.