diff --git a/src/Language/Wasm/Interpreter.hs b/src/Language/Wasm/Interpreter.hs index 6df713e..0c56960 100644 --- a/src/Language/Wasm/Interpreter.hs +++ b/src/Language/Wasm/Interpreter.hs @@ -316,6 +316,7 @@ initialize inst Module {elems, datas, start} store = do return $ st { tableInstances = tableInstances st Vector.// [(idx, table)] } fitOrGrowMemory :: Address -> Store -> Int -> IO MemoryInstance + fitOrGrowMemory idx st 0 = return $ memInstances st ! idx fitOrGrowMemory idx st last = do let m@(MemoryInstance mem maxLen) = memInstances st ! idx let len = IOVector.length mem @@ -329,7 +330,7 @@ initialize inst Module {elems, datas, start} store = do Nothing -> increased Just max -> let maxInBytes = max * pageSize in - if maxInBytes <= last + if maxInBytes < last then error $ "Max memory length reached. Max " ++ show max ++ "(" ++ show maxInBytes ++ "b), but requested " ++ show last else increased diff --git a/tests/Test.hs b/tests/Test.hs index 6d63405..9050d50 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -34,7 +34,7 @@ compile file = do main :: IO () main = do files <- Directory.listDirectory "tests/samples" - -- let files = ["func.wast"] + -- let files = ["memory.wast"] scriptTestCases <- (`mapM` files) $ \file -> do content <- LBS.readFile $ "tests/samples/" ++ file let Right script = Parser.parseScript <$> Lexer.scanner content