From 86f31acf6789be116dcc54ed85b069a37c0f7aa8 Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 11 Aug 2022 01:25:47 +0000 Subject: Actual modules and core --- pkg/lang/vm/utils.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pkg/lang/vm/utils.go') 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 } -- cgit 1.4.1