{"id":13658271,"url":"https://github.com/ocsigen/js_of_ocaml","last_synced_at":"2025-05-14T15:05:20.323Z","repository":{"id":9776885,"uuid":"11749064","full_name":"ocsigen/js_of_ocaml","owner":"ocsigen","description":"Compiler from OCaml to Javascript.","archived":false,"fork":false,"pushed_at":"2025-05-12T11:09:42.000Z","size":1708834,"stargazers_count":1014,"open_issues_count":72,"forks_count":194,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-05-12T11:26:05.635Z","etag":null,"topics":["compiler","javascript","jsoo","ocaml","ocsigen"],"latest_commit_sha":null,"homepage":"http://ocsigen.org/js_of_ocaml/","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocsigen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-29T20:28:11.000Z","updated_at":"2025-05-12T10:54:08.000Z","dependencies_parsed_at":"2023-01-16T19:45:58.828Z","dependency_job_id":"bea7bb4d-0789-47bf-b346-452aae2d1159","html_url":"https://github.com/ocsigen/js_of_ocaml","commit_stats":null,"previous_names":[],"tags_count":75,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocsigen%2Fjs_of_ocaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocsigen%2Fjs_of_ocaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocsigen%2Fjs_of_ocaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocsigen%2Fjs_of_ocaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocsigen","download_url":"https://codeload.github.com/ocsigen/js_of_ocaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254168752,"owners_count":22026206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","javascript","jsoo","ocaml","ocsigen"],"created_at":"2024-08-02T05:00:58.189Z","updated_at":"2025-05-14T15:05:20.260Z","avatar_url":"https://github.com/ocsigen.png","language":"OCaml","funding_links":[],"categories":["OCaml (14)","OCaml"],"sub_categories":[],"readme":"# Js_of_ocaml (jsoo)\n\n[![Build Status](https://github.com/ocsigen/js_of_ocaml/workflows/build/badge.svg?branch=master)](https://github.com/ocsigen/js_of_ocaml/actions)\n[![Update Web site - build](https://github.com/ocsigen/js_of_ocaml/actions/workflows/siteupdate.yml/badge.svg)](https://github.com/ocsigen/js_of_ocaml/actions/workflows/siteupdate.yml)\n[![Update Web site - deploy](https://github.com/ocsigen/js_of_ocaml/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/ocsigen/js_of_ocaml/actions/workflows/pages/pages-build-deployment)\n\nJs_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it\npossible to run pure OCaml programs in JavaScript environment like browsers and\nNode.js.\n\n- It is easy to install and use as it works with an existing installation of\n  OCaml, with no need to recompile any library.\n- It comes with bindings for a large part of the browser APIs.\n- According to our benchmarks, the generated programs runs typically faster than\n  with the OCaml bytecode interpreter.\n- We believe this compiler will prove much easier to maintain than a retargeted\n  OCaml compiler, as the bytecode provides a very stable API.\n\nJs_of_ocaml is composed of multiple packages:\n- js_of_ocaml-compiler, the compiler.\n- js_of_ocaml-ppx, a ppx syntax extension.\n- js_of_ocaml, the base library.\n- js_of_ocaml-ppx_deriving_json\n- js_of_ocaml-lwt, lwt support.\n- js_of_ocaml-tyxml, tyxml support.\n- js_of_ocaml-toplevel, lib and tools to build an ocaml toplevel to\n  javascript.\n- wasm_of_ocaml-compiler, [the Wasm_of_ocaml compiler](README_wasm_of_ocaml.md).\n\n## Requirements\n\nSee\n[opam](https://github.com/ocsigen/js_of_ocaml/blob/master/js_of_ocaml-compiler.opam)\nfile for version constraints.\n\n## Supported engines\n\nThe generated code works with Node.js 16 or any recent web-browser compatible with ECMAScript 6.\nWe optionally rely on js `WeakRef`, which is part of ECMAScript 2021, to implement `Stdlib.Weak` and `Stdlib.Ephemeron`.\n\n### Toplevel requirements\n\n- tyxml, reactiveData\n- ocp-indent: needed to support indentation in the toplevel\n- higlo: needed to support Syntax highlighting in the toplevel\n- cohttp: needed to build the toplevel webserver\n\n## Installation\n\n### Opam\n\n```\nopam install js_of_ocaml js_of_ocaml-compiler js_of_ocaml-ppx\n```\n\n## Usage\n\nYour program must first be compiled using the OCaml bytecode compiler `ocamlc`.\nJavaScript bindings are provided by the `js_of_ocaml` package. The syntax\nextension is provided by `js_of_ocaml-ppx` package.\n\n```\nocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml-ppx -linkpkg -o cubes.byte cubes.ml\n```\n\nThen, run the `js_of_ocaml` compiler to produce JavaScript code:\n\n```\njs_of_ocaml cubes.byte\n```\n\n## Features\n\nMost of the OCaml standard library is supported. However,\n\n- Most of the Sys module is not supported.\n\nExtra libraries distributed with OCaml (such as Thread) are not supported in\ngeneral. However,\n\n- Bigarray: bigarrays are supported using Typed Arrays\n- Num: supported\n- Str: supported\n- Graphics: partially supported using canvas (see js_of_ocaml-lwt.graphics)\n- Unix: time related functions are supported\n\nTail call is not optimized in general. However, mutually recursive functions are\noptimized:\n\n- self recursive functions (when the tail calls are the function itself) are\n  compiled using a loop.\n- trampolines are used otherwise.\n  [More](http://ocsigen.org/js_of_ocaml/dev/manual/tailcall) about tail call\n  optimization.\n\nEffect handlers are supported with the `--effects={cps,double-translation}`\nflag.\n\n## Data representation\n\nData representation differs from the usual one. Most notably, integers are 32\nbits (rather than 31 bits or 63 bits), which is their natural size in\nJavaScript, and floats are not boxed. As a consequence, marshalling, polymorphic\ncomparison, and hashing functions can yield results different from usual:\n\n- marshalling floats might generate different output. Such output should not be\n  unmarshalled using the standard ocaml runtime (native or bytecode).\n- the polymorphic hash function will not give the same results on datastructures\n  containing floats;\n- these functions may be more prone to stack overflow.\n\n| OCaml | javascript |\n| ------------- | ------------- |\n| int   | number (32bit int)  |\n| int32 | number (32bit int)  |\n| nativeint | number (32bit int)  |\n| int64 | Object (MlInt64) |\n| float | number |\n| string | string or object (MlBytes) |\n| bytes | object (MlBytes) |\n| \"immediate\" (e.g. true, false, None, ()) | number (32bit int) |\n| \"block\" | array with tag as first element (e.g. `C(1,2) =\u003e [tag,1,2]`) |\n| array | block with tag 0 (e.g. `[\\|1;2\\|] =\u003e [0,1,2]`) |\n| tuple | block with tag 0 (e.g. `(1,2) =\u003e [0,1,2]`) |\n| record | block (e.g. `{x=1;y=2} =\u003e [0,1,2]`) |\n| constructor with arguments | block (e.g. `C (1, 2) =\u003e [tag,1,2]`) |\n| module | block |\n| exception and extensible variant | block or immediate |\n| function | function |\n\n\n\n## Toplevel\n\n- [OCaml 4.04.0+BER](http://ocsigen.github.io/js_of_ocaml/toplevel/#version=4.04.0+BER)\n  see http://okmij.org/ftp/ML/MetaOCaml.html\n- [OCaml 4.06.0](http://ocsigen.github.io/js_of_ocaml/toplevel/#version=4.06.0)\n  includes Base, Core_kernel, Async_kernel, Async_js\n\n## Contents of the distribution\n\n| Filename    | Description                                  |\n| ----------- | -------------------------------------------- |\n| LICENSE     | license and copyright notice                 |\n| README      | this file                                    |\n| compiler/   | compiler                                     |\n| examples/   | small examples                               |\n| lib/        | library for interfacing with JavaScript APIs |\n| ppx/        | ppx syntax extensions                        |\n| runtime/    | runtime system                               |\n| toplevel/   | web-based OCaml toplevel                     |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focsigen%2Fjs_of_ocaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focsigen%2Fjs_of_ocaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focsigen%2Fjs_of_ocaml/lists"}