forked from GitHub/haskell-wasm
const expression get_global can refer only imported constant globals
This commit is contained in:
@@ -116,7 +116,8 @@ data Ctx = Ctx {
|
|||||||
globals :: [GlobalType],
|
globals :: [GlobalType],
|
||||||
locals :: [ValueType],
|
locals :: [ValueType],
|
||||||
labels :: [Maybe ValueType],
|
labels :: [Maybe ValueType],
|
||||||
returns :: Maybe ValueType
|
returns :: Maybe ValueType,
|
||||||
|
importedGlobals :: Natural
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
type Checker = ReaderT Ctx (StateT Int (Except ValidationResult))
|
type Checker = ReaderT Ctx (StateT Int (Except ValidationResult))
|
||||||
@@ -409,7 +410,10 @@ isConstExpression ((I64Const _):rest) = isConstExpression rest
|
|||||||
isConstExpression ((F32Const _):rest) = isConstExpression rest
|
isConstExpression ((F32Const _):rest) = isConstExpression rest
|
||||||
isConstExpression ((F64Const _):rest) = isConstExpression rest
|
isConstExpression ((F64Const _):rest) = isConstExpression rest
|
||||||
isConstExpression ((GetGlobal idx):rest) = do
|
isConstExpression ((GetGlobal idx):rest) = do
|
||||||
Ctx {globals} <- ask
|
Ctx {globals, importedGlobals} <- ask
|
||||||
|
if importedGlobals <= idx
|
||||||
|
then throwError InvalidConstantExpr
|
||||||
|
else return ()
|
||||||
case globals !! fromIntegral idx of
|
case globals !! fromIntegral idx of
|
||||||
Const _ -> isConstExpression rest
|
Const _ -> isConstExpression rest
|
||||||
Mut _ -> throwError InvalidConstantExpr
|
Mut _ -> throwError InvalidConstantExpr
|
||||||
@@ -436,7 +440,8 @@ ctxFromModule locals labels returns m@Module {types, functions, tables, mems, gl
|
|||||||
globals = globalImports ++ map (\(Global g _) -> g) globals,
|
globals = globalImports ++ map (\(Global g _) -> g) globals,
|
||||||
locals,
|
locals,
|
||||||
labels,
|
labels,
|
||||||
returns
|
returns,
|
||||||
|
importedGlobals = fromIntegral $ length globalImports
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
getTableType (Import _ _ (ImportTable tableType)) = Just tableType
|
getTableType (Import _ _ (ImportTable tableType)) = Just tableType
|
||||||
|
|||||||
Reference in New Issue
Block a user