• Stars
    star
    136
  • Rank 260,457 (Top 6 %)
  • Language
    OCaml
  • License
    GNU Affero Genera...
  • Created over 2 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hotcaml: an interpreter with watching and reloading

Hotcaml: an OCaml interpreter with watching and reloading

Hotcaml is an OCaml interpreter that starts from a source file and loads its dependencies. When one of the source files changes and passes the typechecker, it is reloaded, along with all of its reverse dependencies.

To get started, clone the repository and type make. Two frontends are built: hotcaml.exe and hotcaml_lwt.exe.

Starting hotcaml

An hotcaml invocation takes three kinds of arguments: hotcaml [ -package pkg ]* [ -I path ]* entrypoint.ml*

The pkgs should be valid findlib package names. They will be loaded in order during startup.

The paths are paths that will be looked up for dependencies.

Finally, the entrypoints are the actual code that we want to interpret.

Each entrypoint is loaded and interpreted in order. Dependencies of an entrypoint are looked up in the paths and then in the loaded packages.

Once execution of the entrypoints is done, the interpreter will watch the disk for changes. If one of the source files changes, it is reloaded and interpretation resumes from this module, followed by all of its reverse dependencies.

If one of the dependencies does not typecheck, reloading is postponed until all errors are solved.

Synchronous and asynchronous frontends

Contrary to the normal execution of an OCaml program, modules can be loaded and unloaded, multiple times during the execution.

The synchronous hotcaml only looks for changes after execution finishes. This is not really convenient for interactive programs, where we might want to reload during execution rather than after.

hotcaml_lwt provides an asynchronous frontend: lwt threads continue to execute after loading, and modules can be reloaded concurrentlly.

Observing reload process

The Hotlink module can be used to customize behavior of hot-loaded programs.

Hotlink.is_hot_loaded () : bool is true only when called from a module that has been hot-loaded.

Hotlink.is_hot_unloaded () : bool is true only when called from a module that was hot-loaded and has now been unloaded.

Hotlink.on_unload : (unit -> unit) -> unit allows to register a callback that will be invoked when an hot-loaded module is unloaded.

Hotlink.on_unload_or_at_exit : (unit -> unit) -> unit calls the callback either during unloading or when exiting the program.

Cold execution

In a normal, "cold" execution, the Hotlink module exhibits a compatible, reasonable, behavior:

  • Hotlink.is_hot_loaded and Hotlink.is_hot_unloaded are always false
  • Hotlink.on_unload does nothing
  • Hotlink.on_unload_or_at_exit behaves like at_exit

This allows modules that are compatible with both classical OCaml and with hotcaml, and adjusts their behavior based on the situation.

More Repositories

1

lwd

Lightweight document
OCaml
117
star
2

insydious

Unlock 10 digits BIOS passwords
OCaml
100
star
3

wall

(mirror) A vector graphics renderer like NanoVG in OCaml
OCaml
75
star
4

grenier

Misc algorithms in OCaml (HyperLogLog, jump consistent hashing)
OCaml
62
star
5

cuite

(mirror) OCaml bindings to Qt toolkit.
OCaml
62
star
6

goo

Cross-runtime object interface generation
OCaml
36
star
7

owee

OCaml library to work with DWARF format
OCaml
33
star
8

ocamp

Reactive programming… in the shell
OCaml
30
star
9

ocp-indent-vim

Integration of ocp-indent to vim.
Python
28
star
10

merlin-extend

SDK to extend Merlin
OCaml
28
star
11

cmon

A library for printing OCaml values with sharing
OCaml
25
star
12

inuit

Make interactive text-oriented user-interfaces for OCaml
OCaml
23
star
13

sturgeon

A toolkit for communicating with Emacs from OCaml
OCaml
20
star
14

texpresso

TeXpresso: live rendering and error reporting for LaTeX
C
20
star
15

lrgrep

Menhir polishing toolbox, for experienced druids
OCaml
19
star
16

camlroot

A safer C FFI for OCaml
C
18
star
17

distwit

Distribute/marshal instances of ocaml extensible variant types and exceptions
OCaml
17
star
18

stb_truetype

OCaml bindings to stb_truetype, a public domain truetype font rasterizer
C
11
star
19

assimp

Bindings to Assimp, a 3D assets (mesh, material, scenes) importer
OCaml
11
star
20

autoprinter

proof-of-concept to auto-install printer functions in the OCaml toplevel
OCaml
11
star
21

distheap

Heterogeneous heap
OCaml
10
star
22

ibutsu

C
10
star
23

Ztl

Z3 Type Layer: a strongly-typed interface to Z3
OCaml
9
star
24

stb_image

OCaml bindings to stb_image, a public domain image loader
C
9
star
25

pdfmagick

A small tool to split/cut/merge pdf files
OCaml
9
star
26

melodious

Ocsigen powered media player
OCaml
9
star
27

ocaml-introspect

Generic value printer for OCaml (to be used with tagl branch)
OCaml
9
star
28

ttx

Typedtree related tools
OCaml
8
star
29

vimbufsync

Collection of heuristics to help quickly detect modifications in vim buffers
Python
8
star
30

ocaml-recovery-parser

A simple fork of OCaml parser with support for error recovery
OCaml
8
star
31

ppx_xmatch

Mess with the semantics of pattern matching :-)
OCaml
7
star
32

stb_image_write

OCaml bindings to stb_image_write, a public domain image writer
C
7
star
33

strongenv

OCaml
7
star
34

menhir

Unofficial repository. Experimentations around menhir parser generator
OCaml
6
star
35

balanced-trees

Simple implementation of logarithmic balanced trees
OCaml
6
star
36

ocamllex-refill

Experiments around ocamllex
OCaml
4
star
37

colorfilter

A gnome extension to desaturate and filter colors
JavaScript
4
star
38

ocamlilex

A version of OCamllex that lets you access the last observed character in the buffer (useful for incrementalizing a lexer)
OCaml
3
star
39

recel

Pixelart upscaling toolkit
C
2
star
40

timetrail

A small tool to track how your virtual time is spent
OCaml
2
star
41

mulet

OCaml
1
star
42

ml-test

Exploring custom extensions to lambda calculus
Coq
1
star