@@ -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 ]))
@@ -1682,21 +1696,34 @@ let handle_exceptions ~result_typ ~fall_through ~context body x exn_handler =
16821696 x
16831697 (block_expr
16841698 { params = [] ; result = [ Value. value ] }
1685- (let * exn =
1686- block_expr
1687- { params = [] ; result = [ externref ] }
1688- (let * e =
1689- try_expr
1690- { params = [] ; result = [ externref ] }
1691- (body
1692- ~result_typ: [ externref ]
1693- ~fall_through: `Skip
1694- ~context: (`Skip :: `Skip :: `Catch :: context))
1695- [ ocaml_tag, 1 , Value. value; js_tag, 0 , externref ]
1696- in
1697- instr (W. Push e))
1698- in
1699- instr (W. CallInstr (f, [ exn ]))))
1699+ (if Config.Flag. wasi ()
1700+ then
1701+ let * e =
1702+ try_expr
1703+ { params = [] ; result = [ Value. value ] }
1704+ (body
1705+ ~result_typ: [ Value. value ]
1706+ ~fall_through: `Skip
1707+ ~context: (`Skip :: `Catch :: context))
1708+ [ ocaml_tag, 0 , Value. value ]
1709+ in
1710+ instr (W. Push e)
1711+ else
1712+ let * exn =
1713+ block_expr
1714+ { params = [] ; result = [ externref ] }
1715+ (let * e =
1716+ try_expr
1717+ { params = [] ; result = [ externref ] }
1718+ (body
1719+ ~result_typ: [ externref ]
1720+ ~fall_through: `Skip
1721+ ~context: (`Skip :: `Skip :: `Catch :: context))
1722+ [ ocaml_tag, 1 , Value. value; js_tag, 0 , externref ]
1723+ in
1724+ instr (W. Push e))
1725+ in
1726+ instr (W. CallInstr (f, [ exn ]))))
17001727 in
17011728 let * () = no_event in
17021729 exn_handler ~result_typ ~fall_through ~context )
0 commit comments