all tests are green

This commit is contained in:
Ilya Rezvov
2021-04-19 17:17:25 -07:00
parent 5f28711f6d
commit 54c3cfd697
3 changed files with 10 additions and 4 deletions
+6 -1
View File
@@ -7,7 +7,8 @@ module Language.Wasm.Lexer (
AlexPosn(..), AlexPosn(..),
scanner, scanner,
asFloat, asFloat,
asDouble asDouble,
doubleFromInteger
) where ) where
import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Lazy as LBS
@@ -20,6 +21,7 @@ import Data.Word (Word8, Word64)
import Data.List (isPrefixOf) import Data.List (isPrefixOf)
import Text.Read (readEither) import Text.Read (readEither)
import Data.Bits import Data.Bits
import Numeric (showHex)
} }
@@ -267,6 +269,9 @@ asDouble (NanRep (NanHex isPos payload)) =
then return $ (if isPos then id else negate) $ makeNaN payload then return $ (if isPos then id else negate) $ makeNaN payload
else Left "constant out of range" else Left "constant out of range"
doubleFromInteger :: Integer -> Either String Double
doubleFromInteger int = asDouble . HexRep . ((if int < 0 then "-0x" else "0x") ++) . flip showHex "" $ abs int
startBlockComment :: AlexAction Lexeme startBlockComment :: AlexAction Lexeme
startBlockComment _inp _len = do startBlockComment _inp _len = do
depth <- getLexerCommentDepth depth <- getLexerCommentDepth
+3 -2
View File
@@ -94,7 +94,8 @@ import Language.Wasm.Lexer (
Lexeme(..), Lexeme(..),
AlexPosn(..), AlexPosn(..),
asFloat, asFloat,
asDouble asDouble,
doubleFromInteger
) )
} }
@@ -401,7 +402,7 @@ float64 :: { Double }
: int {% : int {%
let maxInt = round (maxFinite :: Double) in let maxInt = round (maxFinite :: Double) in
if $1 <= maxInt && $1 >= -maxInt if $1 <= maxInt && $1 >= -maxInt
then return $ fromIntegral $1 then doubleFromInteger $1
else Left "constant out of range" else Left "constant out of range"
} }
| f64 {% asDouble $1 } | f64 {% asDouble $1 }
+1 -1
View File
@@ -17,7 +17,7 @@ import qualified Data.List as List
main :: IO () main :: IO ()
main = do main = do
files <- filter (List.isSuffixOf ".wast") <$> Directory.listDirectory "tests/spec" files <- filter (List.isSuffixOf ".wast") <$> Directory.listDirectory "tests/spec"
-- let files = ["conversions.wast"] -- let files = ["const.wast"]
scriptTestCases <- (`mapM` files) $ \file -> do scriptTestCases <- (`mapM` files) $ \file -> do
test <- LBS.readFile ("tests/spec/" ++ file) test <- LBS.readFile ("tests/spec/" ++ file)
return $ testCase file $ do return $ testCase file $ do