Schooner.Compiled (schooner v1.2.0)

Copy Markdown View Source

Opaque artifact produced by Schooner.compile/2 and consumed by Schooner.run_compiled/3.

A %Compiled{} holds the analysed core IR of a program together with the runtime variable bindings that the program's (import ...) declarations resolved to at compile time. Macros are already gone — let, cond, when, case, etc. have been rewritten into quote / if / lambda / define / define-values / begin / letrec* / quasiquote / guard / application / variable references — and those core forms have been pre-analysed into the evaluator's tagged IR, so lambda parameter parsing and body desugaring are not repeated per run.

Reuse semantics

The same %Compiled{} can be passed to Schooner.run_compiled/3 many times against many Schooner.Environments, which is what makes it worth caching. The captured var_bindings are re-applied to the runtime env on every call; macros expanded at compile time stay expanded.

Macro expansion is fixed at compile time: running the program against an Environment whose macros differ from the one passed to compile does not re-expand it. Variable bindings can differ freely, so host primitives can be swapped between runs. The program's own (import ...) bindings are re-applied on each run and shadow any same-named binding in the runtime environment.

The IR records the source position of each application and variable reference, and the struct keeps the :file and :debug options given to Schooner.compile/3, so errors raised by Schooner.run_compiled/3 carry the same locations as those raised by Schooner.eval/3. The artifact is still plain data. Artifacts built by an earlier Schooner version must be recompiled.

Opacity

Embedders must treat the struct as opaque. Pattern-matching on its internals is unsupported, because their shape changes with the evaluator's internal representation.

Summary

Types

t()

@opaque t()