about summary refs log tree commit diff
path: root/pkg/lang/vm/exec.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-29 22:21:36 +0000
committerMel <einebeere@gmail.com>2022-08-29 22:21:36 +0000
commitb4a0f2209026a90bfd67072526f938e00c00af78 (patch)
treec830edfa2cab2b4a679b8501d36171a39b319a58 /pkg/lang/vm/exec.go
parent1bc5eb0d13bb001b4ac7f456c6a61fedcd53f0c8 (diff)
downloadjinx-b4a0f2209026a90bfd67072526f938e00c00af78.tar.zst
jinx-b4a0f2209026a90bfd67072526f938e00c00af78.zip
Put full function data onto call stack
Diffstat (limited to 'pkg/lang/vm/exec.go')
-rw-r--r--pkg/lang/vm/exec.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/lang/vm/exec.go b/pkg/lang/vm/exec.go
index 8cdcdcc..c2d847f 100644
--- a/pkg/lang/vm/exec.go
+++ b/pkg/lang/vm/exec.go
@@ -987,7 +987,7 @@ func (vm *VM) execCall(argCount uint) error {
 		}
 	}
 
-	if err = vm.stack.PushCall(fn.Pos(), vm.pos, fn.Env()); err != nil {
+	if err = vm.stack.PushCall(fn, vm.pos); err != nil {
 		return err
 	}
 
@@ -997,7 +997,7 @@ func (vm *VM) execCall(argCount uint) error {
 			return err
 		}
 
-		if _, err := vm.stack.PopCall(); err != nil {
+		if _, _, err := vm.stack.PopCall(); err != nil {
 			return err
 		}
 
@@ -1007,6 +1007,11 @@ func (vm *VM) execCall(argCount uint) error {
 			vm.stack.Push(value.NewNull())
 		}
 
+		// If the function was native we can drop it immidiately, after the call.
+		if err := f.Drop(vm.memory); err != nil {
+			return err
+		}
+
 		return nil
 	}
 
@@ -1016,6 +1021,8 @@ func (vm *VM) execCall(argCount uint) error {
 
 	vm.setPos(fn.Pos())
 
+	// Note that value 'f' is still not dropped, as it's enviroment has
+	// been stored in the call stack. It will be dropped on the next return.
 	return nil
 }