added line position for failed asserts and implemented mutable globals import/export proposal

This commit is contained in:
Ilya Rezvov
2021-03-09 22:45:16 -08:00
parent 02e2c4a705
commit 252ced4989
4 changed files with 101 additions and 69 deletions
+10 -8
View File
@@ -19,7 +19,8 @@ module Language.Wasm.Interpreter (
emptyStore,
emptyImports,
makeHostModule,
makeMutGlobal
makeMutGlobal,
makeConstGlobal
) where
import qualified Data.Map as Map
@@ -177,6 +178,9 @@ data GlobalInstance = GIConst ValueType Value | GIMut ValueType (IORef Value)
makeMutGlobal :: Value -> IO GlobalInstance
makeMutGlobal val = GIMut (getValueType val) <$> newIORef val
makeConstGlobal :: Value -> GlobalInstance
makeConstGlobal val = GIConst (getValueType val) val
getValueType :: Value -> ValueType
getValueType (VI32 _) = I32
getValueType (VI64 _) = I64
@@ -364,13 +368,11 @@ calcInstance (Store fs ts ms gs) imps Module {functions, types, tables, mems, gl
ExternGlobal globalAddr -> return globalAddr
_ -> err
let globalInst = gs ! globalAddr
let vt = case globalType of
Const vt -> vt
Mut vt -> vt
let vt' = case globalInst of
GIConst vt _ -> vt
GIMut vt _ -> vt
if vt == vt' then return idx else err
let typesMatch = case (globalType, globalInst) of
(Const vt, GIConst vt' _) -> vt == vt'
(Mut vt, GIMut vt' _) -> vt == vt'
_ -> False
if typesMatch then return idx else err
checkImportType imp@(Import _ _ (ImportMemory limit)) = do
idx <- getImpIdx imp
memAddr <- case idx of