This commit is contained in:
c-cube 2021-04-03 22:55:25 +00:00
parent 39b037c85a
commit 527e7d30a4
2 changed files with 13 additions and 2 deletions

View file

@ -1,2 +1,2 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Bitfield (containers.Containers_codegen.Bitfield)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../../index.html">containers</a> &#x00BB; <a href="../index.html">Containers_codegen</a> &#x00BB; Bitfield</nav><h1>Module <code>Containers_codegen.Bitfield</code></h1><h3 id="generate-efficient-bitfields-that-fit-in-an-integer"><a href="#generate-efficient-bitfields-that-fit-in-an-integer" class="anchor"></a>Generate efficient bitfields that fit in an integer</h3></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code></dt></dl><dl><dt class="spec value" id="val-make"><a href="#val-make" class="anchor"></a><code><span class="keyword">val</span> make : <span>?&#8288;emit_failure_if_too_wide:bool</span> <span>&#45;&gt;</span> <span>name:string</span> <span>&#45;&gt;</span> unit <span>&#45;&gt;</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Make a new bitfield with the given name.</p><dl><dt>parameter name</dt><dd><p>the name of the generated type</p></dd></dl><dl><dt>parameter emit_failure_if_too_wide</dt><dd><p>if true, generated code includes a runtime assertion that <span class="xref-unresolved" title="unresolved reference to &quot;Sys.int_size&quot;"><code>Sys</code>.int_size</span> is wide enough to support this type</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-field_bit"><a href="#val-field_bit" class="anchor"></a><code><span class="keyword">val</span> field_bit : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> unit</code></dt><dt class="spec value" id="val-field_int"><a href="#val-field_int" class="anchor"></a><code><span class="keyword">val</span> field_int : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>width:int</span> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> unit</code></dt><dt class="spec value" id="val-total_width"><a href="#val-total_width" class="anchor"></a><code><span class="keyword">val</span> total_width : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dt class="spec value" id="val-gen_mli"><a href="#val-gen_mli" class="anchor"></a><code><span class="keyword">val</span> gen_mli : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="../index.html#type-code">code</a></code></dt><dt class="spec value" id="val-gen_ml"><a href="#val-gen_ml" class="anchor"></a><code><span class="keyword">val</span> gen_ml : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="../index.html#type-code">code</a></code></dt></dl></div></body></html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Bitfield (containers.Containers_codegen.Bitfield)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../../index.html">containers</a> &#x00BB; <a href="../index.html">Containers_codegen</a> &#x00BB; Bitfield</nav><h1>Module <code>Containers_codegen.Bitfield</code></h1><h3 id="generate-efficient-bitfields-that-fit-in-an-integer"><a href="#generate-efficient-bitfields-that-fit-in-an-integer" class="anchor"></a>Generate efficient bitfields that fit in an integer</h3></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code></dt></dl><dl><dt class="spec value" id="val-make"><a href="#val-make" class="anchor"></a><code><span class="keyword">val</span> make : <span>?&#8288;emit_failure_if_too_wide:bool</span> <span>&#45;&gt;</span> <span>name:string</span> <span>&#45;&gt;</span> unit <span>&#45;&gt;</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Make a new bitfield with the given name.</p><dl><dt>parameter name</dt><dd><p>the name of the generated type</p></dd></dl><dl><dt>parameter emit_failure_if_too_wide</dt><dd><p>if true, generated code includes a runtime assertion that <span class="xref-unresolved" title="unresolved reference to &quot;Sys.int_size&quot;"><code>Sys</code>.int_size</span> is wide enough to support this type</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-field_bit"><a href="#val-field_bit" class="anchor"></a><code><span class="keyword">val</span> field_bit : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> unit</code></dt><dd><p><code>field_bit ty name</code> adds a field of size <code>1</code> to the bitfield <code>ty</code>, with name <code>name</code>. The generate code will provide get/set for a boolean.</p></dd></dl><dl><dt class="spec value" id="val-field_int"><a href="#val-field_int" class="anchor"></a><code><span class="keyword">val</span> field_int : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>width:int</span> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> unit</code></dt><dd><p><code>field_int ty name ~width</code> adds a field of size <code>width</code> to the bitfield with name <code>name</code>. The accessors will be for integers of <code>width</code> bits, and the setter might assert that the provided integer fits.</p></dd></dl><dl><dt class="spec value" id="val-total_width"><a href="#val-total_width" class="anchor"></a><code><span class="keyword">val</span> total_width : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p>Total width in bits of the given bitfield.</p></dd></dl><dl><dt class="spec value" id="val-gen_mli"><a href="#val-gen_mli" class="anchor"></a><code><span class="keyword">val</span> gen_mli : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="../index.html#type-code">code</a></code></dt><dd><p>Generate code for the type signature for the given bitfield</p></dd></dl><dl><dt class="spec value" id="val-gen_ml"><a href="#val-gen_ml" class="anchor"></a><code><span class="keyword">val</span> gen_ml : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="../index.html#type-code">code</a></code></dt><dd><p>Generate code for the implementation for the given bitfield</p></dd></dl></div></body></html>

View file

@ -1,2 +1,13 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Containers_codegen (containers.Containers_codegen)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../index.html">containers</a> &#x00BB; Containers_codegen</nav><h1>Module <code>Containers_codegen</code></h1><h2 id="code-generators"><a href="#code-generators" class="anchor"></a>Code generators</h2></header><div class="spec module" id="module-Fmt"><a href="#module-Fmt" class="anchor"></a><code><span class="keyword">module</span> Fmt = <a href="../CCFormat/index.html">CCFormat</a></code></div><dl><dt class="spec type" id="type-code"><a href="#type-code" class="anchor"></a><code><span class="keyword">type</span> code</code></dt></dl><dl><dt class="spec module" id="module-Code"><a href="#module-Code" class="anchor"></a><code><span class="keyword">module</span> <a href="Code/index.html">Code</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></dt><dd></dd></dl><dl><dt class="spec module" id="module-Bitfield"><a href="#module-Bitfield" class="anchor"></a><code><span class="keyword">module</span> <a href="Bitfield/index.html">Bitfield</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></dt><dd></dd></dl><dl><dt class="spec value" id="val-emit_file"><a href="#val-emit_file" class="anchor"></a><code><span class="keyword">val</span> emit_file : string <span>&#45;&gt;</span> <span><a href="index.html#type-code">code</a> list</span> <span>&#45;&gt;</span> unit</code></dt><dt class="spec value" id="val-emit_chan"><a href="#val-emit_chan" class="anchor"></a><code><span class="keyword">val</span> emit_chan : Stdlib.out_channel <span>&#45;&gt;</span> <span><a href="index.html#type-code">code</a> list</span> <span>&#45;&gt;</span> unit</code></dt><dt class="spec value" id="val-emit_string"><a href="#val-emit_string" class="anchor"></a><code><span class="keyword">val</span> emit_string : <span><a href="index.html#type-code">code</a> list</span> <span>&#45;&gt;</span> string</code></dt></dl></div></body></html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Containers_codegen (containers.Containers_codegen)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../index.html">containers</a> &#x00BB; Containers_codegen</nav><h1>Module <code>Containers_codegen</code></h1><h2 id="code-generators"><a href="#code-generators" class="anchor"></a>Code generators</h2><p>The code generator library is designed to be used from a build system (for example, from <code>dune</code>) to generate efficient code for features that are harder to provide at runtime.</p><p>The idea is that the build system should invoke some OCaml script that depends on <code>containers.codegen</code>; the script uses the DSL below to describe what code to generate (e.g. a description of a bitfield type) and emits a <code>.ml</code> file (and possibly a <code>.mli</code> file).</p><p>For example, the build script might contain:</p><pre><code class="ml">module CG = Containers_codegen
let () =
let module B = CG.Bitfield in
let b = B.make ~name:&quot;t&quot; () in
B.field_bit b &quot;x&quot;;
B.field_bit b &quot;y&quot;;
B.field_bit b &quot;z&quot;;
B.field_int b ~width:5 &quot;foo&quot;;
CG.emit_file &quot;foo.mli&quot; (B.gen_mli b);
CG.emit_file &quot;foo.ml&quot; (B.gen_ml b);
()</code></pre><p>and this will produce <code>foo.ml</code> and <code>foo.mli</code> with a bitfield containing <code>x</code>, <code>y</code>, and <code>z</code>.</p></header><div class="spec module" id="module-Fmt"><a href="#module-Fmt" class="anchor"></a><code><span class="keyword">module</span> Fmt = <a href="../CCFormat/index.html">CCFormat</a></code></div><dl><dt class="spec type" id="type-code"><a href="#type-code" class="anchor"></a><code><span class="keyword">type</span> code</code></dt></dl><dl><dt class="spec module" id="module-Code"><a href="#module-Code" class="anchor"></a><code><span class="keyword">module</span> <a href="Code/index.html">Code</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></dt><dd></dd></dl><dl><dt class="spec module" id="module-Bitfield"><a href="#module-Bitfield" class="anchor"></a><code><span class="keyword">module</span> <a href="Bitfield/index.html">Bitfield</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></dt><dd></dd></dl><dl><dt class="spec value" id="val-emit_file"><a href="#val-emit_file" class="anchor"></a><code><span class="keyword">val</span> emit_file : string <span>&#45;&gt;</span> <span><a href="index.html#type-code">code</a> list</span> <span>&#45;&gt;</span> unit</code></dt><dd><p><code>emit_file file cs</code> emits code fragments <code>cs</code> into the given file at path <code>file</code></p></dd></dl><dl><dt class="spec value" id="val-emit_chan"><a href="#val-emit_chan" class="anchor"></a><code><span class="keyword">val</span> emit_chan : Stdlib.out_channel <span>&#45;&gt;</span> <span><a href="index.html#type-code">code</a> list</span> <span>&#45;&gt;</span> unit</code></dt><dt class="spec value" id="val-emit_string"><a href="#val-emit_string" class="anchor"></a><code><span class="keyword">val</span> emit_string : <span><a href="index.html#type-code">code</a> list</span> <span>&#45;&gt;</span> string</code></dt></dl></div></body></html>