Cont

Enum Cont 

Source
pub enum Cont {
Show 20 variants BinOpRight { env: Env, op: BinOpKind, e2: RcExp, }, BinOpFinish { op: BinOpKind, v1: Val, }, UnOpFinish { op: UnOpKind, }, IfDispatch { env: Env, t: RcExp, f: RcExp, }, LetBody { env: Env, e2: RcExp, }, LiftRefDispatch { env: Env, e2: RcExp, }, LiftRefPersist, RunDispatch { env: Env, e: RcExp, }, TransRight { env: Env, env_exp: RcExp, }, TransFinish { e_val: Val, }, EvalmsRight { env: Env, expr_exp: RcExp, }, EvalmsFinish { env_val: Val, }, ForceCode { mode: ForceMode, resume: ForceCodeResume, }, ReifyVExit { saved: ScopeSnapshot, resume: ReifyResume, }, RunNowExit { saved_level: usize, }, LiftCloFinish { fun_level: usize, resume: ForceCodeResume, }, CatchExit { saved: ScopeSnapshot, }, ReadFinish, ReadFileFinish, ThrowFinish,
}
Expand description

An entry on the kont stack — represents pending work to resume when the current sub-evaluation produces a Val.

Each variant either:

  • Holds onto an unevaluated subexpression that becomes the next Mode::Eval (operand sequencing), or
  • Holds enough state to dispatch on the resumed Val and either produce a final Val (Class O), or
  • Holds a ScopeSnapshot for restoring staging state on exit from a reify-like region (Class S).

Variants§

§

BinOpRight

We just evaluated the first operand; resumed Val becomes v1. We need to evaluate e2 next, then dispatch via BinOpKind. Pushes BinOpFinish { op, v1 } on resume.

Fields

§env: Env

Environment for evaluating e2.

§op: BinOpKind

Which binary form this is.

§e2: RcExp

The unevaluated second operand.

§

BinOpFinish

Both operands have been evaluated. Resumed Val is v2. Dispatch on (v1, v2) per BinOpKind semantics.

Fields

§op: BinOpKind

Which binary form this is.

§v1: Val

The already-evaluated first operand.

§

UnOpFinish

We just evaluated the operand. Dispatch on the resumed Val.

Fields

§op: UnOpKind

Which unary form this is.

§

IfDispatch

We evaluated c. If Cst, tail-evaluate the chosen branch. If Code, push a reify scope to compile both branches and reflect. Else TypeError.

Fields

§env: Env

Environment for evaluating the chosen branch (or both, staged).

§t: RcExp

The unevaluated true branch.

§f: RcExp

The unevaluated false branch.

§

LetBody

We evaluated e1; the resumed Val becomes the new top of the environment, and we tail-step into e2. This is operand eval on the kont (Class O) followed by a tail step (Class T) — Let is a hybrid form whose flow class differs across its two operands.

Fields

§env: Env

Environment the bound value is pushed onto.

§e2: RcExp

The unevaluated body.

§

LiftRefDispatch

We evaluated e1. LiftRef’s dispatch on v1 decides how to evaluate e2 — staged inside a reify scope (if v1 is Code), or normally followed by cross-stage persistence (otherwise). This differs from the standard binop shape (which always evaluates e2 normally), so LiftRef has its own dedicated continuation.

Fields

§env: Env

Environment for evaluating e2.

§e2: RcExp

The unevaluated second operand.

§

LiftRefPersist

LiftRef with non-Code e1: e2 just evaluated. Persist the value across stages as (code (proc v)) — base.scm:151’s lift-ref is thunk-based value persistence ((code (proc ,e1 ,(lambda (ignore) (e2))))), never a structural lift. Value identity is preserved: closures are not η-recompiled, runtime pairs residualize fine.

§

RunDispatch

We evaluated b. If Code, push reify scope to compile e and reflect Run. Else, enter run-now: snapshot scope, reset, reify-then-reifyv.

Fields

§env: Env

Environment for evaluating e.

§e: RcExp

The unevaluated expression to run.

§

TransRight

We evaluated e_exp. Now eval env_exp, then walk the env list and call staging::trans + val_cons_to_exp.

Fields

§env: Env

Environment for evaluating env_exp.

§env_exp: RcExp

The unevaluated name-environment argument.

§

TransFinish

Both args evaluated; walk env_val into a NameEnv list and call trans.

Fields

§e_val: Val

The already-evaluated expression argument.

§

EvalmsRight

We evaluated env_list_exp. Now eval expr_exp, then walk env list and recurse into evalmsg with explicit env.

Fields

§env: Env

Environment for evaluating expr_exp.

§expr_exp: RcExp

The unevaluated expression argument.

§

EvalmsFinish

Both args evaluated; walk env_val into Env, then evalmsg the expr.

Fields

§env_val: Val

The already-evaluated environment-list argument.

§

ForceCode

Force the resumed Val to an Exp per mode, then dispatch resume.

Fields

§mode: ForceMode

Strict (force-code) or lenient (lift) coercion.

§resume: ForceCodeResume

What to assemble from the forced Exp.

§

ReifyVExit

Resume from a reifyv-style scope: the resumed Val is folded with the accumulated block. If block is empty, return the val as-is; otherwise wrap the val (force_code’d via the kont) into a Val::Code(Let-chain). Restore snapshot.

Fields

§saved: ScopeSnapshot

Staging state to restore on exit.

§resume: ReifyResume

What surrounding staged Exp the result slots into.

§

RunNowExit

We’re inside a run_now: the level counter has been bumped and we are about to do the inner reifyc → outer reifyv dance. RunNowExit fires when both phases complete and restores level.

Fields

§saved_level: usize

The tower level to restore when the run completes.

§

LiftCloFinish

After the body of a lifted Clo finishes evaluation and has been force_code’d to an Exp inside the inner reify scope, wrap that Exp in Lam(...), reflect into the surrounding block. The resulting Code(Var(fun_level)) is then dispatched per resume.

Fields

§fun_level: usize

The fresh variable the memoised Lam was reflected as.

§resume: ForceCodeResume

What to assemble from the resulting Code(Var(fun_level)).

§

CatchExit

Catch(e): marks an error-handling boundary on the kont. Fires in two modes:

  • Success: step_apply runs this arm with the body’s val and packages it as (ok val ()). Saved snapshot is restored, discarding any emitted block bindings (consistent with run_scope’s discard-on-restore semantics for Catch).
  • Error: the machine’s unwind walks the kont, restores each popped state-carrying cont, stops at CatchExit, restores its snapshot, and packages the error message as (error msg ()).

Fields

§saved: ScopeSnapshot

Staging state to restore on either success or unwind.

§

ReadFinish

Read(prompt_exp): after evaluating the prompt arg, format it, call into IO, and parse the resulting string.

§

ReadFileFinish

ReadFile(path_exp): after evaluating the path arg (must be a Sym), read the file, parse all forms, sug each, return them as a list of data.

§

ThrowFinish

Throw(payload_exp): after evaluating the payload, raise NarjuError::Throw(payload) — the run loop routes it through unwind_to_catch, which delivers the payload structurally to the nearest CatchExit.

Auto Trait Implementations§

§

impl Freeze for Cont

§

impl RefUnwindSafe for Cont

§

impl !Send for Cont

§

impl !Sync for Cont

§

impl Unpin for Cont

§

impl UnwindSafe for Cont

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.