I'm quite new to OCaml and to the js_of_ocaml compiler in particular.
Did someone manage to compile the application which uses Jane Street Core with js_of_ocaml? I get lots of "missing primitives" warnings during the compilation, and then when I try to run it with node
they turn into an actual exceptions.
I understand that those are primitives which can't be ported from OCaml to JS
and that their implementation should depend on the application, but for core there is literally thousands of them, whereas my program only uses output to stdout
.
On a side note, I had trouble even compiling a simple "hello world" project, as IO functions weren't implemented in JS. Is there a "standard" JS file somewhere which could be used for this purpose? e.g. replacing caml_ml_output_char
with console.log
and other things, so that modules can be compiled to something useful without writing any custom javascript?
Yes, it is possible to compile Core_kernel
with js_of_ocaml
, OCamlPro did a version of Try-OCaml with it. It requires to patch a few of its dependencies (sexplib, ounit, etc.) and to use the latest version of js_of_ocaml
from the repository, that includes a bigarray
implementation.
as of today, core_kernel version 0.9, it works.
after compile to bytecode.
run js_of_ocaml
js_of_ocaml +weak.js +nat.js +base/runtime.js +core_kernel/runtime.js +bin_prot/runtime.js main.bc
or add the js_of_ocaml in jbuilder directly.
(js_of_ocaml (
(flags (+weak.js +nat.js +base/runtime.js +core_kernel/runtime.js +bin_prot/runtime.js))))
Yeah, missing primitives are the issue when using Core
with js_of_ocaml
. There is core_kernel
library. It is a subset of Core
which contains basic functions. UNIX-related functions from core
are not included to Core_kernel
. If I remember correctly, the main reason for extracting Core_kernel
from Core
is your issue.
Update.
I have failed. It seems that developers have tried to allow using Core_kernel
with js_of_ocaml but without success. It seems that you can't do it now. They are waiting for OCaml namespaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With