Skip to content

Conversation

@hhugo
Copy link
Member

@hhugo hhugo commented Jul 28, 2025

The goal is to address LexiFi/gen_js_api#177
cc mlasson

@vouillon, can this work with wasmoo ?

@smorimoto
Copy link
Member

@hhugo Ping

@hhugo
Copy link
Member Author

hhugo commented Oct 21, 2025

@vouillon, how do you want to implement such feature ?

@hhugo hhugo requested a review from vouillon October 21, 2025 17:31
@vouillon
Copy link
Member

I have pushed something. It only works with whole-program compilation, though. With separate compilation, only the JavaScript primitives used in the Wasm runtime are linked-in. I'm not sure what to do about that.

@hhugo
Copy link
Member Author

hhugo commented Oct 22, 2025

I have pushed something. It only works with whole-program compilation, though. With separate compilation, only the JavaScript primitives used in the Wasm runtime are linked-in. I'm not sure what to do about that.

Could we add a syntax to re-export js value to the wasm runtime ?

@hhugo
Copy link
Member Author

hhugo commented Oct 23, 2025

I have pushed something. It only works with whole-program compilation, though. With separate compilation, only the JavaScript primitives used in the Wasm runtime are linked-in. I'm not sure what to do about that.

Could we add a syntax to re-export js value to the wasm runtime ?

IIUC, we just need a way to tell the wasmoo compiler that additional js value must be included when building the js runtime.
The current mechanism checks the wasm code for import of the "js" namespace. We could either trick the system with "fake" import of additional js value or have a separate mechanism such as an annotation in the js runtime files.

@hhugo hhugo requested a review from vouillon October 23, 2025 11:41
Comment on lines 296 to 324
let i =
match i with
| Let (x, Apply { f; args; exact = false }) -> (
match Info.def info f with
| None -> i
| Some (Prim (Extern "caml_jsoo_runtime", [ name ])) -> (
let name =
match name with
| Pc (String name) -> Some name
| Pc _ -> None
| Pv x -> (
match Info.def info x with
| Some (Constant (String name)) -> Some name
| Some _ | None -> None)
in
match name with
| None -> i
| Some name -> (
let name = Primitive.resolve name in
match Primitive.arity name with
| exception Not_found -> i
| n ->
if List.compare_length_with args ~len:n = 0
then
Let (x, Prim (Extern name, List.map args ~f:(fun x -> Pv x)))
else i))
| Some _ -> i)
| _ -> i
in
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 we should remove this change (and the associated change in compiler/lib/flow.ml.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. Can you push this change ? I'm away from keyboard

@hhugo hhugo marked this pull request as ready for review October 28, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants