From 527e7d30a41ece249413b475f5979d2a79e7a94c Mon Sep 17 00:00:00 2001 From: c-cube Date: Sat, 3 Apr 2021 22:55:25 +0000 Subject: [PATCH] deploy: 25c5eda5281f3b0a0d467d1ff87b2870639ca255 --- .../Containers_codegen/Bitfield/index.html | 2 +- dev/containers/Containers_codegen/index.html | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dev/containers/Containers_codegen/Bitfield/index.html b/dev/containers/Containers_codegen/Bitfield/index.html index 938adf8b..356f47ec 100644 --- a/dev/containers/Containers_codegen/Bitfield/index.html +++ b/dev/containers/Containers_codegen/Bitfield/index.html @@ -1,2 +1,2 @@ -Bitfield (containers.Containers_codegen.Bitfield)

Module Containers_codegen.Bitfield

Generate efficient bitfields that fit in an integer

type t
val make : ?⁠emit_failure_if_too_wide:bool -> name:string -> unit -> t

Make a new bitfield with the given name.

parameter name

the name of the generated type

parameter emit_failure_if_too_wide

if true, generated code includes a runtime assertion that Sys.int_size is wide enough to support this type

val field_bit : t -> string -> unit
val field_int : t -> width:int -> string -> unit
val total_width : t -> int
val gen_mli : t -> code
val gen_ml : t -> code
\ No newline at end of file +Bitfield (containers.Containers_codegen.Bitfield)

Module Containers_codegen.Bitfield

Generate efficient bitfields that fit in an integer

type t
val make : ?⁠emit_failure_if_too_wide:bool -> name:string -> unit -> t

Make a new bitfield with the given name.

parameter name

the name of the generated type

parameter emit_failure_if_too_wide

if true, generated code includes a runtime assertion that Sys.int_size is wide enough to support this type

val field_bit : t -> string -> unit

field_bit ty name adds a field of size 1 to the bitfield ty, with name name. The generate code will provide get/set for a boolean.

val field_int : t -> width:int -> string -> unit

field_int ty name ~width adds a field of size width to the bitfield with name name. The accessors will be for integers of width bits, and the setter might assert that the provided integer fits.

val total_width : t -> int

Total width in bits of the given bitfield.

val gen_mli : t -> code

Generate code for the type signature for the given bitfield

val gen_ml : t -> code

Generate code for the implementation for the given bitfield

\ No newline at end of file diff --git a/dev/containers/Containers_codegen/index.html b/dev/containers/Containers_codegen/index.html index 90d467bf..f89852cb 100644 --- a/dev/containers/Containers_codegen/index.html +++ b/dev/containers/Containers_codegen/index.html @@ -1,2 +1,13 @@ -Containers_codegen (containers.Containers_codegen)

Module Containers_codegen

Code generators

module Fmt = CCFormat
type code
module Code : sig ... end
module Bitfield : sig ... end
val emit_file : string -> code list -> unit
val emit_chan : Stdlib.out_channel -> code list -> unit
val emit_string : code list -> string
\ No newline at end of file +Containers_codegen (containers.Containers_codegen)

Module Containers_codegen

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.

module Fmt = CCFormat
type code
module Code : sig ... end
module Bitfield : sig ... end
val emit_file : string -> code list -> unit

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

val emit_chan : Stdlib.out_channel -> code list -> unit
val emit_string : code list -> string
\ No newline at end of file