@grain/binaryen.ml 0.34.0 → 0.36.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 (79) hide show
  1. binaryen-archive/CHANGELOG.md +37 -0
  2. binaryen-archive/binaryen.opam +3 -3
  3. binaryen-archive/esy.lock/index.json +366 -391
  4. binaryen-archive/esy.lock/opam/base.v0.17.3/opam +5 -3
  5. binaryen-archive/esy.lock/opam/{chrome-trace.3.20.2 → chrome-trace.3.24.1}/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.20.2 → dune-build-info.3.24.2}/opam +6 -8
  8. binaryen-archive/esy.lock/opam/{dune-configurator.3.20.2 → dune-configurator.3.24.2}/opam +6 -8
  9. binaryen-archive/esy.lock/opam/{dune.3.20.2 → dune.3.24.2}/opam +15 -10
  10. binaryen-archive/esy.lock/opam/fix.20250919/opam +1 -0
  11. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.6.4.1/opam +67 -0
  12. binaryen-archive/esy.lock/opam/{menhir.20250912 → menhir.20260209}/opam +6 -4
  13. binaryen-archive/esy.lock/opam/{menhirCST.20250912 → menhirCST.20260209}/opam +4 -3
  14. binaryen-archive/esy.lock/opam/menhirGLR.20260209/opam +30 -0
  15. binaryen-archive/esy.lock/opam/{menhirLib.20250912 → menhirLib.20260209}/opam +5 -4
  16. binaryen-archive/esy.lock/opam/{menhirSdk.20250912 → menhirSdk.20260209}/opam +5 -4
  17. binaryen-archive/esy.lock/opam/ocaml-lsp-server.1.23.1/opam +2 -2
  18. binaryen-archive/esy.lock/opam/{ocaml-version.4.0.3 → ocaml-version.4.1.3}/opam +3 -3
  19. binaryen-archive/esy.lock/opam/{ocaml_intrinsics_kernel.v0.17.1 → ocaml_intrinsics_kernel.v0.17.2}/opam +3 -3
  20. binaryen-archive/esy.lock/opam/ocamlbuild.0.16.1/opam +1 -0
  21. binaryen-archive/esy.lock/opam/ocamlfind.1.9.8/opam +2 -1
  22. binaryen-archive/esy.lock/opam/{ocamlformat-lib.0.27.0 → ocamlformat-lib.0.29.0}/opam +7 -6
  23. binaryen-archive/esy.lock/opam/{ocamlformat-rpc-lib.0.28.1 → ocamlformat-rpc-lib.0.29.0}/opam +4 -4
  24. binaryen-archive/esy.lock/opam/{ocamlformat.0.27.0 → ocamlformat.0.29.0}/opam +6 -5
  25. binaryen-archive/esy.lock/opam/{ocp-indent.1.7.0 → ocp-indent.1.9.0}/opam +10 -9
  26. binaryen-archive/esy.lock/opam/ppx_yojson_conv_lib.v0.17.0/opam +2 -0
  27. binaryen-archive/esy.lock/opam/{ppxlib.0.37.0 → ppxlib.0.39.0~5.6preview}/opam +12 -13
  28. binaryen-archive/esy.lock/opam/sexplib0.v0.17.0/opam +2 -0
  29. binaryen-archive/esy.lock/opam/stdio.v0.17.0/opam +3 -1
  30. binaryen-archive/esy.lock/opam/{xdg.3.20.2 → xdg.3.24.2}/opam +6 -8
  31. binaryen-archive/package.json +9 -5
  32. binaryen-archive/src/dune +6 -1
  33. binaryen-archive/src/export.c +10 -0
  34. binaryen-archive/src/export.js +13 -0
  35. binaryen-archive/src/export.ml +4 -0
  36. binaryen-archive/src/export.mli +1 -0
  37. binaryen-archive/src/expression.c +636 -0
  38. binaryen-archive/src/expression.js +423 -7
  39. binaryen-archive/src/expression.ml +224 -0
  40. binaryen-archive/src/expression.mli +159 -0
  41. binaryen-archive/src/heap_type.c +19 -0
  42. binaryen-archive/src/heap_type.js +12 -0
  43. binaryen-archive/src/heap_type.ml +10 -1
  44. binaryen-archive/src/heap_type.mli +8 -1
  45. binaryen-archive/src/import.c +32 -0
  46. binaryen-archive/src/import.js +47 -0
  47. binaryen-archive/src/import.ml +12 -0
  48. binaryen-archive/src/import.mli +5 -0
  49. binaryen-archive/src/memory.c +6 -1
  50. binaryen-archive/src/memory.js +2 -2
  51. binaryen-archive/src/memory.ml +1 -1
  52. binaryen-archive/src/memory.mli +1 -1
  53. binaryen-archive/src/module.js +9 -22
  54. binaryen-archive/src/module.ml +4 -0
  55. binaryen-archive/src/module.mli +1 -0
  56. binaryen-archive/src/module_feature.c +6 -0
  57. binaryen-archive/src/module_feature.js +6 -0
  58. binaryen-archive/src/ocaml_helpers.c +17 -0
  59. binaryen-archive/src/ocaml_helpers.h +9 -0
  60. binaryen-archive/src/ocaml_helpers.js +11 -0
  61. binaryen-archive/src/passes.ml +13 -11
  62. binaryen-archive/src/passes.mli +13 -11
  63. binaryen-archive/src/tag.c +61 -0
  64. binaryen-archive/src/tag.js +43 -0
  65. binaryen-archive/src/tag.ml +11 -0
  66. binaryen-archive/src/tag.mli +8 -0
  67. binaryen-archive/src/type.c +5 -3
  68. binaryen-archive/src/type.js +5 -9
  69. binaryen-archive/src/type.ml +4 -1
  70. binaryen-archive/src/type.mli +1 -1
  71. binaryen-archive/src/type_builder.c +180 -0
  72. binaryen-archive/src/type_builder.js +116 -0
  73. binaryen-archive/src/type_builder.ml +67 -0
  74. binaryen-archive/src/type_builder.mli +28 -0
  75. binaryen-archive/test/test.expected +323 -33
  76. binaryen-archive/test/test.ml +220 -4
  77. binaryen-archive/esy.lock/opam/base-bytes.base/opam +0 -10
  78. binaryen-archive/esy.lock/opam/js_of_ocaml-compiler.6.2.0/opam +0 -56
  79. binaryen-archive/esy.lock/opam/stdlib-shims.0.3.0/opam +0 -31
@@ -171,13 +171,19 @@ let start =
171
171
  let _ = Export.add_function_export wasm_mod "adder" "adder"
172
172
  let _ = Table.add_table wasm_mod "table" 1 1 Type.funcref
173
173
 
174
- (* TODO(#240): Re-enable after type-builder api is merged *)
175
- (* let funcref_expr1 = Expression.Ref.func wasm_mod "adder" (Heap_type.func ())
174
+ let adder_type =
175
+ let builder = Type_builder.make 1 in
176
+ Type_builder.set_signature_type builder 0 (params ()) results;
177
+ match Type_builder.build_and_dispose builder with
178
+ | Ok [ ty ] -> ty
179
+ | _ -> failwith "failed to build type"
180
+
181
+ let funcref_expr1 = Expression.Ref.func wasm_mod "adder" adder_type
176
182
 
177
183
  let _ =
178
184
  Expression.Table.set wasm_mod "table"
179
185
  (Expression.Const.make wasm_mod (Literal.int32 0l))
180
- funcref_expr1 *)
186
+ funcref_expr1
181
187
 
182
188
  let funcref_expr2 =
183
189
  Expression.Table.get wasm_mod "table"
@@ -248,12 +254,106 @@ let _ = Memory.set_memory max_memory_wasm_mod 1 2 "memory" [] false false "0"
248
254
  let _ = assert (Memory.has_max max_memory_wasm_mod "0" = true)
249
255
  let _ = assert (Memory.get_max max_memory_wasm_mod "0" = 2)
250
256
 
257
+ (* Memory.get_segment_byte_offset Passive *)
258
+ let _ = assert (Memory.get_segment_byte_offset wasm_mod "world" = None)
259
+
251
260
  let _ =
252
261
  assert (
253
262
  Bytes.equal
254
263
  (Memory.get_segment_data wasm_mod "world")
255
264
  (Bytes.of_string "world"))
256
265
 
266
+ (* Call_ref *)
267
+ let thunk_type =
268
+ let builder = Type_builder.make 1 in
269
+ Type_builder.set_signature_type builder 0 Type.none Type.none;
270
+ match Type_builder.build_and_dispose builder with
271
+ | Ok [ ty ] -> ty
272
+ | _ -> failwith "failed to build type"
273
+
274
+ let _ =
275
+ Expression.Call_ref.make wasm_mod
276
+ (Expression.Ref.func wasm_mod "start" thunk_type)
277
+ [] Type.none
278
+
279
+ let _ = Tag.add_tag wasm_mod "foo" Type.int32 Type.none
280
+ let _ = Tag.add_tag wasm_mod "bar" Type.int32 Type.none
281
+
282
+ (* Exception handling *)
283
+ let body =
284
+ Expression.Throw.make wasm_mod "foo"
285
+ [ Expression.Const.make wasm_mod (Literal.int32 1l) ]
286
+
287
+ let try_catch_1 =
288
+ Expression.Try.make wasm_mod (Some "tc1") body
289
+ [
290
+ ( "foo",
291
+ Expression.Block.make wasm_mod "tc1blk2"
292
+ [
293
+ Expression.Drop.make wasm_mod
294
+ (Expression.Pop.make wasm_mod Type.int32);
295
+ Expression.Const.make wasm_mod (Literal.int32 2l);
296
+ ] );
297
+ ( "bar",
298
+ Expression.Block.make wasm_mod "tc1blk3"
299
+ [
300
+ Expression.Drop.make wasm_mod
301
+ (Expression.Pop.make wasm_mod Type.int32);
302
+ Expression.Const.make wasm_mod (Literal.int32 3l);
303
+ ] );
304
+ ]
305
+ None
306
+
307
+ let _ = assert (Expression.Try.get_name try_catch_1 = Some "tc1")
308
+ let _ = Expression.Try.set_name try_catch_1 "renamed_tc1"
309
+ let _ = assert (Expression.Try.get_name try_catch_1 = Some "renamed_tc1")
310
+ let _ = Expression.Try.set_name try_catch_1 "tc1"
311
+
312
+ let _ =
313
+ assert (
314
+ Expression.get_kind (Expression.Try.get_body try_catch_1)
315
+ = Expression.get_kind body)
316
+
317
+ let _ = assert (Expression.Try.get_num_catch_tags try_catch_1 = 2)
318
+ let _ = assert (Expression.Try.get_num_catch_bodies try_catch_1 = 2)
319
+
320
+ let try_catch_2 =
321
+ Expression.Try.make wasm_mod (Some "tc2")
322
+ (Expression.Throw.make wasm_mod "foo"
323
+ [ Expression.Const.make wasm_mod (Literal.int32 1l) ])
324
+ [
325
+ ( "foo",
326
+ Expression.Block.make wasm_mod "tc2blk2"
327
+ [
328
+ Expression.Drop.make wasm_mod
329
+ (Expression.Pop.make wasm_mod Type.int32);
330
+ ] );
331
+ ( "bar",
332
+ Expression.Block.make wasm_mod "tc2blk3"
333
+ [
334
+ Expression.Drop.make wasm_mod
335
+ (Expression.Pop.make wasm_mod Type.int32);
336
+ ] );
337
+ ]
338
+ None
339
+
340
+ let _ = assert (Expression.Try.get_name try_catch_2 = Some "tc2")
341
+
342
+ (* Test catch_all *)
343
+ let try_catch_all_1 =
344
+ Expression.Try.make wasm_mod (Some "tc3")
345
+ (Expression.Const.make wasm_mod (Literal.int32 1l))
346
+ [
347
+ ( "foo",
348
+ Expression.Block.make wasm_mod "tc3blk2"
349
+ [
350
+ Expression.Drop.make wasm_mod
351
+ (Expression.Pop.make wasm_mod Type.int32);
352
+ Expression.Const.make wasm_mod (Literal.int32 2l);
353
+ ] );
354
+ ]
355
+ (Some (Expression.Const.make wasm_mod (Literal.int32 3l)))
356
+
257
357
  (* Create an imported "write" function i32 (externref, i32, i32) *)
258
358
  (* Similar to the example here: https://bytecodealliance.org/articles/reference-types-in-wasmtime *)
259
359
 
@@ -273,9 +373,125 @@ let _ =
273
373
  ]
274
374
  Type.int32)
275
375
 
376
+ (* Create a function with try *)
377
+ let _ =
378
+ Function.add_function wasm_mod "try" Type.none Type.none [||]
379
+ (Expression.Block.make wasm_mod "blk"
380
+ [
381
+ Expression.Drop.make wasm_mod try_catch_1;
382
+ try_catch_2;
383
+ Expression.Drop.make wasm_mod try_catch_all_1;
384
+ ])
385
+
276
386
  let _ = Export.add_function_export wasm_mod "hello" "hello"
387
+ let _ = Export.add_function_export wasm_mod "try" "try"
277
388
  let _ = Module.validate wasm_mod
278
389
 
390
+ (* Create a function that does gc *)
391
+ let _ =
392
+ let array_u8_type =
393
+ let builder = Type_builder.make 1 in
394
+ Type_builder.set_array_type builder 0 Type.int32 Packed_type.int8 true;
395
+ match Type_builder.build_and_dispose builder with
396
+ | Ok [ ty ] -> ty
397
+ | _ -> failwith "failed to make array type"
398
+ in
399
+ let list_type =
400
+ let builder = Type_builder.make 1 in
401
+ let temp_heap_type = Type_builder.get_temp_heap_type builder 0 in
402
+ let temp_ref_type =
403
+ Type_builder.get_temp_ref_type builder temp_heap_type true
404
+ in
405
+ Type_builder.set_struct_type builder 0
406
+ [
407
+ Type_builder.
408
+ {
409
+ type_ = Type.i31ref;
410
+ packed_type = Packed_type.not_packed;
411
+ mutable_ = false;
412
+ };
413
+ Type_builder.
414
+ {
415
+ type_ = temp_ref_type;
416
+ packed_type = Packed_type.not_packed;
417
+ mutable_ = false;
418
+ };
419
+ ];
420
+ match Type_builder.build_and_dispose builder with
421
+ | Ok [ ty ] -> ty
422
+ | _ -> failwith "failed to make list type"
423
+ in
424
+ let i32 v = Expression.Const.make wasm_mod (Literal.int32 v) in
425
+ let i31 v = Expression.I31.make wasm_mod (i32 v) in
426
+ let cons first rest =
427
+ Expression.Struct.new_ wasm_mod (Some [ first; rest ]) list_type
428
+ in
429
+ let empty () =
430
+ Expression.Ref.null wasm_mod (Type.from_heap_type list_type true)
431
+ in
432
+ Function.add_function wasm_mod "gc" Type.anyref
433
+ (Type.create [| Type.anyref; Type.anyref |])
434
+ [|
435
+ Type.from_heap_type array_u8_type false;
436
+ Type.from_heap_type list_type false;
437
+ |]
438
+ (Expression.Block.make wasm_mod "gc_block"
439
+ [
440
+ Expression.Local_set.make wasm_mod 1
441
+ (Expression.Array.new_fixed wasm_mod array_u8_type
442
+ [ i32 0l; i32 255l ]);
443
+ Expression.Array.set wasm_mod
444
+ (Expression.Local_get.make wasm_mod 1
445
+ (Type.from_heap_type array_u8_type false))
446
+ (i32 1l) (i32 42l);
447
+ Expression.Local_set.make wasm_mod 2
448
+ (cons
449
+ (Expression.Ref.cast wasm_mod
450
+ (Expression.Local_get.make wasm_mod 0 Type.anyref)
451
+ Type.i31ref)
452
+ (cons (i31 1l) (cons (i31 2l) (cons (i31 3l) (empty ())))));
453
+ Expression.Tuple_make.make wasm_mod
454
+ [
455
+ Expression.Local_get.make wasm_mod 1
456
+ (Type.from_heap_type array_u8_type false);
457
+ Expression.Local_get.make wasm_mod 2
458
+ (Type.from_heap_type list_type false);
459
+ ];
460
+ ])
461
+
462
+ let _ = Export.add_function_export wasm_mod "gc" "gc"
463
+ let _ = assert (Module.validate wasm_mod == 1)
464
+
465
+ (* Test Heap_type.set_type_name and Heap_type.set_field_name *)
466
+ let list_type =
467
+ let builder = Type_builder.make 1 in
468
+ let temp_heap_type = Type_builder.get_temp_heap_type builder 0 in
469
+ let temp_ref_type =
470
+ Type_builder.get_temp_ref_type builder temp_heap_type true
471
+ in
472
+ Type_builder.set_struct_type builder 0
473
+ [
474
+ Type_builder.
475
+ {
476
+ type_ = Type.i31ref;
477
+ packed_type = Packed_type.not_packed;
478
+ mutable_ = false;
479
+ };
480
+ Type_builder.
481
+ {
482
+ type_ = temp_ref_type;
483
+ packed_type = Packed_type.not_packed;
484
+ mutable_ = false;
485
+ };
486
+ ];
487
+ match Type_builder.build_and_dispose builder with
488
+ | Ok [ ty ] -> ty
489
+ | _ -> failwith "failed to make list type"
490
+
491
+ let _ = Heap_type.set_type_name wasm_mod list_type "List"
492
+ let _ = Heap_type.set_field_name wasm_mod list_type 0 "head"
493
+ let _ = Heap_type.set_field_name wasm_mod list_type 1 "tail"
494
+
279
495
  (* Shouldn't actually do anything since we aren't doing function renames *)
280
496
  let _ = Module.update_maps wasm_mod
281
497
 
@@ -348,7 +564,7 @@ let _ =
348
564
  Module.Feature.all;
349
565
  ]
350
566
 
351
- let _ = Module.validate new_mod
567
+ let _ = assert (Module.validate new_mod == 1)
352
568
  let _ = Module.print new_mod
353
569
  let _ = Module.print_stack_ir new_mod
354
570
 
@@ -1,10 +0,0 @@
1
- opam-version: "2.0"
2
- maintainer: " "
3
- authors: " "
4
- homepage: " "
5
- depends: [
6
- "ocaml" {>= "4.02.0"}
7
- "ocamlfind" {>= "1.5.3"}
8
- ]
9
- synopsis: "Bytes library distributed with the OCaml compiler"
10
- x-maintained: true
@@ -1,56 +0,0 @@
1
- opam-version: "2.0"
2
- synopsis: "Compiler from OCaml bytecode to JavaScript"
3
- description:
4
- "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js"
5
- maintainer: ["Ocsigen team <dev@ocsigen.org>"]
6
- authors: ["Ocsigen team <dev@ocsigen.org>"]
7
- license: [
8
- "GPL-2.0-or-later" "LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
9
- ]
10
- homepage: "https://ocsigen.org/js_of_ocaml/latest/manual/overview"
11
- doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview"
12
- bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues"
13
- depends: [
14
- "dune" {>= "3.19"}
15
- "ocaml" {>= "4.13" & < "5.5"}
16
- "num" {with-test}
17
- "ppx_expect" {>= "v0.16.1" & with-test}
18
- "ppxlib" {>= "0.35"}
19
- "re" {with-test}
20
- "cmdliner" {>= "1.1.0"}
21
- "sedlex" {>= "3.3"}
22
- "qcheck" {with-test}
23
- "menhir"
24
- "menhirLib"
25
- "menhirSdk"
26
- "yojson" {>= "2.1"}
27
- "odoc" {with-doc}
28
- ]
29
- depopts: ["ocamlfind"]
30
- conflicts: [
31
- "ocamlfind" {< "1.5.1"}
32
- "js_of_ocaml" {< "3.0"}
33
- ]
34
- dev-repo: "git+https://github.com/ocsigen/js_of_ocaml.git"
35
- x-maintenance-intent: ["(latest)"]
36
- build: [
37
- [
38
- "dune"
39
- "build"
40
- "-p"
41
- name
42
- "-j"
43
- jobs
44
- "@install"
45
- "@doc" {with-doc}
46
- ]
47
- ]
48
- url {
49
- src:
50
- "https://github.com/ocsigen/js_of_ocaml/releases/download/6.2.0/js_of_ocaml-6.2.0.tbz"
51
- checksum: [
52
- "sha256=7cc641778d1b172a352a88333ee0e8c621365a0acfcd9b87e38bfddb8dd2a5da"
53
- "sha512=da50c79e1ad667df22abe03d0928ee135729c90cf09279e3c4854aec66557e8600890ca58f550529de1b1a44698720890b97528df167fd9e10cce24c71e763e6"
54
- ]
55
- }
56
- x-commit-hash: "938c18c46b78836119483d9cc9ce25ffdc44b718"
@@ -1,31 +0,0 @@
1
- opam-version: "2.0"
2
- maintainer: "The stdlib-shims programmers"
3
- authors: "The stdlib-shims programmers"
4
- homepage: "https://github.com/ocaml/stdlib-shims"
5
- doc: "https://ocaml.github.io/stdlib-shims/"
6
- dev-repo: "git+https://github.com/ocaml/stdlib-shims.git"
7
- bug-reports: "https://github.com/ocaml/stdlib-shims/issues"
8
- tags: ["stdlib" "compatibility" "org:ocaml"]
9
- license: ["LGPL-2.1-only WITH OCaml-LGPL-linking-exception"]
10
- depends: [
11
- "dune"
12
- "ocaml" {>= "4.02.3"}
13
- ]
14
- build: [ "dune" "build" "-p" name "-j" jobs ]
15
- synopsis: "Backport some of the new stdlib features to older compiler"
16
- description: """
17
- Backport some of the new stdlib features to older compiler,
18
- such as the Stdlib module.
19
-
20
- This allows projects that require compatibility with older compiler to
21
- use these new features in their code.
22
- """
23
- x-commit-hash: "fb6815e5d745f07fd567c11671149de6ef2e74c8"
24
- url {
25
- src:
26
- "https://github.com/ocaml/stdlib-shims/releases/download/0.3.0/stdlib-shims-0.3.0.tbz"
27
- checksum: [
28
- "sha256=babf72d3917b86f707885f0c5528e36c63fccb698f4b46cf2bab5c7ccdd6d84a"
29
- "sha512=1151d7edc8923516e9a36995a3f8938d323aaade759ad349ed15d6d8501db61ffbe63277e97c4d86149cf371306ac23df0f581ec7e02611f58335126e1870980"
30
- ]
31
- }