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.
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
parent: Box<CodeGenContext>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
parent: Box<CodeGenContext>Implementations§
Source§impl CodeGenContext
impl CodeGenContext
Sourcepub fn in_try_block(&self) -> bool
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.
Sourcepub fn break_crosses_try_closure(&self) -> bool
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.
Sourcepub fn break_target_has_else(&self) -> bool
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.
Sourcepub fn in_except_handler(&self) -> bool
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).
Sourcepub fn strip_exception_scopes(self) -> CodeGenContext
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).
Sourcepub fn enclosing_class_name(&self) -> Option<&str>
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
impl Clone for CodeGenContext
Source§fn clone(&self) -> CodeGenContext
fn clone(&self) -> CodeGenContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more