diff --git a/src/Language/Wasm/Interpreter.hs b/src/Language/Wasm/Interpreter.hs index 011b10a..64fd4e5 100644 --- a/src/Language/Wasm/Interpreter.hs +++ b/src/Language/Wasm/Interpreter.hs @@ -570,7 +570,7 @@ eval store FunctionInstance { funcType, moduleInstance, code = Function { localT let funInst = funcInstances store ! (funcaddrs moduleInstance ! fromIntegral fun) let ft = Language.Wasm.Interpreter.funcType funInst let args = params ft - res <- eval store funInst (zipWith checkValType args $ take (length args) $ stack ctx) + res <- eval store funInst (zipWith checkValType args $ reverse $ take (length args) $ stack ctx) return $ Done ctx { stack = reverse res ++ (drop (length args) $ stack ctx) } step ctx@EvalCtx{ stack = (VI32 v): rest } (CallIndirect typeIdx) = do let funcType = funcTypes moduleInstance ! fromIntegral typeIdx @@ -579,7 +579,7 @@ eval store FunctionInstance { funcType, moduleInstance, code = Function { localT case funcAddr of Just (Just addr) -> do let args = params funcType - res <- invoke store addr (zipWith checkValType args $ take (length args) rest) + res <- invoke store addr (zipWith checkValType args $ reverse $ take (length args) rest) return $ Done ctx { stack = reverse res ++ (drop (length args) rest) } _ -> return Trap step ctx@EvalCtx{ stack = (_:rest) } Drop = return $ Done ctx { stack = rest } diff --git a/src/Language/Wasm/Parser.y b/src/Language/Wasm/Parser.y index fe01931..0b66ca9 100644 --- a/src/Language/Wasm/Parser.y +++ b/src/Language/Wasm/Parser.y @@ -152,6 +152,8 @@ import Debug.Trace as Debug 'i64.store32' { Lexeme _ (TKeyword "i64.store32") } 'current_memory' { Lexeme _ (TKeyword "current_memory") } 'grow_memory' { Lexeme _ (TKeyword "grow_memory") } +'memory.size' { Lexeme _ (TKeyword "memory.size") } +'memory.grow' { Lexeme _ (TKeyword "memory.grow") } 'i32.const' { Lexeme _ (TKeyword "i32.const") } 'i64.const' { Lexeme _ (TKeyword "i64.const") } 'f32.const' { Lexeme _ (TKeyword "f32.const") } @@ -436,6 +438,8 @@ plaininstr :: { PlainInstr } | 'i64.store32' memarg4 { I64Store32 $2 } | 'current_memory' { CurrentMemory } | 'grow_memory' { GrowMemory } + | 'memory.size' { CurrentMemory } + | 'memory.grow' { GrowMemory } -- numeric instructions | 'i32.const' int32 { I32Const $2 } | 'i64.const' int64 { I64Const $2 } diff --git a/tests/Test.hs b/tests/Test.hs index 56a49f1..0a50cdf 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 = ["linking.wast"] + -- let files = ["call.wast"] scriptTestCases <- (`mapM` files) $ \file -> do content <- LBS.readFile $ "tests/samples/" ++ file let Right script = Parser.parseScript <$> Lexer.scanner content