From 02d176ad66aecf8be6df78435ea18757e804d7b8 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Fri, 29 Mar 2019 02:00:46 +0100 Subject: [PATCH 1/5] Fix JS generation --- interpreter/script/js.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index ee56e822..957db5cf 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -83,7 +83,7 @@ let harness = "}\n" ^ "\n" ^ "function exports(instance) {\n" ^ - " return {module: instance.exports, host: {ref: hostref}};\n" ^ + " return {module: instance.exports, spectest: spectest};\n" ^ "}\n" ^ "\n" ^ "function run(action) {\n" ^ @@ -327,7 +327,6 @@ let assert_return_func ts at = let wrap item_name wrap_action wrap_assertion at = let itypes, idesc, action = wrap_action at in let locals, assertion = wrap_assertion at in - let item = Lib.List32.length itypes @@ at in let types = (FuncType ([], []) @@ at) :: (FuncType ([NumType I32Type], [RefType AnyRefType]) @@ at) :: @@ -347,6 +346,8 @@ let wrap item_name wrap_action wrap_assertion at = {module_name = Utf8.decode "spectest"; item_name = Utf8.decode "eq_ref"; idesc = FuncImport (4l @@ at) @@ at} @@ at ] in + let idesc_is_func = match idesc.it with FuncImport _ -> 1l | _ -> 0l in + let item = Int32.add idesc_is_func (Lib.List32.length imports) @@ at in let edesc = FuncExport item @@ at in let exports = [{name = Utf8.decode "run"; edesc} @@ at] in let body = From 7d83a4b7073354301c206caf33b81620c32a7ceb Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Fri, 29 Mar 2019 13:03:56 +0100 Subject: [PATCH 2/5] Add missing eq_ref --- interpreter/script/js.ml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 957db5cf..c4f0c49b 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -21,11 +21,15 @@ let harness = "function is_funcref(x) {\n" ^ " return typeof x === \"function\" ? 1 : 0;\n" ^ "}\n" ^ + "function eq_ref(x, y) {\n" ^ + " return x === y ? 1 : 0;\n" ^ + "}\n" ^ "\n" ^ "let spectest = {\n" ^ " hostref: hostref,\n" ^ " is_hostref: is_hostref,\n" ^ " is_funcref: is_funcref,\n" ^ + " eq_ref: eq_ref,\n" ^ " print: console.log.bind(console),\n" ^ " print_i32: console.log.bind(console),\n" ^ " print_i32_f32: console.log.bind(console),\n" ^ From bbe109cd1fa743059fcc36308d4f7f0b88531d61 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Fri, 29 Mar 2019 13:32:43 +0100 Subject: [PATCH 3/5] Fix export index computation --- interpreter/script/js.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index c4f0c49b..37b680ff 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -350,8 +350,8 @@ let wrap item_name wrap_action wrap_assertion at = {module_name = Utf8.decode "spectest"; item_name = Utf8.decode "eq_ref"; idesc = FuncImport (4l @@ at) @@ at} @@ at ] in - let idesc_is_func = match idesc.it with FuncImport _ -> 1l | _ -> 0l in - let item = Int32.add idesc_is_func (Lib.List32.length imports) @@ at in + let idesc_isnt_func = match idesc.it with FuncImport _ -> 0l | _ -> 1l in + let item = Int32.sub (Lib.List32.length imports) idesc_isnt_func @@ at in let edesc = FuncExport item @@ at in let exports = [{name = Utf8.decode "run"; edesc} @@ at] in let body = From 55ec0689f87173e7ea9f5f683403059cccba6f33 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Fri, 29 Mar 2019 13:37:29 +0100 Subject: [PATCH 4/5] Less brittle index computation --- interpreter/script/js.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 37b680ff..469140c0 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -350,8 +350,12 @@ let wrap item_name wrap_action wrap_assertion at = {module_name = Utf8.decode "spectest"; item_name = Utf8.decode "eq_ref"; idesc = FuncImport (4l @@ at) @@ at} @@ at ] in - let idesc_isnt_func = match idesc.it with FuncImport _ -> 0l | _ -> 1l in - let item = Int32.sub (Lib.List32.length imports) idesc_isnt_func @@ at in + let item = + List.fold_left + (fun i im -> + match im.it.idesc.it with FuncImport _ -> Int32.add i 1l | _ -> i + ) 0l imports @@ at + in let edesc = FuncExport item @@ at in let exports = [{name = Utf8.decode "run"; edesc} @@ at] in let body = From 447d725b798612bd7a821cb021408b7f5373e798 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Sat, 30 Mar 2019 01:00:56 +0100 Subject: [PATCH 5/5] Remove bogus test --- test/core/ref_is_null.wast | 1 - 1 file changed, 1 deletion(-) diff --git a/test/core/ref_is_null.wast b/test/core/ref_is_null.wast index ca4bddba..7edc8e28 100644 --- a/test/core/ref_is_null.wast +++ b/test/core/ref_is_null.wast @@ -30,7 +30,6 @@ (assert_return (invoke "funcref" (ref.null)) (i32.const 1)) (assert_return (invoke "anyref" (ref.host 1)) (i32.const 0)) -(assert_return (invoke "funcref" (ref.host 1)) (i32.const 0)) (invoke "init" (ref.host 0))