-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
binaryen.ml.js #15
binaryen.ml.js #15
Conversation
|
||
let dispose wasm_mod = ignore (meth_call wasm_mod "dispose" [||]) | ||
|
||
(* TODO: Check the unit8Array conversion *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't do ANY checks for this, like I did for the module writing/reading.
@@ -0,0 +1,2 @@ | |||
// Attach binaryen to our global | |||
global.binaryen = module.exports; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lulz 😭
@@ -11,3 +11,16 @@ external float64_bits : int64 -> t = "caml_binaryen_literal_float64_bits" | |||
let float32 n = float32_bits @@ Int32.bits_of_float n | |||
|
|||
external float64 : float -> t = "caml_binaryen_literal_float64" | |||
|
|||
(* Hacks for Binaryen.js stack allocations, Don't use in binaryen.native *) | |||
type jsoo = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is absolutely terrible, but I couldn't find a way around it while still using Binaryen.js because their const
implementations use their custom stack.
let uint8array_to_bytes u8a = | ||
Bytes.of_string (Typed_array.String.of_uint8Array u8a) | ||
|
||
let bytes_to_uint8array byts = | ||
meth_call Typed_array.uint8Array "from" | ||
[| inject (string (Bytes.to_string byts)) |] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the byte/uint8array utils that need to be checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 This is truly insane. Well done! I'm pretty ready to start putting it through the paces 👏
Only comment I really think I have: would it make sense to put js/binaryen.js
in src/binaryen.js
to match the other source submodule?
@ospencer I think keeping the If we ever get the main binaryen to build into JS off that main submodule, we might be able to drop the binaryen.js submodule completely. |
This builds on top of #14 and adds OCaml bindings to the Binaryen.js library (I even submoduled it, whoa!)
There are a couple of TODOs around checking bytes/Uint8Arrays but we need to expand the test suite or use it in Grain to try those out.