pub struct State<'a> {Show 22 fields
pub registers: &'a mut Vec<Data>,
pub fns: &'a mut Vec<Function>,
pub structs: &'a mut Vec<Struct>,
pub enums: &'a mut Vec<EnumType>,
pub pools: &'a mut Pools,
pub instr_src: &'a mut Vec<InstrSrc>,
pub callsite_registers: &'a mut Vec<Vec<u16>>,
pub dyn_libs: &'a mut Vec<Dynamiclib>,
pub allocated_arg_count: &'a mut usize,
pub allocated_call_depth: &'a mut usize,
pub const_registers: &'a mut FxHashMap<Data, u16>,
pub free_registers: &'a mut Vec<u16>,
pub sources: &'a mut Vec<Source>,
pub reserved_registers: FxHashSet<u16>,
pub value_callsites: FxHashSet<u16>,
pub optimize: bool,
pub namespaces: &'a mut FileNamespaces,
pub generics: &'a mut Generics,
pub indirect_registers: &'a mut IndirectRegisters,
pub propagations: Vec<Vec<DataType>>,
pub fn_returns: Vec<(SmolStr, DataType)>,
pub captured_binders: Vec<SmolStr>,
}Fields§
§registers: &'a mut Vec<Data>§fns: &'a mut Vec<Function>§structs: &'a mut Vec<Struct>§enums: &'a mut Vec<EnumType>§pools: &'a mut Pools§instr_src: &'a mut Vec<InstrSrc>§callsite_registers: &'a mut Vec<Vec<u16>>§dyn_libs: &'a mut Vec<Dynamiclib>§allocated_arg_count: &'a mut usize§allocated_call_depth: &'a mut usize§const_registers: &'a mut FxHashMap<Data, u16>§free_registers: &'a mut Vec<u16>§sources: &'a mut Vec<Source>§reserved_registers: FxHashSet<u16>§value_callsites: FxHashSet<u16>The call sites, among those that save registers, whose call returns a value. Such a call writes its return register on the way back, so that register holds nothing a save would have to keep.
optimize: boolWhether this is the release profile. candela build compiles with it
and runs the passes that make the program faster to run; a run from
source, the REPL and an embedding host compile without it, straight
from the syntax tree, so the dev loop never waits on a pass.
namespaces: &'a mut FileNamespaces§generics: &'a mut Generics§indirect_registers: &'a mut IndirectRegisters§propagations: Vec<Vec<DataType>>One frame per function body whose returns are being worked out, holding
the operand type of every ? the walk typed in it. Each is a return of
that operand’s None or Err.
fn_returns: Vec<(SmolStr, DataType)>The function bodies being compiled, innermost last: the name a
diagnostic uses and the type the body returns, which is what a ?
in it has to hand back.
captured_binders: Vec<SmolStr>The names an is being compiled binds that a closure in their scope
captures, so each is bound in a cell. Set by whatever compiles the
condition, which is what knows the scope.
Implementations§
Source§impl State<'_>
impl State<'_>
Sourcepub fn checkpoint(&self) -> CompileCheckpoint
pub fn checkpoint(&self) -> CompileCheckpoint
Snapshots the tables a compile attempt writes into as it goes, so a
diagnostic raised partway through can be undone with
State::rollback_to.
The instruction stream needs no entry here: an attempt compiles into a local buffer that only reaches the stream once the whole attempt succeeds. Everything captured below is written in place, because a nested call can only reuse a specialisation another call site already produced.
Sourcepub fn rollback_to(&mut self, checkpoint: &CompileCheckpoint)
pub fn rollback_to(&mut self, checkpoint: &CompileCheckpoint)
Undoes everything a failed compile attempt wrote to the tables, back to
checkpoint. A successful attempt leaves the tables as they stand and
commits its bytecode alongside them.
Sourcepub fn type_names(&self) -> TypeNames<'_>
pub fn type_names(&self) -> TypeNames<'_>
The tables a diagnostic needs to name a struct or an enum the program
declared, rather than printing the bare words struct and enum.
Sourcepub fn scope(&self, file_idx: u16) -> &Namespace
pub fn scope(&self, file_idx: u16) -> &Namespace
The scope names written in file_idx resolve in: that file’s own
declarations, the symbols its bare imports merged in, and the modules it
bound with as.
Sourcepub fn scope_mut(&mut self, file_idx: u16) -> &mut Namespace
pub fn scope_mut(&mut self, file_idx: u16) -> &mut Namespace
The same scope, to declare into. A function or struct declared inside a block is registered here for as long as the block is being compiled.
Sourcepub fn type_ctx(&mut self, file_idx: u16) -> TypeCtx<'_>
pub fn type_ctx(&mut self, file_idx: u16) -> TypeCtx<'_>
The scope and registries a TypeExpr resolves against, borrowed from
this state. Resolving a generic type registers the instantiation, which
is why it needs more than the namespace.
Sourcepub fn free_reg(&mut self, id: u16, v: &[Variable])
pub fn free_reg(&mut self, id: u16, v: &[Variable])
Marks a register as free, allowing it to later be reused by alloc_reg.
The register is marked as free iff:
- the register isn’t tied to any variable
- the register isn’t a constant register
- the register isn’t reserved in
reserved_registers - the register isn’t already marked as free
Sourcepub fn alloc_reg(&mut self) -> u16
pub fn alloc_reg(&mut self) -> u16
Allocates a register. It free_registers isn’t empty, it will reuse the latest one. Else, it will allocate a new one.
Sourcepub fn const_int_register(&mut self, n: i64) -> u16
pub fn const_int_register(&mut self, n: i64) -> u16
The register a constant integer lives in, allocated on first use.
A constant register is written once by the compiler and read by the instructions that name it, so every use of the same constant shares one.
Sourcepub fn template_register(&mut self, data: Data) -> u16
pub fn template_register(&mut self, data: Data) -> u16
A new register holding data, the template a Clone* instruction
copies from.
Nothing writes a template: every run of the literal reads the value the compiler put there. The code holding the literal can run again, through another call of its function or another turn of an enclosing loop, so the register stays out of the allocator for good.
Sourcepub fn type_codes_register(&mut self, codes: &[i64]) -> u16
pub fn type_codes_register(&mut self, codes: &[i64]) -> u16
The register a constant lives in, allocated on first use and shared by every use of the same value. The constant register holding a list of these type codes, the one an earlier check made when there is one.
pub fn const_register(&mut self, data: Data) -> u16
Sourcepub fn indirect_arg_register(&mut self, idx: usize) -> u16
pub fn indirect_arg_register(&mut self, idx: usize) -> u16
The register the argument at idx of an indirect call travels in.
Reserved on first use, so the allocator never hands it to anything else: the caller writes it and the callee reads it as its parameter, and the two never meet at compile time.
Sourcepub fn new_fn_value_set(&mut self, fn_id: u16) -> u32
pub fn new_fn_value_set(&mut self, fn_id: u16) -> u32
A fresh set of the functions one variable may hold, starting with
fn_id.
Sourcepub fn fn_value_candidates(&self, fn_type: &FnValue) -> Vec<u16>
pub fn fn_value_candidates(&self, fn_type: &FnValue) -> Vec<u16>
The functions a call through fn_type may reach.
Sourcepub fn indirect_env_register(&mut self) -> u16
pub fn indirect_env_register(&mut self) -> u16
The register an indirect call leaves the callee’s environment in.
Sourcepub fn fn_entry_register(&mut self, fn_id: usize) -> u16
pub fn fn_entry_register(&mut self, fn_id: usize) -> u16
The register holding where fn_id’s body starts, allocated the first
time the function becomes a value. Every value built for the function
carries it, and the compiler writes the location into it once the
function’s indirect specialisation is compiled.
Sourcepub fn alloc_reg_tgt(&mut self, tgt_id: Option<u16>) -> u16
pub fn alloc_reg_tgt(&mut self, tgt_id: Option<u16>) -> u16
Allocates a register, reusing tgt_id if it holds some register id.
If tgt_id == None, it calls alloc_reg().
Sourcepub fn free_scope_registers(
&mut self,
regs_before: u16,
scope_instrs: &[Instr],
v: &[Variable],
)
pub fn free_scope_registers( &mut self, regs_before: u16, scope_instrs: &[Instr], v: &[Variable], )
Frees registers that are written by instructions in scope_instrs.
Sourcepub fn add_to_src(&mut self, ctx: Ctx, output: &[Instr], span: Span)
pub fn add_to_src(&mut self, ctx: Ctx, output: &[Instr], span: Span)
Associates the last instruction in output with span and adds the InstrSrc to instr_src.
This allows runtime errors to be traced back to span in the source code.
Sourcepub fn add_instr_to_src(&mut self, ctx: Ctx, instr: Instr, span: Span)
pub fn add_instr_to_src(&mut self, ctx: Ctx, instr: Instr, span: Span)
add_to_src for an instruction that is written back
into output after later ones were emitted, so it is no longer the last.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for State<'a>
impl<'a> !Send for State<'a>
impl<'a> !Sync for State<'a>
impl<'a> !UnwindSafe for State<'a>
impl<'a> Freeze for State<'a>
impl<'a> Unpin for State<'a>
impl<'a> UnsafeUnpin for State<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);