package containers

  1. Overview
  2. Docs
A modular, clean and powerful extension of the OCaml standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v3.9.tar.gz
md5=c54431781906065ead3a089883f94726
sha512=8c954cb5ff01dc73a4e04ce2ef8fb5ad5162f16b2e4b2463501dd60c428d388c03c5b641c62b5876cd0d5ac5dc244d6a44d4d92a18525a03bdbf9cca82321272

doc/containers.codegen/Containers_codegen/index.html

Module Containers_codegenSource

Code generators

The code generator library is designed to be used from a build system (for example, from dune) to generate efficient code for features that are harder to provide at runtime.

The idea is that the build system should invoke some OCaml script that depends on containers.codegen; the script uses the DSL below to describe what code to generate (e.g. a description of a bitfield type) and emits a .ml file (and possibly a .mli file).

For example, the build script might contain:

module CG = Containers_codegen
let () =
  let module B = CG.Bitfield in
  let b = B.make ~name:"t" () in
  B.field_bit b "x";
  B.field_bit b "y";
  B.field_bit b "z";
  B.field_int b ~width:5 "foo";

  CG.emit_file "foo.mli" (B.gen_mli b);
  CG.emit_file "foo.ml" (B.gen_ml b);
  ()

and this will produce foo.ml and foo.mli with a bitfield containing x, y, and z.

Sourcemodule Fmt = CCFormat
Sourcetype code
Sourcemodule Code : sig ... end
Sourcemodule Bitfield : sig ... end
Sourceval emit_file : string -> code list -> unit

emit_file file cs emits code fragments cs into the given file at path file

Sourceval emit_chan : out_channel -> code list -> unit
Sourceval emit_string : code list -> string
OCaml

Innovation. Community. Security.

On This Page
  1. Code generators