Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

[interpreter] Fix JS generator #34

Merged
merged 5 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ^
Expand Down Expand Up @@ -83,7 +87,7 @@ let harness =
"}\n" ^
"\n" ^
"function exports(instance) {\n" ^
" return {module: instance.exports, host: {ref: hostref}};\n" ^
" return {module: instance.exports, spectest: spectest};\n" ^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated module expects an import spectest::eq_ref. Could you extend spectest above with an eq_ref field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, some tests expect that hostref(1) provide an exported wasm function, but it doesn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing eq_ref. I'm not sure I understand your other comment. Which test is this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test in ref_is_null.wast:33, hostref(1) is passed in as a valid value of funcref. However, afaict, it is not a valid value. When I change hostref(1) with $1.exports["funcref-elem"], which is a valid funcref value, the test passes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! That test actually was bogus (but the interpreter does not type-check script commands like invoke -- it probably should). I removed it.

"}\n" ^
"\n" ^
"function run(action) {\n" ^
Expand Down Expand Up @@ -327,7 +331,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) ::
Expand All @@ -347,6 +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 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 =
Expand Down
1 change: 0 additions & 1 deletion test/core/ref_is_null.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down