@grain/binaryen.ml 0.35.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. binaryen-archive/CHANGELOG.md +31 -0
  2. binaryen-archive/binaryen.opam +3 -3
  3. binaryen-archive/esy.lock/index.json +339 -462
  4. binaryen-archive/esy.lock/opam/base.v0.17.3/opam +1 -1
  5. binaryen-archive/esy.lock/opam/{chrome-trace.3.21.1 → chrome-trace.3.24.2}/opam +6 -8
  6. binaryen-archive/esy.lock/opam/{cmdliner.1.3.0 → cmdliner.2.1.1}/opam +26 -10
  7. binaryen-archive/esy.lock/opam/{dune-build-info.3.21.1 → dune-build-info.3.24.2}/opam +6 -8
  8. binaryen-archive/esy.lock/opam/{dune-configurator.3.21.1 → dune-configurator.3.24.2}/opam +6 -8
  9. binaryen-archive/esy.lock/opam/{dune-rpc.3.21.1 → dune-rpc.3.20.2}/opam +5 -5
  10. binaryen-archive/esy.lock/opam/{dune.3.21.1 → dune.3.24.2}/opam +13 -9
  11. binaryen-archive/esy.lock/opam/{dyn.3.21.1 → dyn.3.20.2}/opam +6 -6
  12. binaryen-archive/esy.lock/opam/fix.20250919/opam +1 -0
  13. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.6.4.1/opam +67 -0
  14. binaryen-archive/esy.lock/opam/ocaml-lsp-server.1.23.1/opam +2 -2
  15. binaryen-archive/esy.lock/opam/{ocaml-version.4.0.3 → ocaml-version.4.1.3}/opam +3 -3
  16. binaryen-archive/esy.lock/opam/{ocaml_intrinsics_kernel.v0.17.1 → ocaml_intrinsics_kernel.v0.17.2}/opam +3 -5
  17. binaryen-archive/esy.lock/opam/ocamlbuild.0.16.1/opam +1 -0
  18. binaryen-archive/esy.lock/opam/{ocamlc-loc.3.21.1 → ocamlc-loc.3.20.2}/opam +6 -6
  19. binaryen-archive/esy.lock/opam/ocamlfind.1.9.8/opam +2 -1
  20. binaryen-archive/esy.lock/opam/{ocamlformat-lib.0.27.0 → ocamlformat-lib.0.29.0}/opam +7 -6
  21. binaryen-archive/esy.lock/opam/{ocamlformat-rpc-lib.0.28.1 → ocamlformat-rpc-lib.0.29.0}/opam +4 -4
  22. binaryen-archive/esy.lock/opam/{ocamlformat.0.27.0 → ocamlformat.0.29.0}/opam +6 -5
  23. binaryen-archive/esy.lock/opam/{ocp-indent.1.7.0 → ocp-indent.1.9.0}/opam +10 -9
  24. binaryen-archive/esy.lock/opam/{ordering.3.21.1 → ordering.3.20.2}/opam +6 -6
  25. binaryen-archive/esy.lock/opam/{ppxlib.0.37.0 → ppxlib.0.39.0~5.6preview}/opam +12 -13
  26. binaryen-archive/esy.lock/opam/{stdune.3.21.1 → stdune.3.20.2}/opam +7 -9
  27. binaryen-archive/esy.lock/opam/{xdg.3.21.1 → xdg.3.24.2}/opam +6 -8
  28. binaryen-archive/package.json +9 -5
  29. binaryen-archive/src/dune +4 -1
  30. binaryen-archive/src/expression.c +345 -0
  31. binaryen-archive/src/expression.js +243 -11
  32. binaryen-archive/src/expression.ml +106 -0
  33. binaryen-archive/src/expression.mli +72 -0
  34. binaryen-archive/src/heap_type.c +19 -0
  35. binaryen-archive/src/heap_type.js +12 -0
  36. binaryen-archive/src/heap_type.ml +10 -1
  37. binaryen-archive/src/heap_type.mli +8 -1
  38. binaryen-archive/src/memory.c +6 -1
  39. binaryen-archive/src/memory.js +2 -2
  40. binaryen-archive/src/memory.ml +1 -1
  41. binaryen-archive/src/memory.mli +1 -1
  42. binaryen-archive/src/module.js +7 -20
  43. binaryen-archive/src/module.ml +9 -0
  44. binaryen-archive/src/module.mli +2 -0
  45. binaryen-archive/src/module_feature.c +12 -0
  46. binaryen-archive/src/module_feature.js +12 -0
  47. binaryen-archive/src/ocaml_helpers.c +9 -0
  48. binaryen-archive/src/ocaml_helpers.h +5 -0
  49. binaryen-archive/src/ocaml_helpers.js +11 -0
  50. binaryen-archive/src/passes.ml +13 -4
  51. binaryen-archive/src/passes.mli +14 -5
  52. binaryen-archive/src/type.c +5 -3
  53. binaryen-archive/src/type.js +2 -3
  54. binaryen-archive/src/type.ml +4 -1
  55. binaryen-archive/src/type.mli +1 -1
  56. binaryen-archive/src/type_builder.c +180 -0
  57. binaryen-archive/src/type_builder.js +116 -0
  58. binaryen-archive/src/type_builder.ml +67 -0
  59. binaryen-archive/src/type_builder.mli +28 -0
  60. binaryen-archive/test/test.expected +188 -25
  61. binaryen-archive/test/test.ml +131 -4
  62. binaryen-archive/esy.lock/opam/base-bytes.base/opam +0 -10
  63. binaryen-archive/esy.lock/opam/fs-io.3.21.1/opam +0 -41
  64. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.6.2.0/opam +0 -56
  65. binaryen-archive/esy.lock/opam/stdlib-shims.0.3.0/opam +0 -31
  66. binaryen-archive/esy.lock/opam/top-closure.3.21.1/opam +0 -40
@@ -101,6 +101,28 @@ function caml_binaryen_call_indirect__bytecode() {
101
101
  );
102
102
  }
103
103
 
104
+ //Provides: caml_binaryen_call_ref
105
+ //Requires: caml_jsstring_of_string
106
+ //Requires: caml_list_to_js_array
107
+ function caml_binaryen_call_ref(wasm_mod, target, params, typ) {
108
+ return wasm_mod.call_ref(
109
+ target,
110
+ caml_list_to_js_array(params),
111
+ typ
112
+ );
113
+ }
114
+
115
+ //Provides: caml_binaryen_return_call_ref
116
+ //Requires: caml_jsstring_of_string
117
+ //Requires: caml_list_to_js_array
118
+ function caml_binaryen_return_call_ref(wasm_mod, target, params, typ) {
119
+ return wasm_mod.return_call_ref(
120
+ target,
121
+ caml_list_to_js_array(params),
122
+ typ
123
+ );
124
+ }
125
+
104
126
  //Provides: caml_binaryen_return_call
105
127
  //Requires: caml_jsstring_of_string
106
128
  //Requires: caml_list_to_js_array
@@ -367,8 +389,7 @@ function caml_binaryen_const(wasm_mod, lit) {
367
389
 
368
390
  if (lit.type === "int64") {
369
391
  return wasm_mod.i64.const(
370
- caml_int64_lo32(lit.value),
371
- caml_int64_hi32(lit.value)
392
+ (BigInt(caml_int64_hi32(lit.value)) << 32n) | BigInt(caml_int64_lo32(lit.value) >>> 0)
372
393
  );
373
394
  }
374
395
 
@@ -382,8 +403,7 @@ function caml_binaryen_const(wasm_mod, lit) {
382
403
 
383
404
  if (lit.type === "float64_bits") {
384
405
  return wasm_mod.f64.const_bits(
385
- caml_int64_lo32(lit.value),
386
- caml_int64_hi32(lit.value)
406
+ (BigInt(caml_int64_hi32(lit.value)) << 32n) | BigInt(caml_int64_lo32(lit.value) >>> 0)
387
407
  );
388
408
  }
389
409
 
@@ -547,6 +567,32 @@ function caml_binaryen_ref_i31(wasm_mod, typ) {
547
567
  return wasm_mod.ref.i31(typ);
548
568
  }
549
569
 
570
+ //Provides: caml_binaryen_ref_test
571
+ function caml_binaryen_ref_test(wasm_mod, ref, typ) {
572
+ return wasm_mod.ref.test(ref, typ);
573
+ }
574
+
575
+ //Provides: caml_binaryen_ref_cast
576
+ function caml_binaryen_ref_cast(wasm_mod, ref, typ) {
577
+ return wasm_mod.ref.cast(ref, typ);
578
+ }
579
+
580
+ //Provides: caml_binaryen_br_on
581
+ //Requires: caml_jsstring_of_string
582
+ //Requires: Binaryen
583
+ function caml_binaryen_br_on(wasm_mod, op, name, ref, typ) {
584
+ switch (op) {
585
+ case Binaryen.BrOnNull:
586
+ return wasm_mod.br_on_null(caml_jsstring_of_string(name), ref);
587
+ case Binaryen.BrOnNonNull:
588
+ return wasm_mod.br_on_non_null(caml_jsstring_of_string(name), ref);
589
+ case Binaryen.BrOnCast:
590
+ return wasm_mod.br_on_cast(caml_jsstring_of_string(name), ref, typ);
591
+ case Binaryen.BrOnCastFail:
592
+ return wasm_mod.br_on_cast_fail(caml_jsstring_of_string(name), ref, typ);
593
+ }
594
+ }
595
+
550
596
  //Provides: caml_binaryen_i31_get
551
597
  function caml_binaryen_i31_get(wasm_mod, typ, signed) {
552
598
  if (signed) {
@@ -882,14 +928,10 @@ function caml_binaryen_expression_id_array_len() {
882
928
 
883
929
  //Provides: caml_binaryen_expression_print
884
930
  //Requires: Binaryen
885
- //Requires: caml_sys_fds
886
- //Requires: caml_string_of_jsstring
887
- //Requires: caml_ml_output, caml_ml_string_length
931
+ //Requires: caml_ml_output_str_stdout
888
932
  function caml_binaryen_expression_print(expr) {
889
933
  var text = Binaryen.emitText(expr);
890
- var chanid = caml_sys_fds[1].chanid; // stdout
891
- var s = caml_string_of_jsstring(text);
892
- caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
934
+ caml_ml_output_str_stdout(text);
893
935
  }
894
936
 
895
937
  //Provides: caml_binaryen_expression_finalize
@@ -1296,6 +1338,68 @@ function caml_binaryen_call_indirect_set_return(exp, isReturn) {
1296
1338
  return Binaryen.CallIndirect.setReturn(exp, caml_js_from_bool(isReturn));
1297
1339
  }
1298
1340
 
1341
+ //Provides: caml_binaryen_call_ref_get_target
1342
+ //Requires: Binaryen
1343
+ function caml_binaryen_call_ref_get_target(exp) {
1344
+ return Binaryen.CallRef.getTarget(exp);
1345
+ }
1346
+
1347
+ //Provides: caml_binaryen_call_ref_set_target
1348
+ //Requires: Binaryen
1349
+ function caml_binaryen_call_ref_set_target(exp, target) {
1350
+ return Binaryen.CallRef.setTarget(exp, target);
1351
+ }
1352
+
1353
+ //Provides: caml_binaryen_call_ref_get_num_operands
1354
+ //Requires: Binaryen
1355
+ function caml_binaryen_call_ref_get_num_operands(exp) {
1356
+ return Binaryen.CallRef.getNumOperands(exp);
1357
+ }
1358
+
1359
+ //Provides: caml_binaryen_call_ref_get_operand_at
1360
+ //Requires: Binaryen
1361
+ function caml_binaryen_call_ref_get_operand_at(exp, index) {
1362
+ return Binaryen.CallRef.getOperandAt(exp, index);
1363
+ }
1364
+
1365
+ //Provides: caml_binaryen_call_ref_set_operand_at
1366
+ //Requires: Binaryen
1367
+ function caml_binaryen_call_ref_set_operand_at(exp, index, operand) {
1368
+ return Binaryen.CallRef.setOperandAt(exp, index, operand);
1369
+ }
1370
+
1371
+ //Provides: caml_binaryen_call_ref_append_operand
1372
+ //Requires: Binaryen
1373
+ function caml_binaryen_call_ref_append_operand(exp, operand) {
1374
+ return Binaryen.CallRef.appendOperand(exp, operand);
1375
+ }
1376
+
1377
+ //Provides: caml_binaryen_call_ref_insert_operand_at
1378
+ //Requires: Binaryen
1379
+ function caml_binaryen_call_ref_insert_operand_at(exp, index, operand) {
1380
+ return Binaryen.CallRef.insertOperandAt(exp, index, operand);
1381
+ }
1382
+
1383
+ //Provides: caml_binaryen_call_ref_remove_operand_at
1384
+ //Requires: Binaryen
1385
+ function caml_binaryen_call_ref_remove_operand_at(exp, index) {
1386
+ return Binaryen.CallRef.removeOperandAt(exp, index);
1387
+ }
1388
+
1389
+ //Provides: caml_binaryen_call_ref_is_return
1390
+ //Requires: Binaryen
1391
+ //Requires: caml_js_to_bool
1392
+ function caml_binaryen_call_ref_is_return(exp) {
1393
+ return caml_js_to_bool(Binaryen.CallRef.isReturn(exp));
1394
+ }
1395
+
1396
+ //Provides: caml_binaryen_call_ref_set_return
1397
+ //Requires: Binaryen
1398
+ //Requires: caml_js_from_bool
1399
+ function caml_binaryen_call_ref_set_return(exp, isReturn) {
1400
+ return Binaryen.CallRef.setReturn(exp, caml_js_from_bool(isReturn));
1401
+ }
1402
+
1299
1403
  //Provides: caml_binaryen_local_set_get_value
1300
1404
  //Requires: Binaryen
1301
1405
  function caml_binaryen_local_set_get_value(exp) {
@@ -1704,7 +1808,135 @@ function caml_binaryen_ref_func(wasm_mod, name, typ) {
1704
1808
 
1705
1809
  //Provides: caml_binaryen_ref_eq
1706
1810
  function caml_binaryen_ref_eq(wasm_mod, left, right) {
1707
- return wasm_mod.ref.func(left, right);
1811
+ return wasm_mod.ref.eq(left, right);
1812
+ }
1813
+
1814
+ // Struct operations
1815
+
1816
+ //Provides: caml_binaryen_struct_new
1817
+ //Requires: caml_list_to_js_array
1818
+ function caml_binaryen_struct_new(wasm_mod, operands, type) {
1819
+ return wasm_mod.struct.new(
1820
+ operands ? caml_list_to_js_array(operands[1]) : null,
1821
+ type
1822
+ );
1823
+ }
1824
+
1825
+ //Provides: caml_binaryen_struct_get
1826
+ //Requires: caml_js_from_bool
1827
+ function caml_binaryen_struct_get(wasm_mod, index, ref, type, signed) {
1828
+ return wasm_mod.struct.get(index, ref, type, caml_js_from_bool(signed));
1829
+ }
1830
+
1831
+ //Provides: caml_binaryen_struct_set
1832
+ function caml_binaryen_struct_set(wasm_mod, index, ref, value) {
1833
+ return wasm_mod.struct.set(index, ref, value);
1834
+ }
1835
+
1836
+ // Array operations
1837
+
1838
+ //Provides: caml_binaryen_array_new
1839
+ function caml_binaryen_array_new(wasm_mod, type, size, init) {
1840
+ return wasm_mod.array.new(type, size, init);
1841
+ }
1842
+
1843
+ //Provides: caml_binaryen_array_new_data
1844
+ //Requires: caml_jsstring_of_string
1845
+ function caml_binaryen_array_new_data(wasm_mod, type, name, offset, size) {
1846
+ return wasm_mod.array.new_data(
1847
+ type,
1848
+ caml_jsstring_of_string(name),
1849
+ offset,
1850
+ size
1851
+ );
1852
+ }
1853
+
1854
+ //Provides: caml_binaryen_array_new_elem
1855
+ //Requires: caml_jsstring_of_string
1856
+ function caml_binaryen_array_new_elem(wasm_mod, type, name, offset, size) {
1857
+ return wasm_mod.array.new_elem(
1858
+ type,
1859
+ caml_jsstring_of_string(name),
1860
+ offset,
1861
+ size
1862
+ );
1863
+ }
1864
+
1865
+ //Provides: caml_binaryen_array_new_fixed
1866
+ //Requires: caml_list_to_js_array
1867
+ function caml_binaryen_array_new_fixed(wasm_mod, type, values) {
1868
+ return wasm_mod.array.new_fixed(type, caml_list_to_js_array(values));
1869
+ }
1870
+
1871
+ //Provides: caml_binaryen_array_get
1872
+ //Requires: caml_js_from_bool
1873
+ function caml_binaryen_array_get(wasm_mod, ref, index, type, signed) {
1874
+ return wasm_mod.array.get(ref, index, type, caml_js_from_bool(signed));
1875
+ }
1876
+
1877
+ //Provides: caml_binaryen_array_set
1878
+ function caml_binaryen_array_set(wasm_mod, ref, index, value) {
1879
+ return wasm_mod.array.set(ref, index, value);
1880
+ }
1881
+
1882
+ //Provides: caml_binaryen_array_len
1883
+ function caml_binaryen_array_len(wasm_mod, ref) {
1884
+ return wasm_mod.array.len(ref);
1885
+ }
1886
+
1887
+ //Provides: caml_binaryen_array_fill
1888
+ function caml_binaryen_array_fill(wasm_mod, ref, index, value, size) {
1889
+ return wasm_mod.array.fill(ref, index, value, size);
1890
+ }
1891
+
1892
+ //Provides: caml_binaryen_array_copy
1893
+ function caml_binaryen_array_copy(
1894
+ wasm_mod,
1895
+ destRef,
1896
+ destIndex,
1897
+ srcRef,
1898
+ srcIndex,
1899
+ length
1900
+ ) {
1901
+ return wasm_mod.array.copy(destRef, destIndex, srcRef, srcIndex, length);
1902
+ }
1903
+
1904
+ //Provides: caml_binaryen_array_init_data
1905
+ //Requires: caml_jsstring_of_string
1906
+ function caml_binaryen_array_init_data(wasm_mod, name, ref, index, offset, size) {
1907
+ return wasm_mod.array.init_data(caml_jsstring_of_string(name), ref, index, offset, size);
1908
+ }
1909
+
1910
+ //Provides: caml_binaryen_array_init_data__bytecode
1911
+ //Requires: caml_binaryen_array_init_data
1912
+ function caml_binaryen_array_init_data__bytecode() {
1913
+ return caml_binaryen_array_init_data(
1914
+ arguments[0],
1915
+ arguments[1],
1916
+ arguments[2],
1917
+ arguments[3],
1918
+ arguments[4],
1919
+ arguments[5]
1920
+ );
1921
+ }
1922
+
1923
+ //Provides: caml_binaryen_array_init_elem
1924
+ //Requires: caml_jsstring_of_string
1925
+ function caml_binaryen_array_init_elem(wasm_mod, name, ref, index, offset, size) {
1926
+ return wasm_mod.array.init_elem(caml_jsstring_of_string(name), ref, index, offset, size);
1927
+ }
1928
+
1929
+ //Provides: caml_binaryen_array_copy__bytecode
1930
+ //Requires: caml_binaryen_array_copy
1931
+ function caml_binaryen_array_copy__bytecode() {
1932
+ return caml_binaryen_array_copy(
1933
+ arguments[0],
1934
+ arguments[1],
1935
+ arguments[2],
1936
+ arguments[3],
1937
+ arguments[4],
1938
+ arguments[5]
1939
+ );
1708
1940
  }
1709
1941
 
1710
1942
  // Exception handling operations
@@ -583,6 +583,44 @@ module Call_indirect = struct
583
583
  = "caml_binaryen_call_indirect_set_return"
584
584
  end
585
585
 
586
+ module Call_ref = struct
587
+ external make : Module.t -> t -> t list -> Type.t -> t
588
+ = "caml_binaryen_call_ref"
589
+
590
+ (** Module, function value, params, type. *)
591
+ let make mod_ target params typ = make mod_ target params typ
592
+
593
+ external make_return : Module.t -> t -> t list -> Type.t -> t
594
+ = "caml_binaryen_return_call_ref"
595
+
596
+ (** Module, function value, params, type. *)
597
+ let make_return mod_ target params typ = make_return mod_ target params typ
598
+
599
+ external get_target : t -> t = "caml_binaryen_call_ref_get_target"
600
+ external set_target : t -> t -> unit = "caml_binaryen_call_ref_set_target"
601
+
602
+ external get_num_operands : t -> int
603
+ = "caml_binaryen_call_ref_get_num_operands"
604
+
605
+ external get_operand_at : t -> int -> t
606
+ = "caml_binaryen_call_ref_get_operand_at"
607
+
608
+ external set_operand_at : t -> int -> t -> unit
609
+ = "caml_binaryen_call_ref_set_operand_at"
610
+
611
+ external append_operand : t -> t -> int
612
+ = "caml_binaryen_call_ref_append_operand"
613
+
614
+ external insert_operand_at : t -> int -> t -> unit
615
+ = "caml_binaryen_call_ref_insert_operand_at"
616
+
617
+ external remove_operand_at : t -> int -> t
618
+ = "caml_binaryen_call_ref_remove_operand_at"
619
+
620
+ external is_return : t -> bool = "caml_binaryen_call_ref_is_return"
621
+ external set_return : t -> bool -> unit = "caml_binaryen_call_ref_set_return"
622
+ end
623
+
586
624
  module Local_get = struct
587
625
  external make : Module.t -> int -> Type.t -> t = "caml_binaryen_local_get"
588
626
  (** Module, slot, type. *)
@@ -830,6 +868,74 @@ module Ref = struct
830
868
 
831
869
  external eq : Module.t -> t -> t -> t = "caml_binaryen_ref_eq"
832
870
  (** Module, left, right *)
871
+
872
+ external test : Module.t -> t -> Type.t -> t = "caml_binaryen_ref_test"
873
+ (** Module, value, type *)
874
+
875
+ external cast : Module.t -> t -> Type.t -> t = "caml_binaryen_ref_cast"
876
+ (** Module, value, type *)
877
+ end
878
+
879
+ module BrOn = struct
880
+ external make : Module.t -> Op.t -> string -> t -> Type.t -> t
881
+ = "caml_binaryen_br_on"
882
+ (** Module, op, label, value, type *)
883
+ end
884
+
885
+ module Struct = struct
886
+ external new_ : Module.t -> t list option -> Heap_type.t -> t
887
+ = "caml_binaryen_struct_new"
888
+ (** Mdoule, operands, type *)
889
+
890
+ external get : Module.t -> int -> t -> Type.t -> bool -> t
891
+ = "caml_binaryen_struct_get"
892
+ (** Module, index, struct, type, signed *)
893
+
894
+ external set : Module.t -> int -> t -> t -> t = "caml_binaryen_struct_set"
895
+ (** Module, index, struct, value *)
896
+ end
897
+
898
+ module Array = struct
899
+ external new_ : Module.t -> Heap_type.t -> t -> t -> t
900
+ = "caml_binaryen_array_new"
901
+ (** Module, type, size, init *)
902
+
903
+ external new_data : Module.t -> Heap_type.t -> string -> t -> t -> t
904
+ = "caml_binaryen_array_new_data"
905
+ (** Module, type, data name, offset, size *)
906
+
907
+ external new_elem : Module.t -> Heap_type.t -> string -> t -> t -> t
908
+ = "caml_binaryen_array_new_elem"
909
+ (** Module, type, seg, offset, size *)
910
+
911
+ external new_fixed : Module.t -> Heap_type.t -> t list -> t
912
+ = "caml_binaryen_array_new_fixed"
913
+ (** Module, type, values *)
914
+
915
+ external get : Module.t -> t -> t -> Type.t -> bool -> t
916
+ = "caml_binaryen_array_get"
917
+ (** Module, array, index, type, signed *)
918
+
919
+ external set : Module.t -> t -> t -> t -> t = "caml_binaryen_array_set"
920
+ (** Module, array, index, value *)
921
+
922
+ external len : Module.t -> t -> t = "caml_binaryen_array_len"
923
+ (** Module, array *)
924
+
925
+ external fill : Module.t -> t -> t -> t -> t -> t = "caml_binaryen_array_fill"
926
+ (** Module, array, index, value, offset *)
927
+
928
+ external copy : Module.t -> t -> t -> t -> t -> t -> t
929
+ = "caml_binaryen_array_copy__bytecode" "caml_binaryen_array_copy"
930
+ (** Module, dest, dest index, src, src index, length *)
931
+
932
+ external init_data : Module.t -> string -> t -> t -> t -> t -> t
933
+ = "caml_binaryen_array_init_data__bytecode" "caml_binaryen_array_init_data"
934
+ (** Module, name, ref, index, offset, size *)
935
+
936
+ external init_elem : Module.t -> string -> t -> t -> t -> t -> t
937
+ = "caml_binaryen_array_init_elem__bytecode" "caml_binaryen_array_init_elem"
938
+ (** Module, seg, ref, index, offset, size *)
833
939
  end
834
940
 
835
941
  (** Bindings for `try_table` instruction. *)
@@ -161,6 +161,21 @@ module Call_indirect : sig
161
161
  val set_return : t -> bool -> unit
162
162
  end
163
163
 
164
+ module Call_ref : sig
165
+ val make : Module.t -> t -> t list -> Type.t -> t
166
+ val make_return : Module.t -> t -> t list -> Type.t -> t
167
+ val get_target : t -> t
168
+ val set_target : t -> t -> unit
169
+ val get_num_operands : t -> int
170
+ val get_operand_at : t -> int -> t
171
+ val set_operand_at : t -> int -> t -> unit
172
+ val append_operand : t -> t -> int
173
+ val insert_operand_at : t -> int -> t -> unit
174
+ val remove_operand_at : t -> int -> t
175
+ val is_return : t -> bool
176
+ val set_return : t -> bool -> unit
177
+ end
178
+
164
179
  module Local_get : sig
165
180
  val make : Module.t -> int -> Type.t -> t
166
181
  end
@@ -348,6 +363,63 @@ module Ref : sig
348
363
 
349
364
  val eq : Module.t -> t -> t -> t
350
365
  (** Module, left, right *)
366
+
367
+ val test : Module.t -> t -> Type.t -> t
368
+ (** Module, value, type *)
369
+
370
+ val cast : Module.t -> t -> Type.t -> t
371
+ (** Module, value, type *)
372
+ end
373
+
374
+ module BrOn : sig
375
+ val make : Module.t -> Op.t -> string -> t -> Type.t -> t
376
+ (** Module, op, label, value, type *)
377
+ end
378
+
379
+ module Struct : sig
380
+ val new_ : Module.t -> t list option -> Heap_type.t -> t
381
+ (** Mdoule, operands, type *)
382
+
383
+ val get : Module.t -> int -> t -> Type.t -> bool -> t
384
+ (** Module, index, struct, type, signed *)
385
+
386
+ val set : Module.t -> int -> t -> t -> t
387
+ (** Module, index, struct, value *)
388
+ end
389
+
390
+ module Array : sig
391
+ val new_ : Module.t -> Heap_type.t -> t -> t -> t
392
+ (** Module, type, size, init *)
393
+
394
+ val new_data : Module.t -> Heap_type.t -> string -> t -> t -> t
395
+ (** Module, type, data name, offset, size *)
396
+
397
+ val new_elem : Module.t -> Heap_type.t -> string -> t -> t -> t
398
+ (** Module, type, seg, offset, size *)
399
+
400
+ val new_fixed : Module.t -> Heap_type.t -> t list -> t
401
+ (** Module, type, values *)
402
+
403
+ val get : Module.t -> t -> t -> Type.t -> bool -> t
404
+ (** Module, array, index, type, signed *)
405
+
406
+ val set : Module.t -> t -> t -> t -> t
407
+ (** Module, array, index, value *)
408
+
409
+ val len : Module.t -> t -> t
410
+ (** Module, array *)
411
+
412
+ val fill : Module.t -> t -> t -> t -> t -> t
413
+ (** Module, array, index, value, offset *)
414
+
415
+ val copy : Module.t -> t -> t -> t -> t -> t -> t
416
+ (** Module, dest, dest index, src, src index, length *)
417
+
418
+ val init_data : Module.t -> string -> t -> t -> t -> t -> t
419
+ (** Module, name, ref, index, offset, size *)
420
+
421
+ val init_elem : Module.t -> string -> t -> t -> t -> t -> t
422
+ (** Module, seg, ref, index, offset, size *)
351
423
  end
352
424
 
353
425
  (** Bindings for `try` instruction. *)
@@ -148,3 +148,22 @@ caml_binaryen_type_get_heap_type(value _ty) {
148
148
  BinaryenHeapType heapTy = BinaryenTypeGetHeapType(ty);
149
149
  CAMLreturn(alloc_BinaryenHeapType(heapTy));
150
150
  }
151
+
152
+ CAMLprim value caml_binaryen_module_set_type_name(value _module, value _heapType, value _name) {
153
+ CAMLparam3(_module, _heapType, _name);
154
+ BinaryenModuleRef module = BinaryenModuleRef_val(_module);
155
+ BinaryenHeapType heapType = BinaryenHeapType_val(_heapType);
156
+ const char* name = String_val(_name);
157
+ BinaryenModuleSetTypeName(module, heapType, name);
158
+ CAMLreturn(Val_unit);
159
+ }
160
+
161
+ CAMLprim value caml_binaryen_module_set_field_name(value _module, value _heapType, value _index, value _name) {
162
+ CAMLparam4(_module, _heapType, _index, _name);
163
+ BinaryenModuleRef module = BinaryenModuleRef_val(_module);
164
+ BinaryenHeapType heapType = BinaryenHeapType_val(_heapType);
165
+ BinaryenIndex index = Int_val(_index);
166
+ const char* name = String_val(_name);
167
+ BinaryenModuleSetFieldName(module, heapType, index, name);
168
+ CAMLreturn(Val_unit);
169
+ }
@@ -111,3 +111,15 @@ function caml_binaryen_heap_type_is_sub_type(left, right) {
111
111
  function caml_binaryen_type_get_heap_type(typ) {
112
112
  return Binaryen._BinaryenTypeGetHeapType(typ);
113
113
  }
114
+
115
+ //Provides: caml_binaryen_module_set_type_name
116
+ //Requires: caml_jsstring_of_string
117
+ function caml_binaryen_module_set_type_name(wasm_mod, heapType, name) {
118
+ wasm_mod.setTypeName(heapType, caml_jsstring_of_string(name));
119
+ }
120
+
121
+ //Provides: caml_binaryen_module_set_field_name
122
+ //Requires: caml_jsstring_of_string
123
+ function caml_binaryen_module_set_field_name(wasm_mod, heapType, index, name) {
124
+ wasm_mod.setFieldName(heapType, index, caml_jsstring_of_string(name));
125
+ }
@@ -17,4 +17,13 @@ external is_struct : t -> bool = "caml_binaryen_heap_type_is_struct"
17
17
  external is_array : t -> bool = "caml_binaryen_heap_type_is_array"
18
18
  external is_bottom : t -> bool = "caml_binaryen_heap_type_is_bottom"
19
19
  external get_bottom : t -> t = "caml_binaryen_heap_type_get_bottom"
20
- external is_sub_type : t -> bool = "caml_binaryen_heap_type_is_sub_type"
20
+ external is_sub_type : t -> t -> bool = "caml_binaryen_heap_type_is_sub_type"
21
+
22
+ external set_type_name : Module.t -> t -> string -> unit
23
+ = "caml_binaryen_module_set_type_name"
24
+ (** Sets the textual name of a compound `heapType`. Has no effect if the type
25
+ already has a canonical name. *)
26
+
27
+ external set_field_name : Module.t -> t -> int -> string -> unit
28
+ = "caml_binaryen_module_set_field_name"
29
+ (** Sets the field name of a struct `heapType` at index `index`. *)
@@ -17,4 +17,11 @@ val is_struct : t -> bool
17
17
  val is_array : t -> bool
18
18
  val is_bottom : t -> bool
19
19
  val get_bottom : t -> t
20
- val is_sub_type : t -> bool
20
+ val is_sub_type : t -> t -> bool
21
+
22
+ val set_type_name : Module.t -> t -> string -> unit
23
+ (** Sets the textual name of a compound `heapType`. Has no effect if the type
24
+ already has a canonical name. *)
25
+
26
+ val set_field_name : Module.t -> t -> int -> string -> unit
27
+ (** Sets the field name of a struct `heapType` at index `index`. *)
@@ -121,7 +121,12 @@ caml_binaryen_get_memory_segment_byte_offset(value _module, value _name) {
121
121
  CAMLparam2(_module, _name);
122
122
  BinaryenModuleRef module = BinaryenModuleRef_val(_module);
123
123
  char* name = Safe_String_val(_name);
124
- CAMLreturn(Val_int(BinaryenGetMemorySegmentByteOffset(module, name)));
124
+ if (BinaryenGetMemorySegmentPassive(module, name)) {
125
+ CAMLreturn(Val_none);
126
+ } else {
127
+ int offset = BinaryenGetMemorySegmentByteOffset(module, name);
128
+ CAMLreturn(caml_alloc_some(Val_int(offset)));
129
+ }
125
130
  }
126
131
 
127
132
  CAMLprim value
@@ -112,10 +112,10 @@ function caml_binaryen_get_num_memory_segments(wasm_mod) {
112
112
  }
113
113
 
114
114
  //Provides: caml_binaryen_get_memory_segment_byte_offset
115
- //Requires: caml_jsstring_of_string
115
+ //Requires: caml_jsstring_of_string, to_option
116
116
  function caml_binaryen_get_memory_segment_byte_offset(wasm_mod, name) {
117
117
  var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
118
- return info.offset;
118
+ return to_option(info.offset);
119
119
  }
120
120
 
121
121
  //Provides: caml_binaryen_get_memory_segment_passive
@@ -71,7 +71,7 @@ let unlimited = -1
71
71
  external get_num_segments : Module.t -> int
72
72
  = "caml_binaryen_get_num_memory_segments"
73
73
 
74
- external get_segment_byte_offset : Module.t -> string -> int
74
+ external get_segment_byte_offset : Module.t -> string -> int option
75
75
  = "caml_binaryen_get_memory_segment_byte_offset"
76
76
 
77
77
  external get_segment_passive : Module.t -> string -> bool
@@ -20,6 +20,6 @@ val is_shared : Module.t -> string -> bool
20
20
  val is_64 : Module.t -> string -> bool
21
21
  val unlimited : int
22
22
  val get_num_segments : Module.t -> int
23
- val get_segment_byte_offset : Module.t -> string -> int
23
+ val get_segment_byte_offset : Module.t -> string -> int option
24
24
  val get_segment_passive : Module.t -> string -> bool
25
25
  val get_segment_data : Module.t -> string -> bytes
@@ -17,36 +17,24 @@ function caml_binaryen_module_parse(text) {
17
17
  }
18
18
 
19
19
  //Provides: caml_binaryen_module_print
20
- //Requires: caml_sys_fds
21
- //Requires: caml_string_of_jsstring
22
- //Requires: caml_ml_output, caml_ml_string_length
20
+ //Requires: caml_ml_output_str_stdout
23
21
  function caml_binaryen_module_print(wasm_mod) {
24
22
  var text = wasm_mod.emitText();
25
- var chanid = caml_sys_fds[1].chanid; // stdout
26
- var s = caml_string_of_jsstring(text);
27
- caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
23
+ caml_ml_output_str_stdout(text);
28
24
  }
29
25
 
30
26
  //Provides: caml_binaryen_module_print_asmjs
31
- //Requires: caml_sys_fds
32
- //Requires: caml_string_of_jsstring
33
- //Requires: caml_ml_output, caml_ml_string_length
27
+ //Requires: caml_ml_output_str_stdout
34
28
  function caml_binaryen_module_print_asmjs(wasm_mod) {
35
29
  var asm = wasm_mod.emitAsmjs();
36
- var chanid = caml_sys_fds[1].chanid; // stdout
37
- var s = caml_string_of_jsstring(asm);
38
- caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
30
+ caml_ml_output_str_stdout(asm);
39
31
  }
40
32
 
41
33
  //Provides: caml_binaryen_module_print_stack_ir
42
- //Requires: caml_sys_fds
43
- //Requires: caml_string_of_jsstring
44
- //Requires: caml_ml_output, caml_ml_string_length
34
+ //Requires: caml_ml_output_str_stdout
45
35
  function caml_binaryen_module_print_stack_ir(wasm_mod) {
46
36
  var stackir = wasm_mod.emitStackIR();
47
- var chanid = caml_sys_fds[1].chanid; // stdout
48
- var s = caml_string_of_jsstring(stackir);
49
- caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
37
+ caml_ml_output_str_stdout(stackir);
50
38
  }
51
39
 
52
40
  //Provides: caml_binaryen_module_validate
@@ -132,6 +120,5 @@ function caml_binaryen_add_custom_section(wasm_mod, name, contents) {
132
120
 
133
121
  //Provides: caml_binaryen_module_update_maps
134
122
  function caml_binaryen_module_update_maps(wasm_mod) {
135
- // The JS version doesn't expose `update_maps`
136
- return;
123
+ return wasm_mod.updateMaps();
137
124
  }