Skip to main content

CodeGenContext

Enum CodeGenContext 

Source
pub enum CodeGenContext {
    Module(String),
    Class(String),
    Function,
    Async(Box<CodeGenContext>),
    Loop {
        has_else: bool,
        parent: Box<CodeGenContext>,
    },
    TryBlock {
        parent: Box<CodeGenContext>,
    },
    ExceptHandler {
        parent: Box<CodeGenContext>,
    },
}
Expand description

A type to track the context of code generation.

Variants§

§

Module(String)

§

Class(String)

Inside a class body; the payload is the class name, so method lowering can resolve self (receiver typing, self.method() calls) against the class’s definition in the symbol table.

§

Function

§

Async(Box<CodeGenContext>)

§

Loop

Directly inside a loop body. has_else is true when the loop carries a Python else clause, in which case break statements must also set the __rython_broke flag the loop lowering declares.

Fields

§has_else: bool
§

TryBlock

Inside a try block body, which lowers to a closure returning Result<(), PyException>; raise (and failed assert) here lower to return Err(...) so the except handlers can catch them.

Fields

§

ExceptHandler

Inside an except handler body, where the caught exception is in scope as __rython_exc. parent is the context the try statement itself appears in (handler code runs outside the try’s closure).

Fields

Implementations§

Source§

impl CodeGenContext

Source

pub fn in_try_block(&self) -> bool

Whether code generated here runs inside a try-block closure, so a raised exception can return Err(...) to be caught by its handlers.

Source

pub fn break_crosses_try_closure(&self) -> bool

Whether a break/continue generated here would have to cross a try-block closure boundary to reach its loop. Walking outward, the first Loop means the statement binds to a real Rust loop; hitting TryBlock first means the loop is outside the closure, so the statement must be threaded out as a PyFlow signal instead.

Source

pub fn break_target_has_else(&self) -> bool

Whether the loop a break here targets carries a Python else clause, so the break must also set the loop’s __rython_broke flag.

Source

pub fn in_except_handler(&self) -> bool

Whether code generated here runs inside an except handler, i.e. the caught exception is in scope as __rython_exc (for bare raise).

Source

pub fn strip_exception_scopes(self) -> CodeGenContext

The context for a nested function definition’s body: exception scopes don’t cross function boundaries (a raise in a nested function can’t return out of the enclosing try’s closure).

Source

pub fn enclosing_class_name(&self) -> Option<&str>

The name of the class whose method body this context sits inside, if any — the class self refers to.

Trait Implementations§

Source§

impl Clone for CodeGenContext

Source§

fn clone(&self) -> CodeGenContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodeGenContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErrorContext for T
where T: Debug,

Source§

fn with_context(&self, operation: &str) -> String

Generate a standardized error message with context.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Ungil for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more