@@ -573,9 +573,13 @@ module Value = struct
573
573
return () )
574
574
(val_int (if negate then Arith. eqz n else n))
575
575
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
577
578
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
579
583
580
584
let ult = binop Arith. (ult)
581
585
@@ -1294,7 +1298,12 @@ module Math = struct
1294
1298
{ W. params = List. init ~len: n ~f: (fun _ : W. value_type -> F64 ); result = [ F64 ] }
1295
1299
1296
1300
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
1298
1307
let * x = x in
1299
1308
return (W. Call (f, [ x ]))
1300
1309
@@ -1337,7 +1346,12 @@ module Math = struct
1337
1346
let log10 f = unary " log10" f
1338
1347
1339
1348
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
1341
1355
let * x = x in
1342
1356
let * y = y in
1343
1357
return (W. Call (f, [ x; y ]))
@@ -1682,21 +1696,34 @@ let handle_exceptions ~result_typ ~fall_through ~context body x exn_handler =
1682
1696
x
1683
1697
(block_expr
1684
1698
{ 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 ]))))
1700
1727
in
1701
1728
let * () = no_event in
1702
1729
exn_handler ~result_typ ~fall_through ~context )
0 commit comments