handle functions with empty body

This commit is contained in:
Ilya Rezvov
2018-02-24 21:49:06 -08:00
parent 55215f56de
commit e05bcdd0cb
3 changed files with 24 additions and 12 deletions
+22 -10
View File
@@ -296,13 +296,6 @@ EOF { Lexeme _ EOF }
%%
functype :: { FuncType }
: '(' 'func' params_results { $3 }
params_results :: { FuncType }
: ')' { FuncType [] [] }
| '(' paramsresultstypeuse ')' { $2 }
name :: { TL.Text }
: string { $1 }
@@ -538,9 +531,6 @@ plaininstr :: { PlainInstr }
| 'f32.reinterpret/i32' { FReinterpretI BS32 }
| 'f64.reinterpret/i64' { FReinterpretI BS64 }
typedef :: { TypeDef }
: 'type' opt(ident) functype ')' { TypeDef $2 $3 }
typeuse :: { TypeUse }
: '(' typeuse1 { $2 }
| {- empty -} { AnonimousTypeUse $ FuncType [] [] }
@@ -553,6 +543,28 @@ typedtypeuse :: { Maybe FuncType }
: '(' paramsresultstypeuse { Just $2 }
| {- empty -} { Nothing }
typedef :: { TypeDef }
: 'type' opt(ident) functype ')' { TypeDef $2 $3 }
functype :: { FuncType }
: '(' 'func' params_results { $3 }
params_results :: { FuncType }
: ')' { emptyFuncType }
| '(' params_results1 { $2 }
params_results1 :: { FuncType }
: 'param' list(valtype) ')' params_results { mergeFuncType (FuncType (map (ParamType Nothing) $2) []) $4 }
| 'param' ident valtype ')' params_results { mergeFuncType (FuncType [ParamType (Just $2) $3] []) $5 }
| results1 { $1 }
results :: { FuncType }
: ')' { emptyFuncType }
| '(' results1 { $2 }
results1 :: { FuncType }
: 'result' list(valtype) ')' results { mergeFuncType (FuncType [] $2) $4 }
paramsresultstypeuse :: { FuncType }
: paramsresultstypeuse '(' paramsresulttypeuse { mergeFuncType $1 $3 }
| paramsresulttypeuse { $1 }
+1 -1
View File
@@ -389,7 +389,7 @@ isFunctionValid Function {funcType, locals, body} mod@Module {types} =
let ctx = ctxFromModule (params ++ locals) [r] r mod in
case runChecker ctx $ getExpressionType body of
Left err -> err
Right arr -> if arr == (empty ==> results) then Valid else TypeMismatch
Right arr -> if arr == (empty ==> results) || arr == (Any ==> Any) then Valid else TypeMismatch
functionsShouldBeValid :: Validator
functionsShouldBeValid mod@Module {functions} =
+1 -1
View File
@@ -31,7 +31,7 @@ compile file = do
main :: IO ()
main = do
files <- Directory.listDirectory "tests/samples"
-- let files = ["endianess.wast"]
-- let files = ["func.wast"]
-- compile "fact.wast"
syntaxTestCases <- (`mapM` files) $ \file -> do
content <- LBS.readFile $ "tests/samples/" ++ file