@grain/binaryen.ml 0.26.0 → 0.27.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 (60) hide show
  1. binaryen-archive/CHANGELOG.md +19 -0
  2. binaryen-archive/README.md +3 -2
  3. binaryen-archive/binaryen.opam +3 -3
  4. binaryen-archive/dune +2 -0
  5. binaryen-archive/esy.lock/index.json +630 -577
  6. binaryen-archive/esy.lock/opam/{base.v0.16.4 → base.v0.17.3}/opam +8 -6
  7. binaryen-archive/esy.lock/opam/{chrome-trace.3.18.2 → chrome-trace.3.20.2}/opam +5 -5
  8. binaryen-archive/esy.lock/opam/{dune-build-info.3.18.2 → dune-build-info.3.20.2}/opam +5 -5
  9. binaryen-archive/esy.lock/opam/{dune-configurator.3.18.2 → dune-configurator.3.20.2}/opam +5 -5
  10. binaryen-archive/esy.lock/opam/{dune-rpc.3.18.2 → dune-rpc.3.20.2}/opam +6 -5
  11. binaryen-archive/esy.lock/opam/{dune.3.18.2 → dune.3.20.2}/opam +8 -7
  12. binaryen-archive/esy.lock/opam/{dyn.3.18.2 → dyn.3.20.2}/opam +6 -6
  13. binaryen-archive/esy.lock/opam/{fix.20250428 → fix.20250919}/opam +3 -3
  14. binaryen-archive/esy.lock/opam/{js_of_ocaml-compiler.5.9.1 → js_of_ocaml-compiler.6.2.0}/opam +10 -10
  15. binaryen-archive/esy.lock/opam/jsonrpc.1.23.1/opam +50 -0
  16. binaryen-archive/esy.lock/opam/lsp.1.23.1/opam +60 -0
  17. binaryen-archive/esy.lock/opam/{menhir.20240715 → menhir.20250912}/opam +3 -3
  18. binaryen-archive/esy.lock/opam/{menhirCST.20240715 → menhirCST.20250912}/opam +4 -4
  19. binaryen-archive/esy.lock/opam/{menhirLib.20240715 → menhirLib.20250912}/opam +3 -3
  20. binaryen-archive/esy.lock/opam/{menhirSdk.20240715 → menhirSdk.20250912}/opam +3 -3
  21. binaryen-archive/esy.lock/opam/merlin-lib.5.6-503/opam +36 -0
  22. binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.17.0/opam +28 -0
  23. binaryen-archive/esy.lock/opam/{ocaml-lsp-server.1.12.4 → ocaml-lsp-server.1.23.1}/opam +24 -12
  24. binaryen-archive/esy.lock/opam/{ocaml-version.3.5.0 → ocaml-version.4.0.3}/opam +33 -28
  25. binaryen-archive/esy.lock/opam/ocaml_intrinsics_kernel.v0.17.1/opam +30 -0
  26. binaryen-archive/esy.lock/opam/ocamlc-loc.3.20.2/opam +45 -0
  27. binaryen-archive/esy.lock/opam/ocamlformat-lib.0.27.0/opam +68 -0
  28. binaryen-archive/esy.lock/opam/ocamlformat.0.27.0/opam +59 -0
  29. binaryen-archive/esy.lock/opam/{ordering.3.18.2 → ordering.3.20.2}/opam +6 -6
  30. binaryen-archive/esy.lock/opam/{ppx_yojson_conv_lib.v0.16.0 → ppx_yojson_conv_lib.v0.17.0}/opam +5 -4
  31. binaryen-archive/esy.lock/opam/{ppxlib.0.35.0 → ppxlib.0.37.0}/opam +5 -5
  32. binaryen-archive/esy.lock/opam/{re.1.12.0 → re.1.14.0}/opam +35 -27
  33. binaryen-archive/esy.lock/opam/{sedlex.3.4 → sedlex.3.7}/opam +3 -3
  34. binaryen-archive/esy.lock/opam/{sexplib0.v0.16.0 → sexplib0.v0.17.0}/opam +9 -4
  35. binaryen-archive/esy.lock/opam/{stdio.v0.16.0 → stdio.v0.17.0}/opam +6 -5
  36. binaryen-archive/esy.lock/opam/{stdune.3.18.2 → stdune.3.20.2}/opam +6 -6
  37. binaryen-archive/esy.lock/opam/{topkg.1.0.8 → topkg.1.1.0}/opam +2 -2
  38. binaryen-archive/esy.lock/opam/{uucp.16.0.0 → uucp.17.0.0}/opam +5 -5
  39. binaryen-archive/esy.lock/opam/{uuseg.16.0.0 → uuseg.17.0.0}/opam +4 -4
  40. binaryen-archive/esy.lock/opam/{xdg.3.18.2 → xdg.3.20.2}/opam +6 -5
  41. binaryen-archive/esy.lock/opam/{yojson.2.2.2 → yojson.3.0.0}/opam +5 -6
  42. binaryen-archive/package.json +9 -6
  43. binaryen-archive/src/expression.js +2 -1
  44. binaryen-archive/src/expression.ml +0 -24
  45. binaryen-archive/src/expression.mli +6 -6
  46. binaryen-archive/src/memory.c +30 -24
  47. binaryen-archive/src/memory.js +17 -11
  48. binaryen-archive/src/memory.ml +23 -12
  49. binaryen-archive/src/memory.mli +4 -4
  50. binaryen-archive/src/module.js +6 -3
  51. binaryen-archive/test/dune +1 -2
  52. binaryen-archive/test/test.expected +25 -23
  53. binaryen-archive/test/test.ml +7 -5
  54. binaryen-archive/esy.lock/opam/base-bigarray.base/opam +0 -6
  55. binaryen-archive/esy.lock/opam/ocaml-compiler-libs.v0.12.4/opam +0 -39
  56. binaryen-archive/esy.lock/opam/ocamlformat.0.24.1/opam +0 -57
  57. binaryen-archive/esy.lock/opam/octavius.1.2.2/opam +0 -36
  58. binaryen-archive/esy.lock/opam/odoc-parser.2.0.0/opam +0 -47
  59. binaryen-archive/esy.lock/opam/omd.1.3.2/opam +0 -50
  60. binaryen-archive/esy.lock/opam/result.1.5/opam +0 -25
@@ -16,9 +16,8 @@ doc: "https://ocaml.org/p/yojson/latest"
16
16
  bug-reports: "https://github.com/ocaml-community/yojson/issues"
17
17
  depends: [
18
18
  "dune" {>= "2.7"}
19
- "ocaml" {>= "4.02.3"}
19
+ "ocaml" {>= "4.08"}
20
20
  "alcotest" {with-test & >= "0.8.5"}
21
- "seq" {>= "0.2.2"}
22
21
  "odoc" {with-doc}
23
22
  ]
24
23
  build: [
@@ -38,10 +37,10 @@ build: [
38
37
  dev-repo: "git+https://github.com/ocaml-community/yojson.git"
39
38
  url {
40
39
  src:
41
- "https://github.com/ocaml-community/yojson/releases/download/2.2.2/yojson-2.2.2.tbz"
40
+ "https://github.com/ocaml-community/yojson/releases/download/3.0.0/yojson-3.0.0.tbz"
42
41
  checksum: [
43
- "sha256=9abfad8c9a79d4723ad2f6448e669c1e68dbfc87cc54a1b7c064b0c90912c595"
44
- "sha512=ac52eae3ca1d3129a7885ca638e6ae5bcfc387598a82cc30d3e4988fd154f1756719c399f96e950d898c79a6dbd4ccc44b6f468bcafbd620e6945a0415b41e0c"
42
+ "sha256=99414da7609b92a02474ef4b49ecda15edc8cbba5229341b124e7e4695c39610"
43
+ "sha512=896d0ea829a36ccadba6628800369c1a3ab9e7c64dbda8b76331889c9db481cd64e137f467481ae80a8dd5fca45d748bfa71f58641806cc1bb1a007f8291789f"
45
44
  ]
46
45
  }
47
- x-commit-hash: "3f82b79d1865eec82c6f498ee1835a90c74c31b4"
46
+ x-commit-hash: "b2193e8e0c88c6501710d08b836b3219673383f3"
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@grain/binaryen.ml",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "OCaml bindings for Binaryen.",
5
5
  "author": "Oscar Spencer <oscar@grain-lang.org>",
6
6
  "license": "Apache-2.0",
7
+ "installConfig": {
8
+ "pnp": false
9
+ },
7
10
  "dependencies": {
8
- "ocaml": ">= 4.13.0 < 5.0.0",
9
- "@grain/libbinaryen": ">= 116.0.0 < 117.0.0",
11
+ "ocaml": ">= 4.13.0 < 5.4.0",
12
+ "@grain/libbinaryen": "117.0.0-b",
10
13
  "@opam/dune": ">= 3.0.0",
11
14
  "@opam/dune-configurator": ">= 3.0.0"
12
15
  },
13
16
  "devDependencies": {
14
- "@opam/js_of_ocaml-compiler": ">= 4.1.0 < 6.0.0",
15
- "@opam/ocamlformat": "0.24.1",
16
- "@opam/ocaml-lsp-server": ">= 1.9.1 < 1.13.0"
17
+ "@opam/js_of_ocaml-compiler": ">= 6.0.0 < 7.0.0",
18
+ "@opam/ocamlformat": "0.27.0",
19
+ "@opam/ocaml-lsp-server": ">= 1.9.1 < 2.0.0"
17
20
  },
18
21
  "resolutions": {
19
22
  "@opam/ocp-indent": "1.7.0"
@@ -882,11 +882,12 @@ function caml_binaryen_expression_id_array_len() {
882
882
 
883
883
  //Provides: caml_binaryen_expression_print
884
884
  //Requires: Binaryen
885
+ //Requires: caml_sys_fds
885
886
  //Requires: caml_string_of_jsstring
886
887
  //Requires: caml_ml_output, caml_ml_string_length
887
888
  function caml_binaryen_expression_print(expr) {
888
889
  var text = Binaryen.emitText(expr);
889
- var chanid = 1; // stdout
890
+ var chanid = caml_sys_fds[1].chanid; // stdout
890
891
  var s = caml_string_of_jsstring(text);
891
892
  caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
892
893
  }
@@ -706,22 +706,9 @@ module Memory_init = struct
706
706
  external make : Module.t -> string -> t -> t -> t -> string -> t
707
707
  = "caml_binaryen_memory_init__bytecode" "caml_binaryen_memory_init"
708
708
  (** Module, segment, destination, offset, size, memory_name *)
709
-
710
- (* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
711
- let make wasm_mod segment dest offset size memory_name =
712
- make wasm_mod (string_of_int segment) dest offset size memory_name
713
-
714
709
  external get_segment : t -> string = "caml_binaryen_memory_init_get_segment"
715
-
716
- (* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
717
- let get_segment expr = int_of_string (get_segment expr)
718
-
719
710
  external set_segment : t -> string -> unit
720
711
  = "caml_binaryen_memory_init_set_segment"
721
-
722
- (* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
723
- let set_segment expr segment = set_segment expr (string_of_int segment)
724
-
725
712
  external get_dest : t -> t = "caml_binaryen_memory_init_get_dest"
726
713
  external set_dest : t -> t -> unit = "caml_binaryen_memory_init_set_dest"
727
714
  external get_offset : t -> t = "caml_binaryen_memory_init_get_offset"
@@ -733,20 +720,9 @@ end
733
720
  module Data_drop = struct
734
721
  external make : Module.t -> string -> t = "caml_binaryen_data_drop"
735
722
  (** Module, segment. *)
736
-
737
- (* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
738
- let make wasm_mod segment = make wasm_mod (string_of_int segment)
739
-
740
723
  external get_segment : t -> string = "caml_binaryen_data_drop_get_segment"
741
-
742
- (* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
743
- let get_segment expr = int_of_string (get_segment expr)
744
-
745
724
  external set_segment : t -> string -> unit
746
725
  = "caml_binaryen_data_drop_set_segment"
747
-
748
- (* Binaryen v113 still uses indexes for data segements, so we only want to change the binding itself, not our interface *)
749
- let set_segment expr segment = set_segment expr (string_of_int segment)
750
726
  end
751
727
 
752
728
  module Memory_copy = struct
@@ -256,9 +256,9 @@ module Memory_grow : sig
256
256
  end
257
257
 
258
258
  module Memory_init : sig
259
- val make : Module.t -> int -> t -> t -> t -> string -> t
260
- val get_segment : t -> int
261
- val set_segment : t -> int -> unit
259
+ val make : Module.t -> string -> t -> t -> t -> string -> t
260
+ val get_segment : t -> string
261
+ val set_segment : t -> string -> unit
262
262
  val get_dest : t -> t
263
263
  val set_dest : t -> t -> unit
264
264
  val get_offset : t -> t
@@ -268,9 +268,9 @@ module Memory_init : sig
268
268
  end
269
269
 
270
270
  module Data_drop : sig
271
- val make : Module.t -> int -> t
272
- val get_segment : t -> int
273
- val set_segment : t -> int -> unit
271
+ val make : Module.t -> string -> t
272
+ val get_segment : t -> string
273
+ val set_segment : t -> string -> unit
274
274
  end
275
275
 
276
276
  module Memory_copy : sig
@@ -8,19 +8,25 @@
8
8
 
9
9
 
10
10
  CAMLprim value
11
- caml_binaryen_set_memory(value _module, value _initial, value _maximum, value _exportName, value _segments, value _segmentPassive, value _segmentOffsets, value _segmentSizes, value _shared, value _memory64, value _memoryName) {
12
- CAMLparam5(_module, _initial, _maximum, _exportName, _segments);
13
- CAMLxparam5(_segmentPassive, _segmentOffsets, _segmentSizes, _shared, _memory64);
14
- CAMLxparam1(_memoryName);
11
+ caml_binaryen_set_memory(value _module, value _initial, value _maximum, value _exportName, value _segment_names, value _segment_data, value _segmentPassive, value _segmentOffsets, value _segmentSizes, value _shared, value _memory64, value _memoryName) {
12
+ CAMLparam5(_module, _initial, _maximum, _exportName, _segment_names);
13
+ CAMLxparam5(_segment_data, _segmentPassive, _segmentOffsets, _segmentSizes, _shared);
14
+ CAMLxparam2(_memory64, _memoryName);
15
15
  BinaryenModuleRef module = BinaryenModuleRef_val(_module);
16
16
  BinaryenIndex initial = Int_val(_initial);
17
17
  BinaryenIndex maximum = Int_val(_maximum);
18
18
  char* exportName = Safe_String_val(_exportName);
19
- _segments = array_of_list(_segments);
20
- int segmentsLen = array_length(_segments);
21
- const char* segments[segmentsLen];
22
- for (int i = 0; i < segmentsLen; i++) {
23
- segments[i] = Safe_String_val(Field(_segments, i));
19
+ _segment_names = array_of_list(_segment_names);
20
+ int segmentNamesLen = array_length(_segment_names);
21
+ const char* segment_names[segmentNamesLen];
22
+ for (int i = 0; i < segmentNamesLen; i++) {
23
+ segment_names[i] = Safe_String_val(Field(_segment_names, i));
24
+ }
25
+ _segment_data = array_of_list(_segment_data);
26
+ int segmentDataLen = array_length(_segment_data);
27
+ const char* segment_data[segmentDataLen];
28
+ for (int i = 0; i < segmentDataLen; i++) {
29
+ segment_data[i] = Safe_String_val(Field(_segment_data, i));
24
30
  }
25
31
  _segmentPassive = array_of_list(_segmentPassive);
26
32
  int segmentPassiveLen = array_length(_segmentPassive);
@@ -43,12 +49,12 @@ caml_binaryen_set_memory(value _module, value _initial, value _maximum, value _e
43
49
  bool shared = Bool_val(_shared);
44
50
  bool memory64 = Bool_val(_memory64);
45
51
  char* memoryName = Safe_String_val(_memoryName);
46
- BinaryenSetMemory(module, initial, maximum, exportName, segments, segmentPassive, segmentOffsets, segmentSizes, segmentsLen, shared, memory64, memoryName);
52
+ BinaryenSetMemory(module, initial, maximum, exportName, segment_names, segment_data, segmentPassive, segmentOffsets, segmentSizes, segmentNamesLen, shared, memory64, memoryName);
47
53
  CAMLreturn(Val_unit);
48
54
  }
49
55
  CAMLprim value
50
56
  caml_binaryen_set_memory__bytecode(value * argv) {
51
- return caml_binaryen_set_memory(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]);
57
+ return caml_binaryen_set_memory(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]);
52
58
  }
53
59
 
54
60
  CAMLprim value
@@ -111,28 +117,28 @@ caml_binaryen_get_num_memory_segments(value _module) {
111
117
  }
112
118
 
113
119
  CAMLprim value
114
- caml_binaryen_get_memory_segment_byte_offset(value _module, value _id) {
115
- CAMLparam2(_module, _id);
120
+ caml_binaryen_get_memory_segment_byte_offset(value _module, value _name) {
121
+ CAMLparam2(_module, _name);
116
122
  BinaryenModuleRef module = BinaryenModuleRef_val(_module);
117
- BinaryenIndex id = Int_val(_id);
118
- CAMLreturn(Val_int(BinaryenGetMemorySegmentByteOffset(module, id)));
123
+ char* name = Safe_String_val(_name);
124
+ CAMLreturn(Val_int(BinaryenGetMemorySegmentByteOffset(module, name)));
119
125
  }
120
126
 
121
127
  CAMLprim value
122
- caml_binaryen_get_memory_segment_passive(value _module, value _id) {
123
- CAMLparam2(_module, _id);
128
+ caml_binaryen_get_memory_segment_passive(value _module, value _name) {
129
+ CAMLparam2(_module, _name);
124
130
  BinaryenModuleRef module = BinaryenModuleRef_val(_module);
125
- BinaryenIndex id = Int_val(_id);
126
- CAMLreturn(Val_bool(BinaryenGetMemorySegmentPassive(module, id)));
131
+ char* name = Safe_String_val(_name);
132
+ CAMLreturn(Val_bool(BinaryenGetMemorySegmentPassive(module, name)));
127
133
  }
128
134
 
129
135
  CAMLprim value
130
- caml_binaryen_get_memory_segment_data(value _module, value _id) {
131
- CAMLparam2(_module, _id);
136
+ caml_binaryen_get_memory_segment_data(value _module, value _name) {
137
+ CAMLparam2(_module, _name);
132
138
  BinaryenModuleRef module = BinaryenModuleRef_val(_module);
133
- BinaryenIndex id = Int_val(_id);
134
- size_t size = BinaryenGetMemorySegmentByteLength(module, id);
139
+ char* name = Safe_String_val(_name);
140
+ size_t size = BinaryenGetMemorySegmentByteLength(module, name);
135
141
  CAMLprim value bytes = caml_alloc_string(size);
136
- BinaryenCopyMemorySegmentData(module, id, (char*)Bytes_val(bytes));
142
+ BinaryenCopyMemorySegmentData(module, name, (char*)Bytes_val(bytes));
137
143
  CAMLreturn(bytes);
138
144
  }
@@ -6,7 +6,8 @@ function caml_binaryen_set_memory(
6
6
  initial,
7
7
  maximum,
8
8
  exportName,
9
- segments,
9
+ segmentNames,
10
+ segmentData,
10
11
  segmentPassives,
11
12
  segmentOffsets,
12
13
  segmentSizes,
@@ -14,11 +15,13 @@ function caml_binaryen_set_memory(
14
15
  memory64,
15
16
  memoryName
16
17
  ) {
18
+ var datas = caml_list_to_js_array(segmentData);
17
19
  var passives = caml_list_to_js_array(segmentPassives);
18
20
  var offsets = caml_list_to_js_array(segmentOffsets);
19
- var segs = caml_list_to_js_array(segments).map(function (segment, idx) {
21
+ var segs = caml_list_to_js_array(segmentNames).map(function (name, idx) {
20
22
  return {
21
- data: caml_convert_bytes_to_array(segment),
23
+ name: caml_jsstring_of_string(name),
24
+ data: caml_convert_bytes_to_array(datas[idx]),
22
25
  passive: caml_js_from_bool(passives[idx]),
23
26
  offset: offsets[idx],
24
27
  };
@@ -48,7 +51,8 @@ function caml_binaryen_set_memory__bytecode() {
48
51
  arguments[7],
49
52
  arguments[8],
50
53
  arguments[9],
51
- arguments[10]
54
+ arguments[10],
55
+ arguments[11]
52
56
  );
53
57
  }
54
58
 
@@ -108,20 +112,22 @@ function caml_binaryen_get_num_memory_segments(wasm_mod) {
108
112
  }
109
113
 
110
114
  //Provides: caml_binaryen_get_memory_segment_byte_offset
111
- function caml_binaryen_get_memory_segment_byte_offset(wasm_mod, idx) {
112
- var info = wasm_mod.getMemorySegmentInfoByIndex(idx);
115
+ //Requires: caml_jsstring_of_string
116
+ function caml_binaryen_get_memory_segment_byte_offset(wasm_mod, name) {
117
+ var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
113
118
  return info.offset;
114
119
  }
115
120
 
116
121
  //Provides: caml_binaryen_get_memory_segment_passive
117
- function caml_binaryen_get_memory_segment_passive(wasm_mod, idx) {
118
- var info = wasm_mod.getMemorySegmentInfoByIndex(idx);
122
+ //Requires: caml_jsstring_of_string
123
+ function caml_binaryen_get_memory_segment_passive(wasm_mod, name) {
124
+ var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
119
125
  return info.passive;
120
126
  }
121
127
 
122
128
  //Provides: caml_binaryen_get_memory_segment_data
123
- //Requires: caml_bytes_of_array
124
- function caml_binaryen_get_memory_segment_data(wasm_mod, idx) {
125
- var info = wasm_mod.getMemorySegmentInfoByIndex(idx);
129
+ //Requires: caml_bytes_of_array, caml_jsstring_of_string
130
+ function caml_binaryen_get_memory_segment_data(wasm_mod, name) {
131
+ var info = wasm_mod.getMemorySegmentInfo(caml_jsstring_of_string(name));
126
132
  return caml_bytes_of_array(info.data);
127
133
  }
@@ -3,6 +3,7 @@ external set_memory :
3
3
  int ->
4
4
  int ->
5
5
  string ->
6
+ string list ->
6
7
  bytes list ->
7
8
  bool list ->
8
9
  Expression.t list ->
@@ -12,7 +13,7 @@ external set_memory :
12
13
  string ->
13
14
  unit = "caml_binaryen_set_memory__bytecode" "caml_binaryen_set_memory"
14
15
 
15
- type segment = { data : bytes; kind : segment_kind; size : int }
16
+ type segment = { name : string; data : bytes; kind : segment_kind; size : int }
16
17
  and segment_kind = Passive | Active of { offset : Expression.t }
17
18
 
18
19
  (** Module, initial size, maximum size, export name, segments, shared, memory64, moduleName . *)
@@ -20,26 +21,36 @@ let set_memory wasm_mod initial maximum export_name (segments : segment list)
20
21
  shared memory64 moduleName =
21
22
  let split_segments segments =
22
23
  List.fold_right
23
- (fun { data; kind; size }
24
- (segment_data, segment_passive, segment_offsets, segment_sizes) ->
24
+ (fun { name; data; kind; size }
25
+ ( segment_name,
26
+ segment_data,
27
+ segment_passive,
28
+ segment_offsets,
29
+ segment_sizes ) ->
25
30
  match kind with
26
31
  | Active { offset } ->
27
- ( data :: segment_data,
32
+ ( name :: segment_name,
33
+ data :: segment_data,
28
34
  false :: segment_passive,
29
35
  offset :: segment_offsets,
30
36
  size :: segment_sizes )
31
37
  | Passive ->
32
- ( data :: segment_data,
38
+ ( name :: segment_name,
39
+ data :: segment_data,
33
40
  true :: segment_passive,
34
41
  Expression.Null.make () :: segment_offsets,
35
42
  size :: segment_sizes ))
36
- segments ([], [], [], [])
43
+ segments ([], [], [], [], [])
37
44
  in
38
- let segment_data, segment_passive, segment_offsets, segment_sizes =
45
+ let ( segment_name,
46
+ segment_data,
47
+ segment_passive,
48
+ segment_offsets,
49
+ segment_sizes ) =
39
50
  split_segments segments
40
51
  in
41
- set_memory wasm_mod initial maximum export_name segment_data segment_passive
42
- segment_offsets segment_sizes shared memory64 moduleName
52
+ set_memory wasm_mod initial maximum export_name segment_name segment_data
53
+ segment_passive segment_offsets segment_sizes shared memory64 moduleName
43
54
 
44
55
  external has_memory : Module.t -> bool = "caml_binaryen_has_memory"
45
56
 
@@ -59,11 +70,11 @@ let unlimited = -1
59
70
  external get_num_segments : Module.t -> int
60
71
  = "caml_binaryen_get_num_memory_segments"
61
72
 
62
- external get_segment_byte_offset : Module.t -> int -> int
73
+ external get_segment_byte_offset : Module.t -> string -> int
63
74
  = "caml_binaryen_get_memory_segment_byte_offset"
64
75
 
65
- external get_segment_passive : Module.t -> int -> bool
76
+ external get_segment_passive : Module.t -> string -> bool
66
77
  = "caml_binaryen_get_memory_segment_passive"
67
78
 
68
- external get_segment_data : Module.t -> int -> bytes
79
+ external get_segment_data : Module.t -> string -> bytes
69
80
  = "caml_binaryen_get_memory_segment_data"
@@ -1,4 +1,4 @@
1
- type segment = { data : bytes; kind : segment_kind; size : int }
1
+ type segment = { name : string; data : bytes; kind : segment_kind; size : int }
2
2
  and segment_kind = Passive | Active of { offset : Expression.t }
3
3
 
4
4
  val set_memory :
@@ -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 -> int -> int
24
- val get_segment_passive : Module.t -> int -> bool
25
- val get_segment_data : Module.t -> int -> bytes
23
+ val get_segment_byte_offset : Module.t -> string -> int
24
+ val get_segment_passive : Module.t -> string -> bool
25
+ val get_segment_data : Module.t -> string -> bytes
@@ -17,31 +17,34 @@ function caml_binaryen_module_parse(text) {
17
17
  }
18
18
 
19
19
  //Provides: caml_binaryen_module_print
20
+ //Requires: caml_sys_fds
20
21
  //Requires: caml_string_of_jsstring
21
22
  //Requires: caml_ml_output, caml_ml_string_length
22
23
  function caml_binaryen_module_print(wasm_mod) {
23
24
  var text = wasm_mod.emitText();
24
- var chanid = 1; // stdout
25
+ var chanid = caml_sys_fds[1].chanid; // stdout
25
26
  var s = caml_string_of_jsstring(text);
26
27
  caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
27
28
  }
28
29
 
29
30
  //Provides: caml_binaryen_module_print_asmjs
31
+ //Requires: caml_sys_fds
30
32
  //Requires: caml_string_of_jsstring
31
33
  //Requires: caml_ml_output, caml_ml_string_length
32
34
  function caml_binaryen_module_print_asmjs(wasm_mod) {
33
35
  var asm = wasm_mod.emitAsmjs();
34
- var chanid = 1; // stdout
36
+ var chanid = caml_sys_fds[1].chanid; // stdout
35
37
  var s = caml_string_of_jsstring(asm);
36
38
  caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
37
39
  }
38
40
 
39
41
  //Provides: caml_binaryen_module_print_stack_ir
42
+ //Requires: caml_sys_fds
40
43
  //Requires: caml_string_of_jsstring, caml_js_from_bool
41
44
  //Requires: caml_ml_output, caml_ml_string_length
42
45
  function caml_binaryen_module_print_stack_ir(wasm_mod, optimize) {
43
46
  var stackir = wasm_mod.emitStackIR(caml_js_from_bool(optimize));
44
- var chanid = 1; // stdout
47
+ var chanid = caml_sys_fds[1].chanid; // stdout
45
48
  var s = caml_string_of_jsstring(stackir);
46
49
  caml_ml_output(chanid, s, 0, caml_ml_string_length(s));
47
50
  }
@@ -4,8 +4,7 @@
4
4
  (modes exe js)
5
5
  (flags
6
6
  :standard
7
- (:include ./config/ocamlopt_flags.sexp))
8
- (js_of_ocaml))
7
+ (:include ./config/ocamlopt_flags.sexp)))
9
8
 
10
9
  (rule
11
10
  (alias runtest)
@@ -16,8 +16,8 @@
16
16
  (global $max_int64_mut (mut i64) (i64.const 9223372036854775807))
17
17
  (global $test_float64_bits f64 (f64.const 1.23))
18
18
  (memory $0 1)
19
- (data $0 (i32.const 0) "hello")
20
- (data $1 "world")
19
+ (data $hello (i32.const 0) "hello")
20
+ (data $world "world")
21
21
  (table $table 1 1 funcref)
22
22
  (elem $elem (i32.const 0) $adder)
23
23
  (export "adder" (func $adder))
@@ -28,7 +28,9 @@
28
28
  (block $add (result i32)
29
29
  (if
30
30
  (i32.const 0)
31
- (unreachable)
31
+ (then
32
+ (unreachable)
33
+ )
32
34
  )
33
35
  (i32.add
34
36
  (select
@@ -44,7 +46,7 @@
44
46
  )
45
47
  (func $start (type $1)
46
48
  (block $start
47
- (memory.init $1
49
+ (memory.init $world
48
50
  (i32.const 2048)
49
51
  (i32.const 0)
50
52
  (i32.const 5)
@@ -73,8 +75,8 @@
73
75
  (type $3 (func (param anyref) (result i32)))
74
76
  (import "future-wasi" "write" (func $write (type $2) (param anyref i32 i32) (result i32)))
75
77
  (memory $0 1)
76
- (data $0 (i32.const 0) "hello")
77
- (data $1 "world")
78
+ (data $hello (i32.const 0) "hello")
79
+ (data $world "world")
78
80
  (table $table 1 1 funcref)
79
81
  (elem $elem (i32.const 0) $adder)
80
82
  (export "adder" (func $adder))
@@ -94,7 +96,7 @@
94
96
  )
95
97
  )
96
98
  (func $start (type $1) (; has Stack IR ;)
97
- (memory.init $1
99
+ (memory.init $world
98
100
  (i32.const 2048)
99
101
  (i32.const 0)
100
102
  (i32.const 5)
@@ -115,11 +117,11 @@
115
117
  )
116
118
  )
117
119
  (module
118
- (type $type$0 (func (param anyref i32 i32) (result i32)))
119
- (type $type$1 (func (param i32 i32) (result i32)))
120
- (type $type$2 (func))
121
- (type $type$3 (func (param anyref) (result i32)))
122
- (import "future-wasi" "write" (func $fimport$0 (type $type$0) (param anyref i32 i32) (result i32)))
120
+ (type $type (func (param anyref i32 i32) (result i32)))
121
+ (type $type_1 (func (param i32 i32) (result i32)))
122
+ (type $type_2 (func))
123
+ (type $type_3 (func (param anyref) (result i32)))
124
+ (import "future-wasi" "write" (func $fimport$0 (type $type) (param anyref i32 i32) (result i32)))
123
125
  (memory $0 1)
124
126
  (data $0 (i32.const 0) "hello")
125
127
  (data $1 "world")
@@ -129,7 +131,7 @@
129
131
  (export "memory" (memory $0))
130
132
  (export "hello" (func $2))
131
133
  (start $1)
132
- (func $0 (type $type$1) (param $0 i32) (param $1 i32) (result i32)
134
+ (func $0 (type $type_1) (param $0 i32) (param $1 i32) (result i32)
133
135
  (i32.add
134
136
  (select
135
137
  (local.get $0)
@@ -141,7 +143,7 @@
141
143
  (local.get $1)
142
144
  )
143
145
  )
144
- (func $1 (type $type$2)
146
+ (func $1 (type $type_2)
145
147
  (memory.init $1
146
148
  (i32.const 2048)
147
149
  (i32.const 0)
@@ -154,7 +156,7 @@
154
156
  )
155
157
  )
156
158
  )
157
- (func $2 (type $type$3) (param $0 anyref) (result i32)
159
+ (func $2 (type $type_3) (param $0 anyref) (result i32)
158
160
  (call $fimport$0
159
161
  (local.get $0)
160
162
  (i32.const 0)
@@ -163,11 +165,11 @@
163
165
  )
164
166
  )
165
167
  (module
166
- (type $type$0 (func (param anyref i32 i32) (result i32)))
167
- (type $type$1 (func (param i32 i32) (result i32)))
168
- (type $type$2 (func))
169
- (type $type$3 (func (param anyref) (result i32)))
170
- (import "future-wasi" "write" (func $fimport$0 (type $type$0) (param anyref i32 i32) (result i32)))
168
+ (type $type (func (param anyref i32 i32) (result i32)))
169
+ (type $type_1 (func (param i32 i32) (result i32)))
170
+ (type $type_2 (func))
171
+ (type $type_3 (func (param anyref) (result i32)))
172
+ (import "future-wasi" "write" (func $fimport$0 (type $type) (param anyref i32 i32) (result i32)))
171
173
  (memory $0 1)
172
174
  (data $0 (i32.const 0) "hello")
173
175
  (data $1 "world")
@@ -177,7 +179,7 @@
177
179
  (export "memory" (memory $0))
178
180
  (export "hello" (func $2))
179
181
  (start $1)
180
- (func $0 (type $type$1) (param $0 i32) (param $1 i32) (result i32)
182
+ (func $0 (type $type_1) (param $0 i32) (param $1 i32) (result i32)
181
183
  local.get $0
182
184
  local.get $1
183
185
  i32.load
@@ -186,7 +188,7 @@
186
188
  local.get $1
187
189
  i32.add
188
190
  )
189
- (func $1 (type $type$2)
191
+ (func $1 (type $type_2)
190
192
  i32.const 2048
191
193
  i32.const 0
192
194
  i32.const 5
@@ -196,7 +198,7 @@
196
198
  call $0
197
199
  drop
198
200
  )
199
- (func $2 (type $type$3) (param $0 anyref) (result i32)
201
+ (func $2 (type $type_3) (param $0 anyref) (result i32)
200
202
  local.get $0
201
203
  i32.const 0
202
204
  i32.const 1
@@ -82,7 +82,7 @@ let add =
82
82
  let _ = assert (Expression.Block.get_name add = Some "add")
83
83
 
84
84
  (* Create the add function *)
85
- let adder = Function.add_function wasm_mod "adder" (params ()) results [||] add
85
+ let _adder = Function.add_function wasm_mod "adder" (params ()) results [||] add
86
86
 
87
87
  let call_adder =
88
88
  Expression.Call_indirect.make wasm_mod "table"
@@ -97,7 +97,7 @@ let start =
97
97
  Function.add_function wasm_mod "start" Type.none Type.none [||]
98
98
  (Expression.Block.make wasm_mod ~return_type:Type.none "start"
99
99
  [
100
- Expression.Memory_init.make wasm_mod 1
100
+ Expression.Memory_init.make wasm_mod "world"
101
101
  (Expression.Const.make wasm_mod (Literal.int32 2048l))
102
102
  (Expression.Const.make wasm_mod (Literal.int32 0l))
103
103
  (Expression.Const.make wasm_mod (Literal.int32 5l))
@@ -157,13 +157,13 @@ let segment : Binaryen.Memory.segment =
157
157
  { offset = Expression.Const.make wasm_mod (Literal.int32 0l) }
158
158
  in
159
159
  let size = Bytes.length data in
160
- { data; kind; size }
160
+ { name = "hello"; data; kind; size }
161
161
 
162
162
  let passive_segment : Binaryen.Memory.segment =
163
163
  let data = Bytes.of_string "world" in
164
164
  let kind = Binaryen.Memory.Passive in
165
165
  let size = Bytes.length data in
166
- { data; kind; size }
166
+ { name = "world"; data; kind; size }
167
167
 
168
168
  let _ = assert (Memory.has_memory wasm_mod = false)
169
169
 
@@ -183,7 +183,9 @@ let _ = assert (Memory.get_max max_memory_wasm_mod "0" = 2)
183
183
 
184
184
  let _ =
185
185
  assert (
186
- Bytes.equal (Memory.get_segment_data wasm_mod 1) (Bytes.of_string "world"))
186
+ Bytes.equal
187
+ (Memory.get_segment_data wasm_mod "world")
188
+ (Bytes.of_string "world"))
187
189
 
188
190
  (* Create an imported "write" function i32 (externref, i32, i32) *)
189
191
  (* Similar to the example here: https://bytecodealliance.org/articles/reference-types-in-wasmtime *)
@@ -1,6 +0,0 @@
1
- opam-version: "2.0"
2
- maintainer: "https://github.com/ocaml/opam-repository/issues"
3
- description: """
4
- Bigarray library distributed with the OCaml compiler
5
- """
6
-