home Anil Madhavapeddy, Professor of Planetary Computing  

Runtimes à la carte: crossloading native and bytecode OCaml

This is an idea proposed in 2025 as a good starter project, and is available for being worked on. It may be co-supervised with David Allsopp.

In 1998, Fabrice le Fessant released Efuns ("Emacs for Functions"), an implementation of an Emacs-like editor entire in OCaml and which included a library for loading bytecode within native code programs[1].

This nearly a decade before OCaml 3.11 would introduce Alain Frisch's native Dynlink support to OCaml. Natdynlink means that this original work has been largely forgotten, but there remain two interesting applications for being able to "cross-load" code compiled for the OCaml bytecode runtime in an OCaml native code application and vice versa:

  1. Native code OCaml applications could use OCaml as a scripting language without needing to include an assembler toolchain or solutions such as ocaml-jit.
  2. The existing bytecode REPL could use OCaml natdynlink plugins (.cmxs files) directly, allowing more dynamic programming and exploration of high-performance libraries with the ease of the bytecode interpreter, but retaining the runtime performance of the libraries themselves.

This project aims to implement these two features directly in the OCaml distribution by:

  1. Extending the bytecode version of Dynlink to be able to load .cmxs files. This feature would be validated by extending the #load directive of the bytecode toplevel ocaml to be able to load .cmxs files.
  2. Extending the native version of Dynlink to be able to load bytecode units, both from .cmo/.cma files but also directly generated in the native code program itself. This feature would be validated by adding ocaml.opt to the distribution - i.e. the bytecode toplevel compiled in native code, acting as the bytecode toplevel today, but also capable of #loading .cmxs files, and still converting toplevel phrases for execution by the bytecode interpreter

This is a good student project for anyone seeking to gain more familiarity with a "real" compiler codebase, and to learn more about how these work towards (e.g.) hacking on webassembly in the future.

  1. A version can be found at jrrk/efuns

    ↩︎︎
# 1st Apr 2025   iconideas effects functional idea-available idea-beginner ocaml urop

Related News