@@ -573,9 +573,13 @@ module Value = struct
573573 return () )
574574 (val_int (if negate then Arith. eqz n else n))
575575
576- let eq x y = eq_gen ~negate: false x y
576+ let eq x y =
577+ if Config.Flag. wasi () then val_int (ref_eq x y) else eq_gen ~negate: false x y
577578
578- let neq x y = eq_gen ~negate: true x y
579+ let neq x y =
580+ if Config.Flag. wasi ()
581+ then val_int (Arith. eqz (ref_eq x y))
582+ else eq_gen ~negate: true x y
579583
580584 let ult = binop Arith. (ult)
581585
@@ -1294,7 +1298,12 @@ module Math = struct
12941298 { W. params = List. init ~len: n ~f: (fun _ : W. value_type -> F64 ); result = [ F64 ] }
12951299
12961300 let unary name x =
1297- let * f = register_import ~import_module: " Math" ~name (Fun (float_func_type 1 )) in
1301+ let * f =
1302+ register_import
1303+ ~import_module: (if Config.Flag. wasi () then " env" else " Math" )
1304+ ~name
1305+ (Fun (float_func_type 1 ))
1306+ in
12981307 let * x = x in
12991308 return (W. Call (f, [ x ]))
13001309
@@ -1337,7 +1346,12 @@ module Math = struct
13371346 let log10 f = unary " log10" f
13381347
13391348 let binary name x y =
1340- let * f = register_import ~import_module: " Math" ~name (Fun (float_func_type 2 )) in
1349+ let * f =
1350+ register_import
1351+ ~import_module: (if Config.Flag. wasi () then " env" else " Math" )
1352+ ~name
1353+ (Fun (float_func_type 2 ))
1354+ in
13411355 let * x = x in
13421356 let * y = y in
13431357 return (W. Call (f, [ x; y ]))
@@ -1676,21 +1690,34 @@ let handle_exceptions ~result_typ ~fall_through ~context body x exn_handler =
16761690 x
16771691 (block_expr
16781692 { params = [] ; result = [ Value. value ] }
1679- (let * exn =
1680- block_expr
1681- { params = [] ; result = [ externref ] }
1682- (let * e =
1683- try_expr
1684- { params = [] ; result = [ externref ] }
1685- (body
1686- ~result_typ: [ externref ]
1687- ~fall_through: `Skip
1688- ~context: (`Skip :: `Skip :: `Catch :: context))
1689- [ ocaml_tag, 1 , Value. value; js_tag, 0 , externref ]
1690- in
1691- instr (W. Push e))
1692- in
1693- instr (W. CallInstr (f, [ exn ]))))
1693+ (if Config.Flag. wasi ()
1694+ then
1695+ let * e =
1696+ try_expr
1697+ { params = [] ; result = [ Value. value ] }
1698+ (body
1699+ ~result_typ: [ Value. value ]
1700+ ~fall_through: `Skip
1701+ ~context: (`Skip :: `Catch :: context))
1702+ [ ocaml_tag, 0 , Value. value ]
1703+ in
1704+ instr (W. Push e)
1705+ else
1706+ let * exn =
1707+ block_expr
1708+ { params = [] ; result = [ externref ] }
1709+ (let * e =
1710+ try_expr
1711+ { params = [] ; result = [ externref ] }
1712+ (body
1713+ ~result_typ: [ externref ]
1714+ ~fall_through: `Skip
1715+ ~context: (`Skip :: `Skip :: `Catch :: context))
1716+ [ ocaml_tag, 1 , Value. value; js_tag, 0 , externref ]
1717+ in
1718+ instr (W. Push e))
1719+ in
1720+ instr (W. CallInstr (f, [ exn ]))))
16941721 in
16951722 let * () = no_event in
16961723 exn_handler ~result_typ ~fall_through ~context )
0 commit comments