about summary refs log tree commit diff
path: root/pkg/lang/vm/utils.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-11 01:25:47 +0000
committerMel <einebeere@gmail.com>2022-08-11 01:25:47 +0000
commit86f31acf6789be116dcc54ed85b069a37c0f7aa8 (patch)
treebc7afd6a8c340825996d29c6cfd392ae42b4fbd5 /pkg/lang/vm/utils.go
parentc46b2bc7ce6df1f2c6c9494ef08015ec29992da5 (diff)
downloadjinx-86f31acf6789be116dcc54ed85b069a37c0f7aa8.tar.zst
jinx-86f31acf6789be116dcc54ed85b069a37c0f7aa8.zip
Actual modules and core
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
 }