Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit d9ebd33

Browse files
authored
[interpreter] Fix JS generator (#34)
* Add missing eq_ref * Fix export index computation * Remove bogus test
1 parent 564fc40 commit d9ebd33

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

interpreter/script/js.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ let harness =
2121
"function is_funcref(x) {\n" ^
2222
" return typeof x === \"function\" ? 1 : 0;\n" ^
2323
"}\n" ^
24+
"function eq_ref(x, y) {\n" ^
25+
" return x === y ? 1 : 0;\n" ^
26+
"}\n" ^
2427
"\n" ^
2528
"let spectest = {\n" ^
2629
" hostref: hostref,\n" ^
2730
" is_hostref: is_hostref,\n" ^
2831
" is_funcref: is_funcref,\n" ^
32+
" eq_ref: eq_ref,\n" ^
2933
" print: console.log.bind(console),\n" ^
3034
" print_i32: console.log.bind(console),\n" ^
3135
" print_i32_f32: console.log.bind(console),\n" ^
@@ -83,7 +87,7 @@ let harness =
8387
"}\n" ^
8488
"\n" ^
8589
"function exports(instance) {\n" ^
86-
" return {module: instance.exports, host: {ref: hostref}};\n" ^
90+
" return {module: instance.exports, spectest: spectest};\n" ^
8791
"}\n" ^
8892
"\n" ^
8993
"function run(action) {\n" ^
@@ -327,7 +331,6 @@ let assert_return_func ts at =
327331
let wrap item_name wrap_action wrap_assertion at =
328332
let itypes, idesc, action = wrap_action at in
329333
let locals, assertion = wrap_assertion at in
330-
let item = Lib.List32.length itypes @@ at in
331334
let types =
332335
(FuncType ([], []) @@ at) ::
333336
(FuncType ([NumType I32Type], [RefType AnyRefType]) @@ at) ::
@@ -347,6 +350,12 @@ let wrap item_name wrap_action wrap_assertion at =
347350
{module_name = Utf8.decode "spectest"; item_name = Utf8.decode "eq_ref";
348351
idesc = FuncImport (4l @@ at) @@ at} @@ at ]
349352
in
353+
let item =
354+
List.fold_left
355+
(fun i im ->
356+
match im.it.idesc.it with FuncImport _ -> Int32.add i 1l | _ -> i
357+
) 0l imports @@ at
358+
in
350359
let edesc = FuncExport item @@ at in
351360
let exports = [{name = Utf8.decode "run"; edesc} @@ at] in
352361
let body =

test/core/ref_is_null.wast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
(assert_return (invoke "funcref" (ref.null)) (i32.const 1))
3131

3232
(assert_return (invoke "anyref" (ref.host 1)) (i32.const 0))
33-
(assert_return (invoke "funcref" (ref.host 1)) (i32.const 0))
3433

3534
(invoke "init" (ref.host 0))
3635

0 commit comments

Comments
 (0)