pub struct Ctx { /* private fields */ }Expand description
The long-lived state of an evaluation, the equivalent of a JS realm: the
unique-id source for closure identities, the builtin module cache, the
environment free list, and the module loader — a resolver plus the cache of
modules loaded through it (load).
A host creates one per program run, per Python realm object or per
playground session, and passes &Ctx to every call. Imports are still
resolved before evaluation, and loaded modules are Rc-held values. See
docs/done/2026-10-02_elly-host.md.
Implementations§
Source§impl Ctx
impl Ctx
Sourcepub fn new() -> Self
pub fn new() -> Self
A context with a fresh id source and no module resolver, so every import
fails. Used by crate::eval::eval and crate::eval::apply.
Sourcepub fn with_resolver(resolver: Box<dyn ModuleResolver>) -> Self
pub fn with_resolver(resolver: Box<dyn ModuleResolver>) -> Self
A context whose imports are served by resolver.
Sourcepub fn with_ids(ids: u64) -> Self
pub fn with_ids(ids: u64) -> Self
A context resuming an id source at ids so identities continue from
an earlier context. Needed only when values outlive the Ctx that made
them and a fresh one runs them: without it, a module’s reserved id block
and later closure ids could alias, and __eq would call them equal.
Hosts keep one long-lived Ctx instead. The module bench is the
remaining user: it wants a fresh context per timed pass, as run_eval
gets one.
Source§impl Ctx
impl Ctx
Sourcepub fn load(&self, spec: &str) -> Result<Value, LoadError>
pub fn load(&self, spec: &str) -> Result<Value, LoadError>
Loads a module and its import graph through this context’s resolver,
returning the instance for spec. A module already in the cache is
reused, so two loads that reach one module share its instance.
Without a resolver, every spec is LoadError::NotFound.
Loading is not re-entrant: nothing evaluates while a graph is instantiated, so no host callback can run a nested load.