Skip to content

Instantly share code, notes, and snippets.

View xavierleroy's full-sized avatar

Xavier Leroy xavierleroy

View GitHub Profile
@xavierleroy
xavierleroy / unambregexp.ml
Created April 3, 2024 17:22
Non-ambiguity test for regular expressions, with application to ocamlopt's name mangling schemas
open Printf
(* Regular expressions *)
type regexp =
| Empty
| Epsilon
| Charclass of char * char
| Seq of regexp * regexp
| Alt of regexp * regexp
@xavierleroy
xavierleroy / expand_module_aliases.py
Created December 2, 2022 10:30
Python reimplementation of stdlib/expand_module_aliases.awk
#!/usr/bin/python3
import re, argparse
def transform(filename, ocamldoc):
"""Preprocess MODULE_ALIASES section and @since tags in the given file.
Put the MODULE_ALIASES section at end of file in the form that the
compiler expects (module Foo = Stdlib__Bar).
Add @canonical tags unless ocamldoc argument is true.
@xavierleroy
xavierleroy / add-stdlib-prefix.py
Created December 2, 2022 10:28
Python reimplementation of sak add-stdlib-prefix
#!/usr/bin/python3
import sys
def add_stdlib_prefix(name):
""" "stdlib" and names beginning "camlinternal" are returned unchanged.
All other names are prefixed "stdlib__" with the original name capitalized
(i.e. "foo" becomes "stdlib__Foo"). """
if name == "stdlib" or name.startswith("camlinternal"):
return name
@xavierleroy
xavierleroy / gcbench.ml
Last active October 23, 2022 17:02
A simple benchmark that exercises garbage collection and `caml_modify`. Inspired from Java code originally written by Hans Boehm.
type tree =
| Leaf
| Node of tree * int * tree
type itree =
| ILeaf
| INode of { mutable left: itree; mutable data: int; mutable right: itree }
let rec maketree depth =
if depth <= 0
@xavierleroy
xavierleroy / camlstate.ml
Created October 23, 2022 16:54
Measure the time taken to evaluate Caml_state
external camlstate: int -> unit = "camlstate"
let _ =
camlstate (int_of_string Sys.argv.(1))