Skip to content

Commit 3be7078

Browse files
committed
Expose mutable memory access
1 parent c8f1bc9 commit 3be7078

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Language/Wasm/Interpreter.hs

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ module Language.Wasm.Interpreter (
1010
ExternalValue(..),
1111
ExportInstance(..),
1212
GlobalInstance(..),
13+
MemoryInstance(..),
14+
MemoryStore,
1315
Imports,
14-
HostItem(..),
16+
HostItem(..),
17+
Address,
1518
instantiate,
1619
invoke,
1720
invokeExport,
@@ -20,7 +23,8 @@ module Language.Wasm.Interpreter (
2023
emptyImports,
2124
makeHostModule,
2225
makeMutGlobal,
23-
makeConstGlobal
26+
makeConstGlobal,
27+
getMemory
2428
) where
2529

2630
import qualified Data.Map as Map
@@ -1206,4 +1210,9 @@ getGlobalValueByName store ModuleInstance { exports } name =
12061210
case globalInst of
12071211
GIConst _ v -> return v
12081212
GIMut _ ref -> readIORef ref
1209-
_ -> error $ "Function with name " ++ show name ++ " was not found in module's exports"
1213+
_ -> error $ "Function with name " ++ show name ++ " was not found in module's exports"
1214+
1215+
-- | Retrieve mutable memory from the 'Store'
1216+
getMemory :: Store -> Address -> Maybe MemoryInstance
1217+
getMemory Store{memInstances} address = memInstances !? address
1218+

wasm.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: wasm
3-
version: 1.1.1
3+
version: 1.1.2
44
synopsis: WebAssembly Language Toolkit and Interpreter
55
description:
66
Library for parsing and interpreting WebAssembly, including:
@@ -64,7 +64,7 @@ library
6464
, ieee754 >=0.8 && < 0.9
6565
, mtl >=2.2.1 && < 2.3
6666
, primitive >=0.7 && < 0.8
67-
, text >=1.1 && < 1.3
67+
, text >=1.1 && < 3
6868
, transformers >=0.4 && < 0.6
6969
, utf8-string >=1.0 && < 1.1
7070
, vector >=0.12 && < 0.13

0 commit comments

Comments
 (0)