pub fn eval_main(instance: &Value, ctx: &Ctx) -> Result<Option<Value>, Raised>Expand description
Evaluate a module instance’s body — the __main its source declared — in
the module’s own environment, and hand back the result. Ok(None) for a
module that declares none, which is what a library is.
This is the whole of what makes a module runnable, and it is a call rather
than a phase of loading: crate::load_module instantiates every module it
reaches and evaluates none of them, so a __main in an imported module is
inert and only the module a runner was pointed at ever gets here. That is the
Python if __name__ == "__main__" semantics, arrived at structurally.
The body runs in the instance’s own Module terminal, so
it reaches the module’s members exactly as an item body does. It is not a
member itself, so it claims no reserved id: a closure it builds mints one from
ctx the ordinary way. A non-module instance raises .not_a_module.
The result is handed back rather than interpreted. What a runner does with it
— apply it to the root capability, report a still-partial closure — is the
runner’s policy; see docs/done/2026-08-14_elly-run.md.