Expose mutable memory access

This commit is contained in:
Mateusz Galazyn
2022-10-22 09:37:50 +02:00
parent c8f1bc9186
commit 3be70781b8
2 changed files with 14 additions and 5 deletions
+12 -3
View File
@@ -10,8 +10,11 @@ module Language.Wasm.Interpreter (
ExternalValue(..),
ExportInstance(..),
GlobalInstance(..),
MemoryInstance(..),
MemoryStore,
Imports,
HostItem(..),
HostItem(..),
Address,
instantiate,
invoke,
invokeExport,
@@ -20,7 +23,8 @@ module Language.Wasm.Interpreter (
emptyImports,
makeHostModule,
makeMutGlobal,
makeConstGlobal
makeConstGlobal,
getMemory
) where
import qualified Data.Map as Map
@@ -1206,4 +1210,9 @@ getGlobalValueByName store ModuleInstance { exports } name =
case globalInst of
GIConst _ v -> return v
GIMut _ ref -> readIORef ref
_ -> error $ "Function with name " ++ show name ++ " was not found in module's exports"
_ -> error $ "Function with name " ++ show name ++ " was not found in module's exports"
-- | Retrieve mutable memory from the 'Store'
getMemory :: Store -> Address -> Maybe MemoryInstance
getMemory Store{memInstances} address = memInstances !? address