Page
Library
Module
Module type
Parameter
Class
Class type
Source
Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js.
See opam file for version constraints.
opam install js_of_ocaml js_of_ocaml-ppx
Makefile.conf
to change the default configurationmake all
to compilemake install
as root to install the compiler and its librariesmake uninstall
as root to uninstall themYou can run make toplevel-examples
if you want to build a Web-based OCaml toplevel as well. Try the toplevel
Your program must first be compiled using the OCaml bytecode compiler ocamlc
. JavaScript bindings are provided by the js_of_ocaml
package. The syntax extension is provided by js_of_ocaml.syntax
package.
ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.ppx -linkpkg -o cubes.byte cubes.ml
Then, run the js_of_ocaml
compiler to produce JavaScript code:
js_of_ocaml cubes.byte
Most of the OCaml standard library is supported. However,
Extra libraries distributed with OCaml (such as Thread or Str) are not supported in general. However,
+nat.js
optionTail call is not optimized in general. However, mutually recursive functions are optimized:
Data representation differs from the usual one. Most notably, integers are 32 bits (rather than 31 bits or 63 bits), which is their natural size in JavaScript, and floats are not boxed. As a consequence, marshalling, polymorphic comparison, and hashing functions can yield results different from usual:
Filename | Description |
---|---|
LICENSE | license and copyright notice |
README | this file |
compiler/ | compiler |
examples/ | small examples |
lib/ | library for interfacing with JavaScript APIs |
ppx/ | ppx syntax extensions |
runtime/ | runtime system |
toplevel/ | web-based OCaml toplevel |
ocamlbuild/ | ocamlbuild plugin for js_of_ocaml |