aboutsummaryrefslogtreecommitdiff
path: root/pkg/lang/vm/stack
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/stack')
-rw-r--r--pkg/lang/vm/stack/stack.go29
1 files changed, 13 insertions, 16 deletions
diff --git a/pkg/lang/vm/stack/stack.go b/pkg/lang/vm/stack/stack.go
index 74d4ab8..c710878 100644
--- a/pkg/lang/vm/stack/stack.go
+++ b/pkg/lang/vm/stack/stack.go
@@ -19,8 +19,8 @@ type Stack interface {
IsEmpty() bool
PutRootCall(basePos code.Pos) error
- PushCall(newPos, returnPos code.Pos, env mem.Ptr) error
- PopCall() (code.Pos, error)
+ PushCall(fn value.FunctionData, returnPos code.Pos) error
+ PopCall() (value.FunctionData, code.Pos, error)
CurrentCallEnv() mem.Ptr
CallDepth() int
@@ -104,10 +104,9 @@ func (stack *stackImpl) IsEmpty() bool {
func (stack *stackImpl) PutRootCall(basePos code.Pos) error {
frame := callFrame{
- pos: basePos,
+ fn: value.FunctionData{},
returnPos: basePos,
base: 0,
- env: mem.NullPtr,
}
if stack.CallDepth() == 0 {
@@ -125,38 +124,37 @@ func (stack *stackImpl) PutRootCall(basePos code.Pos) error {
return nil
}
-func (stack *stackImpl) PushCall(newPos, returnPos code.Pos, env mem.Ptr) error {
+func (stack *stackImpl) PushCall(fn value.FunctionData, returnPos code.Pos) error {
if stack.CallDepth() == 1000 {
return ErrReachedMaxCallDepth
}
stack.calls = append(stack.calls, callFrame{
- pos: newPos,
+ fn: fn,
returnPos: returnPos,
base: stack.Len(),
- env: env,
})
return nil
}
-func (stack *stackImpl) PopCall() (code.Pos, error) {
+func (stack *stackImpl) PopCall() (value.FunctionData, code.Pos, error) {
if stack.CallDepth() == 0 {
- return code.Pos{}, ErrReachedRootCallFrame
+ return value.FunctionData{}, code.Pos{}, ErrReachedRootCallFrame
}
call := stack.topCall()
stack.calls = stack.calls[:stack.CallDepth()-1]
- return call.returnPos, nil
+ return call.fn, call.returnPos, nil
}
func (stack *stackImpl) CurrentCallEnv() mem.Ptr {
- if stack.CallDepth() == 0 || stack.topCall().env.IsNull() {
+ if stack.CallDepth() == 0 || stack.topCall().fn.Env().IsNull() {
return mem.NullPtr
}
- return stack.topCall().env
+ return stack.topCall().fn.Env()
}
func (stack *stackImpl) CallDepth() int {
@@ -179,8 +177,7 @@ func (stack *stackImpl) topCall() *callFrame {
}
type callFrame struct {
- pos code.Pos // Beginning of the called function.
- returnPos code.Pos // Where to return to after the called function returns.
- base int // Base of the local variables on the data stack.
- env mem.Ptr // Environment of the called function.
+ fn value.FunctionData // The called function.
+ returnPos code.Pos // Where to return to after the called function returns.
+ base int // Base of the local variables on the data stack.
}