forked from GitHub/haskell-wasm
report multiple start sections in text representation as parsing error
This commit is contained in:
@@ -1501,6 +1501,7 @@ constInstructionToValue _ = error "Only const instructions supported as argument
|
||||
desugarize :: [ModuleField] -> Either String S.Module
|
||||
desugarize fields = do
|
||||
checkImportsOrder fields
|
||||
checkStartCount fields
|
||||
let mod = Module {
|
||||
types = reverse $ foldl' extractTypeDef (reverse $ explicitTypeDefs fields) fields,
|
||||
functions = extract extractFunction fields,
|
||||
@@ -1562,6 +1563,15 @@ desugarize fields = do
|
||||
checkDef _ (MFMem _) = return True
|
||||
checkDef _ (MFTable _) = return True
|
||||
checkDef nonImportOccured _ = return nonImportOccured
|
||||
|
||||
checkStartCount :: [ModuleField] -> Either String ()
|
||||
checkStartCount fields = foldM checkDef False fields >> return ()
|
||||
where
|
||||
checkDef startOccured (MFStart _) =
|
||||
if startOccured
|
||||
then Left "Multiple start sections"
|
||||
else Right True
|
||||
checkDef startOccured _ = return startOccured
|
||||
|
||||
extractTypeDef :: [TypeDef] -> ModuleField -> [TypeDef]
|
||||
extractTypeDef defs (MFType _) = defs -- should be extracted before implicit defs
|
||||
|
||||
+1
-1
@@ -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 = ["linking.wast"]
|
||||
-- let files = ["start.wast"]
|
||||
scriptTestCases <- (`mapM` files) $ \file -> do
|
||||
test <- LBS.readFile ("tests/spec/" ++ file)
|
||||
return $ testCase file $ do
|
||||
|
||||
Reference in New Issue
Block a user