exec
Convenience helpers for the common “compile if needed, cache, then execute” workflow.
Cached bytecode is stored under fs.cache_dir(), scoped by application name.
If app: is omitted, the scope is derived from shell.program.
Functions
module path … -> std.Module
Compiles a module if needed, caches the bytecode, and loads it.
Parameters
| Name | Type | Description |
|---|---|---|
path |
(Str | fs.Path) |
Module source path. |
:name? |
Str |
Module name. Defaults to the source file stem. |
:app? |
Str |
Cache scope. Defaults to a name derived from the caller's shell.program. |
:prelude? |
Dict[Str | Sym, compile.PreludeBinding] |
Imports to bind before the source, as
compile.compile takes them. |
:inject? |
Dict[Sym, Value] |
Global bindings visible to the source when compiled and run. |
:import? |
Dict[Str | Sym, Value] |
Modules supplied by name while running. A dictionary with symbol keys is exposed as a module whose fields are its entries. |
:args? |
Iterable[Value] |
Arguments the module sees as shell.args while it loads.
Defaults to the caller's. |
:program? |
(Str | fs.Path) |
Identity the module sees as shell.program while it
loads. Defaults to the caller's. |
Example
import exec
let mod = exec.module "./lib/build.dol"
mod.main()
let plugin = exec.module "./plugin.dol" name: "plugins.build"
let injected = exec.module "./plugin.dol" inject: {answer: 42}
run path … -> Value
Compiles a script if needed, caches the bytecode, and runs it.
Parameters
| Name | Type | Description |
|---|---|---|
path |
(Str | fs.Path) |
Script path. |
:app? |
Str |
Cache scope. Defaults to a name derived from the caller's shell.program. |
:prelude? |
Dict[Str | Sym, compile.PreludeBinding] |
Imports to bind before the source, as
compile.compile takes them. |
:inject? |
Dict[Sym, Value] |
Global bindings visible to the source when compiled and run. |
:import? |
Dict[Str | Sym, Value] |
Modules supplied by name while running. A dictionary with symbol keys is exposed as a module whose fields are its entries. |
:args? |
Iterable[Value] |
Arguments the script sees as shell.args. Defaults to the
caller's. |
:program? |
(Str | fs.Path) |
Identity the script sees as shell.program. Defaults to
the caller's. |
Returns
The value of the script's final expression or early return.