about summary refs log tree commit diff
path: root/pkg/lang/vm/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/vm/utils.go')
-rw-r--r--pkg/lang/vm/utils.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/pkg/lang/vm/utils.go b/pkg/lang/vm/utils.go
index 2b7fa6f..975d31b 100644
--- a/pkg/lang/vm/utils.go
+++ b/pkg/lang/vm/utils.go
@@ -1,6 +1,7 @@
 package vm
 
 import (
+	"jinx/pkg/lang/modules"
 	"jinx/pkg/lang/vm/code"
 	"jinx/pkg/lang/vm/mem"
 	"jinx/pkg/lang/vm/value"
@@ -35,7 +36,7 @@ func (vm *VM) getMemCell(ptr mem.Ptr, kind mem.CellKind, allowNil bool) (mem.Cel
 	}
 
 	if !vm.memory.Is(ptr, kind) {
-		return nil, ErrUnexpectedMemCell{Ptr: ptr, Expected: mem.CellKindEnv, Got: vm.memory.Kind(ptr)}
+		return nil, ErrUnexpectedMemCell{Ptr: ptr, Expected: kind, Got: vm.memory.Kind(ptr)}
 	}
 
 	cell, err := vm.memory.Get(ptr)
@@ -75,10 +76,18 @@ func (vm *VM) getMemCell(ptr mem.Ptr, kind mem.CellKind, allowNil bool) (mem.Cel
 	return cell, nil
 }
 
-func (vm *VM) module() int {
+func (vm *VM) moduleID() int {
 	return vm.pos.Module
 }
 
+func (vm *VM) module() modules.Module {
+	if vm.moduleID() == -1 {
+		return vm.main
+	} else {
+		return vm.modules[vm.moduleID()]
+	}
+}
+
 func (vm *VM) pc() int {
 	return vm.pos.PC
 }