@@ -574,9 +574,13 @@ module Value = struct
574574 return () )
575575 (val_int (if negate then Arith. eqz n else n))
576576
577- let eq x y = eq_gen ~negate: false x y
577+ let eq x y =
578+ if Config.Flag. wasi () then val_int (ref_eq x y) else eq_gen ~negate: false x y
578579
579- let neq x y = eq_gen ~negate: true x y
580+ let neq x y =
581+ if Config.Flag. wasi ()
582+ then val_int (Arith. eqz (ref_eq x y))
583+ else eq_gen ~negate: true x y
580584
581585 let ult = binop Arith. (ult)
582586
@@ -1299,7 +1303,12 @@ module Math = struct
12991303 { W. params = List. init ~len: n ~f: (fun _ : W. value_type -> F64 ); result = [ F64 ] }
13001304
13011305 let unary name x =
1302- let * f = register_import ~import_module: " Math" ~name (Fun (float_func_type 1 )) in
1306+ let * f =
1307+ register_import
1308+ ~import_module: (if Config.Flag. wasi () then " env" else " Math" )
1309+ ~name
1310+ (Fun (float_func_type 1 ))
1311+ in
13031312 let * x = x in
13041313 return (W. Call (f, [ x ]))
13051314
@@ -1342,7 +1351,12 @@ module Math = struct
13421351 let log10 f = unary " log10" f
13431352
13441353 let binary name x y =
1345- let * f = register_import ~import_module: " Math" ~name (Fun (float_func_type 2 )) in
1354+ let * f =
1355+ register_import
1356+ ~import_module: (if Config.Flag. wasi () then " env" else " Math" )
1357+ ~name
1358+ (Fun (float_func_type 2 ))
1359+ in
13461360 let * x = x in
13471361 let * y = y in
13481362 return (W. Call (f, [ x; y ]))
@@ -1681,21 +1695,34 @@ let handle_exceptions ~result_typ ~fall_through ~context body x exn_handler =
16811695 x
16821696 (block_expr
16831697 { params = [] ; result = [ Value. value ] }
1684- (let * exn =
1685- block_expr
1686- { params = [] ; result = [ externref ] }
1687- (let * e =
1688- try_expr
1689- { params = [] ; result = [ externref ] }
1690- (body
1691- ~result_typ: [ externref ]
1692- ~fall_through: `Skip
1693- ~context: (`Skip :: `Skip :: `Catch :: context))
1694- [ ocaml_tag, 1 , Value. value; js_tag, 0 , externref ]
1695- in
1696- instr (W. Push e))
1697- in
1698- instr (W. CallInstr (f, [ exn ]))))
1698+ (if Config.Flag. wasi ()
1699+ then
1700+ let * e =
1701+ try_expr
1702+ { params = [] ; result = [ Value. value ] }
1703+ (body
1704+ ~result_typ: [ Value. value ]
1705+ ~fall_through: `Skip
1706+ ~context: (`Skip :: `Catch :: context))
1707+ [ ocaml_tag, 0 , Value. value ]
1708+ in
1709+ instr (W. Push e)
1710+ else
1711+ let * exn =
1712+ block_expr
1713+ { params = [] ; result = [ externref ] }
1714+ (let * e =
1715+ try_expr
1716+ { params = [] ; result = [ externref ] }
1717+ (body
1718+ ~result_typ: [ externref ]
1719+ ~fall_through: `Skip
1720+ ~context: (`Skip :: `Skip :: `Catch :: context))
1721+ [ ocaml_tag, 1 , Value. value; js_tag, 0 , externref ]
1722+ in
1723+ instr (W. Push e))
1724+ in
1725+ instr (W. CallInstr (f, [ exn ]))))
16991726 in
17001727 let * () = no_event in
17011728 exn_handler ~result_typ ~fall_through ~context )
0 commit comments