Skip to content

Conversation

@ospencer
Copy link
Member

Requires some upstream Binaryen.js changes I haven't upstreamed yet.

@ospencer ospencer self-assigned this Mar 11, 2025
@ospencer ospencer force-pushed the oscar/122 branch 4 times, most recently from b8876c4 to 92aa57f Compare November 2, 2025 03:57
@ospencer ospencer force-pushed the oscar/122 branch 2 times, most recently from 54618d1 to 6aa04d1 Compare November 11, 2025 22:42
Base automatically changed from oscar/122 to main November 12, 2025 01:07
Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a basic review of this it seems the TypeBuilder js api bassically ended up being the exact same minus one small difference.

I noticed some other functions we may want to implement.

My focus on this review was mostly to find out what needed updating so I didn't pay to close attention to the actual and .ml, .mli files.

//Requires: caml_jsstring_of_string
//Requires: caml_list_to_js_array, caml_js_from_bool
function caml_binaryen_call_ref(wasm_mod, target, params, typ, is_return) {
return wasm_mod.call_ref(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find this function in the js bindings in v124

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be added to the bindings, though I don't know the process on the binaryen side as I haven't touched it before:

self['call_ref'] = function(target, operands, type, isReturned) {
    return preserveStack(() =>
      Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type, isReturn)
    );
  };

function caml_binaryen_br_on(wasm_mod, op, name, ref, typ) {
switch (op) {
case Binaryen.BrOnNull:
return wasm_mod.br_on.null(caml_jsstring_of_string(name), ref, typ);
Copy link
Member

@spotandjake spotandjake Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//Provides: caml_binaryen_call_ref_get_target
//Requires: Binaryen
function caml_binaryen_call_ref_get_target(exp) {
return Binaryen.CallRef.getTarget(exp);
Copy link
Member

@spotandjake spotandjake Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find the Binaryen.CallRef stuff in the js bindings.

//Requires: caml_js_from_bool
function caml_binaryen_struct_get(wasm_mod, index, ref, type, signed) {
if (caml_js_from_bool(signed)) {
return wasm_mod.struct.get_s(index, ref, type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the get_s and get_u were converted to get accepting a signed bool. https://github.com/WebAssembly/binaryen/blob/64ba23996a10e229d46e41eb37736a55af87f79a/src/js/binaryen.js-post.js#L2506

Copy link
Member

@spotandjake spotandjake Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to implement all of the function as of v124,

We don't seem to have the js versions of:

  • We don't seem to have either the c or js bindings for array.fill
  • We don't seem to have either the c or js bindings for array.new_elem

Copy link
Member

@spotandjake spotandjake Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to implement all of the function as of v124,

We don't seem to have the js versions of:

external is_nullable : t -> bool = "caml_binaryen_type_is_nullable"
external from_heap_type : Heap_type.t -> t = "caml_binaryen_type_from_heap_type"

external from_heap_type : Heap_type.t -> bool -> t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that this is just a fix to our existing bindings.

mutable_ : bool;
}

type error =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to link to the values here: https://github.com/WebAssembly/binaryen/blob/64ba23996a10e229d46e41eb37736a55af87f79a/src/binaryen-c.h#L3618

Just for future updates.

Might also be a good idea to document the update practice for this in #252

var types = builder.buildAndDispose();
return [0, caml_js_to_array(types)];
} catch (e) {
return [1, [0, e.index, e.reason]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/WebAssembly/binaryen/blob/64ba23996a10e229d46e41eb37736a55af87f79a/src/js/binaryen.js-post.js#L2962

This looks to just throw a generic TypeError which I don't think has an index or reason.

The api looks to just ignore the error reason.

case Binaryen.BrOnNull:
return wasm_mod.br_on.null(caml_jsstring_of_string(name), ref, typ);
case Binaryen.BrOnNonNull:
return wasm_mod.br_on.non_null(caml_jsstring_of_string(name), ref, typ);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case Binaryen.BrOnNonNull:
return wasm_mod.br_on.non_null(caml_jsstring_of_string(name), ref, typ);
case Binaryen.BrOnCast:
return wasm_mod.br_on.cast(caml_jsstring_of_string(name), ref, typ);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case Binaryen.BrOnCast:
return wasm_mod.br_on.cast(caml_jsstring_of_string(name), ref, typ);
case Binaryen.BrOnCastFail:
return wasm_mod.br_on.cast_fail(caml_jsstring_of_string(name), ref, typ);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spotandjake
Copy link
Member

spotandjake commented Dec 6, 2025

Closes: #195, #182

@spotandjake spotandjake added the Api Issues or pull requests relating to implementing or modifying a binaryen api. label Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Api Issues or pull requests relating to implementing or modifying a binaryen api.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants