Skip to main content

Ctx

Struct Ctx 

Source
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

Source

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.

Source

pub fn with_resolver(resolver: Box<dyn ModuleResolver>) -> Self

A context whose imports are served by resolver.

Source

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

pub fn ids_used(&self) -> u64

Returns the current id source value to seed a successor context (see with_ids).

Source§

impl Ctx

Source

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.

Source

pub fn load_source(&self, name: &str, src: &str) -> Result<Value, LoadError>

Loads a module from src under name, resolving its imports through this context’s resolver. The caller supplied the text, so it replaces whatever name held in the cache — the explicit reload.

Source

pub fn instances(&self) -> Ref<'_, Instances>

The modules loaded so far, by canonical name.

Trait Implementations§

Source§

impl Default for Ctx

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Ctx

Frees the cells iteratively: dropping the list whole would recurse once per cell.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Ctx

§

impl !RefUnwindSafe for Ctx

§

impl !Send for Ctx

§

impl !Sync for Ctx

§

impl !UnwindSafe for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.