pub struct CompilerState {
pub loop_start: Option<Label>,
pub loop_end: Option<Label>,
pub last_stmt: bool,
pub top_level_assign: bool,
}
Expand description
The state of the compiler.
Fields§
§loop_start: Option<Label>
The label pointing to the start of the current loop.
loop_end: Option<Label>
The label pointing to the end of the current loop.
last_stmt: bool
Whether the current statement is the last statement in a block or the program, indicating that its return value is the return value of the block / program.
top_level_assign: bool
Whether the expression being compiled is a top-level assignment expression, indicating that its return value is not used.
This is used to determine whether to use the InstructionKind::StoreVar
or
InstructionKind::AssignVar
instruction.
For example, in the following code:
x = y = 2
The x = ...
expression is a top-level assignment expression, so its return value is not
used within the same statement. However, the y = 2
expression is not a top-level
assignment, as its return value is then passed to the x = ...
expression. In this case,
the compiler will generate a InstructionKind::AssignVar
instruction for x
and a
InstructionKind::StoreVar
instruction for y
.
Trait Implementations§
Source§impl Clone for CompilerState
impl Clone for CompilerState
Source§fn clone(&self) -> CompilerState
fn clone(&self) -> CompilerState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more