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.
While the module initializes, input ends immediately and output is discarded. The caller's input and output are restored when initialization returns or raises. Exported functions use the channels of their caller when invoked.
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? |
BaseDict[Str | Sym, compile.PreludeBinding] |
Imports to bind before the source, as
compile.compile takes them. |
:inject? |
BaseDict[Sym, Value] |
Global bindings visible to the source when compiled and run. |
:import? |
BaseDict[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. |
Errors
Raises std.TypeError if the loaded bytecode returns a value
other than a module.
Example
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.
The script uses the caller's input and output. Its import handlers run with input ended and output discarded.
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? |
BaseDict[Str | Sym, compile.PreludeBinding] |
Imports to bind before the source, as
compile.compile takes them. |
:inject? |
BaseDict[Sym, Value] |
Global bindings visible to the source when compiled and run. |
:import? |
BaseDict[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. |
< |
Iter[Value] |
|
> |
Sink[Value] |
Returns
The value of the script's final expression or early return.