github ↗
docs menu

Module Renderer.Compiler

Compilers: source to binary.

A compiler turns the source a renderer writes into the bytes of a program. Compiling runs nothing: a compiler may call a toolchain, and returns its output.

#exception Compile_error of string

Raised by a compiler that rejects its source, with the toolchain's message.

#type t

The type for compilers.

#val v : ?cachekey:(unit -> string) -> ?disassemble:(string -> unit) -> (string -> string) -> t

v ~cachekey ~disassemble compile is the compiler that compiles a source with compile. disassemble prints a binary as instructions on standard output; it defaults to printing nothing. cachekey () names everything besides a source that determines its binary: the toolchain, its version and its options. The caches of programs and searches key on it, and binaries are kept in the Helpers.Diskcache table it names while the setting Setting.ccache holds. cachekey is called when the name is first needed, and again only after it raised.

#val batch : ?cachekey:(unit -> string) -> ?disassemble:(string -> unit) -> (string list -> string list) -> t

batch ~cachekey ~disassemble compile is v's compiler, whose compile is given several sources at once and returns their binaries in their order. Each binary is the one compile makes of its source given alone.

#val cachekey : t -> string option

cachekey c is the name of c's toolchain and options, if c has one: the table of its binaries, whether or not they are kept.

Raises what c's cachekey function raises.

#val compile : t -> string -> string

compile c src is src compiled by c.

Raises Compile_error if c rejects src.

#val kept : t -> string -> string option

kept c src is the binary of src held in c's disk cache table while Setting.ccache holds, if any: what compile_cached returns without compiling. An entry that does not read, or cannot be read, is none.

Raises what cachekey raises.

#val compile_cached : t -> string -> string

compile_cached c src is the binary of src held in c's disk cache table, or else compile c src (compile), which is then kept there, while Setting.ccache holds; otherwise it is compile c src. An entry that does not read, or cannot be read, is compiled anew and replaced.

Raises Compile_error as compile, what cachekey raises, and Invalid_argument naming src if it must be compiled under Setting.assert_compile.

#val compile_all : t -> string list -> string list

compile_all c srcs is List.map (compile_cached c) srcs, with the sources that c's disk cache does not hold, each once, compiled by one call of c's function: one of batch's compiles them in one run of its toolchain.

Raises as compile_cached does, for the first of srcs that raises.

#val disassemble : t -> string -> unit

disassemble c lib prints the binary lib as instructions on standard output, if c can.