From 2eab69021359b8973bbc71272f57473d5b3b710b Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Sun, 11 Apr 2021 21:19:21 -0700 Subject: [PATCH] hack nan's check and handle select typings properly --- src/Language/Wasm/Script.hs | 4 ++-- src/Language/Wasm/Validate.hs | 3 +++ tests/Test.hs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Language/Wasm/Script.hs b/src/Language/Wasm/Script.hs index 4ad619b..08ced60 100644 --- a/src/Language/Wasm/Script.hs +++ b/src/Language/Wasm/Script.hs @@ -137,8 +137,8 @@ runScript onAssertFail script = do isValueEqual :: Interpreter.Value -> Interpreter.Value -> Bool isValueEqual (Interpreter.VI32 v1) (Interpreter.VI32 v2) = v1 == v2 isValueEqual (Interpreter.VI64 v1) (Interpreter.VI64 v2) = v1 == v2 - isValueEqual (Interpreter.VF32 v1) (Interpreter.VF32 v2) = identicalIEEE v1 v2 - isValueEqual (Interpreter.VF64 v1) (Interpreter.VF64 v2) = identicalIEEE v1 v2 + isValueEqual (Interpreter.VF32 v1) (Interpreter.VF32 v2) = (isNaN v1 && isNaN v2) || identicalIEEE v1 v2 + isValueEqual (Interpreter.VF64 v1) (Interpreter.VF64 v2) = (isNaN v1 && isNaN v2) || identicalIEEE v1 v2 isValueEqual _ _ = False isNaNReturned :: Action -> Assertion -> AssertM () diff --git a/src/Language/Wasm/Validate.hs b/src/Language/Wasm/Validate.hs index 6ddad39..5dfdc69 100644 --- a/src/Language/Wasm/Validate.hs +++ b/src/Language/Wasm/Validate.hs @@ -421,6 +421,9 @@ getExpressionTypeWithInput inp = fmap (inp `Arrow`) . foldM go inp matchStack (Val v:stack) (Var:args) res = let subst = replace Var (Val v) in matchStack stack (subst args) (subst res) + matchStack (Var:stack) (Val v:args) res = + let subst = replace Var (Val v) in + matchStack stack (subst args) (subst res) matchStack stack [] res = return $ res ++ stack matchStack [] args res = throwError $ TypeMismatch ((reverse args) `Arrow` res) ([] `Arrow` []) matchStack _ _ _ = error "inconsistent checker state" diff --git a/tests/Test.hs b/tests/Test.hs index bd8c60e..a71f6cc 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -17,7 +17,7 @@ import qualified Data.List as List main :: IO () main = do files <- filter (List.isSuffixOf ".wast") <$> Directory.listDirectory "tests/spec" - -- let files = ["loop.wast"] + -- let files = ["select.wast"] scriptTestCases <- (`mapM` files) $ \file -> do test <- LBS.readFile ("tests/spec/" ++ file) return $ testCase file $ do