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
Compile OCaml with Melange #164
Comments
After a lot of hacks, ALMOST $ /usr/bin/node driver/main.js
/home/eduardo/reason/ocaml/_esy/ocaml-development/store/b/melange-ed5e2880/default/lib/js/caml_external_polyfill.js:16
throw new Error(s + " not polyfilled by ReScript yet\n")
^
Error: caml_weak_create not polyfilled by ReScript yet |
Some of this will require dropping IE11 support, but that's probably ok.
This can likely be done with a combination of WeakMap, WeakSet and WeakRef. Note that the MDN WeakRef docs states Safari is not supported but it does work (I've filed a bug).
There was previously a nativeint implementation but it wasn't correct. It should be possible to implement it using Bigint, but instead of attempting this it was removed. Looking through other ReScript issues that mention nativeint, one interesting complication is likely to be pattern matching: let f = function
| 1n
| 2n -> 3n
| x -> Nativeint.add 3n x So this may involve more than just implementing the basic nativeint functions. |
@TheSpyder I don't think we need to use And it will behave exactly like OCaml 32bits platforms, my guess is that we can even generate binaries for it. It would be also cool to have support to
|
yeah reverting the removal will restore 32 bit nativeint support. JS isn’t a 32 bit platform though, if there’s no advantage over |
Because And JS is a 32bit platform, the only kind of integers supported naturally by JS is 32bits. |
That’s not true with bigint, it was added to the primitive data types, and arguably it’s not true at all - JS integers are 64 bit and the maximum value is an obscene 2^1024 (although the largest "safe integer" is 2^53 - 1, anything bigger is an approximation). I think it's safe to say it is supported "naturally", whatever that means, even if some older devices don't implement bigint (a self-solving problem). |
@TheSpyder BigInt is not a type of integer in the low level sense of it.
JS integers are not 64bit, Remember https://tc39.es/ecma262/#sec-numberbitwiseop So the range of numbers which JS can process the fastest, is only 32bits integers, and I believe that as soon as you cross the 32bits range for integers you get a performance penalty, that's also why the That's also why in Why does it matter?If you're writing a compiler for a target that matters, as you can do all sorts of tricks based on the supported |
You're right, I forgot the math operations on numbers truncate to 32 bit (I hit this in my project at work). I realise I certainly haven't tested whether bigint is good enough to encode |
also, having |
@TheSpyder Encoding The problem of bigint is the platform requirement, it cannot be easily transpiled so adding a dependency on it is really bad. But also the syntax conflict is truly a shame, |
I'm opening this issue because hopefully we can compile OCaml with Melange soon. And this is a good signal that we support OCaml.
Known issues
bsc file.ml
ignoresfile.mli
leading to weak typessolved by adding -bs-read-cmi
symtable.ml
usesObj.new_block
andObj.set_field
The text was updated successfully, but these errors were encountered: