From 6b376ee4cbc83cf7516befc9eee2bc91e2d9049e Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Sun, 8 Apr 2018 17:51:04 -0700 Subject: [PATCH] fix elems validator --- src/Language/Wasm/Script.hs | 3 ++- src/Language/Wasm/Validate.hs | 3 ++- tests/Test.hs | 2 +- tests/samples/imports.wast | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Language/Wasm/Script.hs b/src/Language/Wasm/Script.hs index dcd4c8a..62d9e32 100644 --- a/src/Language/Wasm/Script.hs +++ b/src/Language/Wasm/Script.hs @@ -56,7 +56,8 @@ runScript onAssertFail script = do ("global_i32", globI32), ("global_f32", globF32), ("global_f64", globF64), - ("memory", Interpreter.HostMemory $ Struct.Limit 1 (Just 2)) + ("memory", Interpreter.HostMemory $ Struct.Limit 1 (Just 2)), + ("table", Interpreter.HostTable $ Struct.Limit 10 (Just 20)) ] go script $ emptyState { store = st, moduleRegistery = Map.singleton "spectest" inst } where diff --git a/src/Language/Wasm/Validate.hs b/src/Language/Wasm/Validate.hs index e0cdeb9..46b055c 100644 --- a/src/Language/Wasm/Validate.hs +++ b/src/Language/Wasm/Validate.hs @@ -539,7 +539,8 @@ elemsShouldBeValid m@Module { elems, functions, tables, imports } = then Valid else IndexOutOfRange in - let funsLength = fromIntegral $ length functions in + let funImports = filter isFuncImport imports in + let funsLength = fromIntegral $ length functions + length funImports in let isFunsValid = foldMap (\i -> if i < funsLength then Valid else IndexOutOfRange) funs in isIniterValid <> isFunsValid <> isTableIndexValid diff --git a/tests/Test.hs b/tests/Test.hs index 0901ae6..dd1d160 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 = ["imports.wast"] scriptTestCases <- (`mapM` files) $ \file -> do content <- LBS.readFile $ "tests/samples/" ++ file let Right script = Parser.parseScript <$> Lexer.scanner content diff --git a/tests/samples/imports.wast b/tests/samples/imports.wast index 7c17f80..3abc989 100644 --- a/tests/samples/imports.wast +++ b/tests/samples/imports.wast @@ -32,7 +32,7 @@ ;; (func (import "spectest" "print_i64") (param i64)) (import "spectest" "print_i32" (func $print_i32 (param i32))) ;; JavaScript can't handle i64 yet. - ;; (import "spectest" "print_i64" (func $print_i64 (param i64))) + (import "spectest" "print_i64" (func $print_i64 (param i64))) (import "spectest" "print_f32" (func $print_f32 (param f32))) (import "spectest" "print_f64" (func $print_f64 (param f64))) (import "spectest" "print_i32_f32" (func $print_i32_f32 (param i32 f32)))