Skip to main content

State

Struct State 

Source
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: bool

Whether 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<'_>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn const_register(&mut self, data: Data) -> u16

Source

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.

Source

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.

Source

pub fn fn_value_candidates(&self, fn_type: &FnValue) -> Vec<u16>

The functions a call through fn_type may reach.

Source

pub fn indirect_env_register(&mut self) -> u16

The register an indirect call leaves the callee’s environment in.

Source

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.

Source

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().

Source

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.

Source

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.

Source

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> 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.

§

impl<T> Paint for T
where T: ?Sized,

§

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 primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
§

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>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

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 bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
§

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 mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
§

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.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
§

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);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. 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.