Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): return JS null value from Expression.null #83

Merged
merged 1 commit into from Mar 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions js/expression.ml
Expand Up @@ -179,8 +179,7 @@ let tuple_extract wasm_mod tuple index =
let pop wasm_mod typ =
meth_call global##.binaryen "_BinaryenPop" [| inject wasm_mod; inject typ |]

(* TODO: Figure this out *)
let null () = Obj.magic ()
let null () = pure_js_expr "null"

let print expr =
let text = meth_call global##.binaryen "emitText" [| inject expr |] in
Expand Down
4 changes: 4 additions & 0 deletions test/test.expected
Expand Up @@ -5,6 +5,10 @@
(export "memory" (memory $0))
(func $adder (param $0 i32) (param $1 i32) (result i32)
(block $add (result i32)
(if
(i32.const 0)
(unreachable)
)
(i32.add
(select
(local.get $0)
Expand Down
5 changes: 4 additions & 1 deletion test/test.ml
Expand Up @@ -20,7 +20,10 @@ let select =

let bin = Expression.binary wasm_mod Op.add_int32 select (y ())

let add = Expression.block wasm_mod ~return_type:Type.int32 "add" [ bin ]
let add = Expression.block wasm_mod ~return_type:Type.int32 "add" [
Expression.if_ wasm_mod (Expression.const wasm_mod (Literal.int32 0l)) (Expression.unreachable wasm_mod) (Expression.null ());
bin
]

(* Create the add function *)
let adder = Function.add_function wasm_mod "adder" params results [||] add
Expand Down