pub enum Instruction {
Show 58 variants
Unreachable,
LoadLiteral {
dst: RegId,
lit: Literal,
},
LoadValue {
dst: RegId,
val: Box<Value>,
},
Move {
dst: RegId,
src: RegId,
},
Clone {
dst: RegId,
src: RegId,
},
Collect {
src_dst: RegId,
},
TryCollect {
src_dst: RegId,
},
Span {
src_dst: RegId,
},
Drop {
src: RegId,
},
Drain {
src: RegId,
},
DrainIfEnd {
src: RegId,
},
LoadVariable {
dst: RegId,
var_id: VarId,
preserve_origin: bool,
},
StoreVariable {
var_id: VarId,
src: RegId,
},
DropVariable {
var_id: VarId,
},
LoadEnv {
dst: RegId,
key: DataSlice,
},
LoadEnvOpt {
dst: RegId,
key: DataSlice,
},
StoreEnv {
key: DataSlice,
src: RegId,
},
PushPositional {
src: RegId,
},
AppendRest {
src: RegId,
},
PushFlag {
name: DataSlice,
},
PushShortFlag {
short: DataSlice,
},
PushNamed {
name: DataSlice,
src: RegId,
},
PushShortNamed {
short: DataSlice,
src: RegId,
},
PushParserInfo {
name: DataSlice,
info: Box<Expression>,
},
RedirectOut {
mode: RedirectMode,
},
RedirectErr {
mode: RedirectMode,
},
CheckErrRedirected {
src: RegId,
},
OpenFile {
file_num: u32,
path: RegId,
append: bool,
},
WriteFile {
file_num: u32,
src: RegId,
},
CloseFile {
file_num: u32,
},
Call {
decl_id: DeclId,
src_dst: RegId,
},
StringAppend {
src_dst: RegId,
val: RegId,
},
GlobFrom {
src_dst: RegId,
no_expand: bool,
},
ListPush {
src_dst: RegId,
item: RegId,
},
ListSpread {
src_dst: RegId,
items: RegId,
},
RecordInsert {
src_dst: RegId,
key: RegId,
val: RegId,
},
RecordSpread {
src_dst: RegId,
items: RegId,
},
Not {
src_dst: RegId,
},
BinaryOp {
lhs_dst: RegId,
op: Operator,
rhs: RegId,
},
FollowCellPath {
src_dst: RegId,
path: RegId,
},
CloneCellPath {
dst: RegId,
src: RegId,
path: RegId,
},
UpsertCellPath {
src_dst: RegId,
path: RegId,
new_value: RegId,
},
UpdateVarCellPath {
var_id: VarId,
cell_path: RegId,
new_value: RegId,
},
Jump {
index: usize,
},
BranchIf {
cond: RegId,
index: usize,
},
BranchIfEmpty {
src: RegId,
index: usize,
},
Match {
pattern: Box<Pattern>,
src: RegId,
index: usize,
},
CheckMatchGuard {
src: RegId,
},
Iterate {
dst: RegId,
stream: RegId,
end_index: usize,
},
UnwindJump {
index: usize,
handlers: usize,
},
OnError {
index: usize,
},
OnErrorInto {
index: usize,
dst: RegId,
},
FinallyInto {
index: usize,
dst: RegId,
},
PopErrorHandler,
BeginFinally,
EndFinally,
ReturnEarly {
src: RegId,
},
Return {
src: RegId,
},
}Variants§
Unreachable
Unreachable code path (error)
LoadLiteral
Load a literal value into the dst register
LoadValue
Load a clone of a boxed value into the dst register (e.g. from const evaluation)
Move
Move a register. Value is taken from src (used by this instruction).
Clone
Copy a register (must be a collected value). Value is still in src after this instruction.
Collect
Collect a stream in a register to a value. Because it collects to a value, nushell will ignore the errors in the stream. It’s important when the stream is from an external command
TryCollect
Collect a stream in a register to a value.
But it’s different from Collect in that if there is an error in the stream, it will be
returned as an error instead of being ignored.
Span
Change the span of the contents of a register to the span of this instruction.
Drop
Drop the value/stream in a register, without draining
Drain
Drain the value/stream in a register and discard (e.g. semicolon).
If passed a stream from an external command, sets $env.LAST_EXIT_CODE to the resulting exit code, and invokes any available error handler with Empty, or if not available, returns an exit-code-only stream, leaving the block.
DrainIfEnd
Drain the value/stream in a register and discard only if this is the last pipeline element.
LoadVariable
Load the value of a variable into the dst register.
When preserve_origin is false (the default), the value is re-spanned to this
instruction’s span so error labels point at the use site. When true, the value keeps
the span from where it was defined (used by metadata $var).
StoreVariable
Store the value of a variable from the src register
DropVariable
Remove a variable from the stack, freeing up whatever resources were associated with it
LoadEnv
Load the value of an environment variable into the dst register
LoadEnvOpt
Load the value of an environment variable into the dst register, or Nothing if it
doesn’t exist
StoreEnv
Store the value of an environment variable from the src register
PushPositional
Add a positional arg to the next (internal) call.
AppendRest
Add a list of args to the next (internal) call (spread/rest).
PushFlag
Add a named arg with no value to the next (internal) call.
PushShortFlag
Add a short named arg with no value to the next (internal) call.
PushNamed
Add a named arg with a value to the next (internal) call.
PushShortNamed
Add a short named arg with a value to the next (internal) call.
PushParserInfo
Add parser info to the next (internal) call.
RedirectOut
Set the redirection for stdout for the next call (only).
The register for a file redirection is not consumed.
Fields
mode: RedirectModeRedirectErr
Set the redirection for stderr for the next call (only).
The register for a file redirection is not consumed.
Fields
mode: RedirectModeCheckErrRedirected
Throw an error if stderr wasn’t redirected in the given stream. src is preserved.
OpenFile
Open a file for redirection, pushing it onto the file stack.
WriteFile
Write data from the register to a file. This is done to finish a file redirection, in case an internal command or expression was evaluated rather than an external one.
CloseFile
Pop a file used for redirection from the file stack.
Call
Make a call. The input is taken from src_dst, and the output is placed in src_dst,
overwriting it. The argument stack is used implicitly and cleared when the call ends.
StringAppend
Append a value onto the end of a string. Uses to_expanded_string(", ", ...) on the value.
Used for string interpolation literals. Not the same thing as the ++ operator.
GlobFrom
Convert a string into a glob. Used for glob interpolation and setting glob variables. If the
value is already a glob, it won’t be modified (no_expand will have no effect).
ListPush
Push a value onto the end of a list. Used to construct list literals.
ListSpread
Spread a value onto the end of a list. Used to construct list literals.
RecordInsert
Insert a key-value pair into a record. Used to construct record literals. Raises an error if the key already existed in the record.
RecordSpread
Spread a record onto a record. Used to construct record literals. Any existing value for the key is overwritten.
Not
Negate a boolean.
BinaryOp
Do a binary operation on lhs_dst (left) and rhs (right) and write the result to
lhs_dst.
FollowCellPath
Follow a cell path on the value in src_dst, storing the result back to src_dst
CloneCellPath
Clone the value at a cell path in src, storing the result to dst. The original value
remains in src. Must be a collected value.
UpsertCellPath
Update/insert a cell path to new_value on the value in src_dst, storing the modified
value back to src_dst
UpdateVarCellPath
Update/insert a cell path directly on a variable in the stack, without cloning the variable first. Combines LoadVariable + UpsertCellPath + StoreVariable into a single in-place mutation. The variable must be mutable.
Jump
Jump to an offset in this block
BranchIf
Branch to an offset in this block if the value of the cond register is a true boolean,
otherwise continue execution
BranchIfEmpty
Branch to an offset in this block if the value of the src register is Empty or Nothing,
otherwise continue execution. The original value in src is preserved.
Match
Match a pattern on src. If the pattern matches, branch to index after having set any
variables captured by the pattern. If the pattern doesn’t match, continue execution. The
original value is preserved in src through this instruction.
CheckMatchGuard
Check that a match guard is a boolean, throwing
MatchGuardNotBool if it isn’t. Preserves src.
Iterate
Iterate on register stream, putting the next value in dst if present, or jumping to
end_index if the iterator is finished
UnwindJump
Jump to an offset in this block, unwinding through handlers entries of the try
handler stack first. This is how break and continue leave try expressions: any
finally block among those handlers runs before the jump completes.
OnError
Push a catch handler, without capturing the error value
OnErrorInto
Push a catch handler, capturing the error value into dst. If the error handler is not
called, the register should be freed manually.
FinallyInto
Push a finally handler, capturing the error value into dst. If the handler is entered
for any other reason than an error, dst is set to empty instead.
PopErrorHandler
Pop a catch handler. This is not necessary when control flow is directed to the error
handler due to an error.
BeginFinally
Mark the finally handler on top of the handler stack as running, on the way into its
block from the try/catch fall-through path. The unwinder does this itself when it
enters a finally block, so index of finally points just past this instruction.
EndFinally
Leave a finally block: pops its running marker and, if the block was entered by
unwinding (an error, return, exit, break, or continue), resumes that unwinding.
ReturnEarly
Return early from the block with the value in the register.
Unlike return, this runs pending finally handlers first (collecting the value in that
case, like the try-collect on the fall-through path), and flags the result as an early
return. Custom command and closure calls clear that flag; only top-level file evaluation
reads it, to skip main.
Return
Return from the block with the value in the register
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn display<'a>(
&'a self,
engine_state: &'a EngineState,
data: &'a [u8],
) -> FmtInstruction<'a>
pub fn display<'a>( &'a self, engine_state: &'a EngineState, data: &'a [u8], ) -> FmtInstruction<'a>
Returns a value that can be formatted with Display to show a detailed
listing of the instruction.
Sourcepub fn output_register(&self) -> Option<RegId>
pub fn output_register(&self) -> Option<RegId>
Get the output register, for instructions that produce some kind of immediate result.
Sourcepub fn branch_target(&self) -> Option<usize>
pub fn branch_target(&self) -> Option<usize>
Returns the branch target index of the instruction if this is a branching instruction.
Sourcepub fn set_branch_target(&mut self, target_index: usize) -> Result<(), usize>
pub fn set_branch_target(&mut self, target_index: usize) -> Result<(), usize>
Sets the branch target of the instruction if this is a branching instruction.
Returns Err(target_index) if it isn’t a branching instruction.
Sourcepub fn check_interrupt(
&self,
engine_state: &EngineState,
span: &Span,
) -> Result<(), ShellError>
pub fn check_interrupt( &self, engine_state: &EngineState, span: &Span, ) -> Result<(), ShellError>
Check for an interrupt before certain instructions
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§impl Debug for Instruction
impl Debug for Instruction
Source§impl<'de> Deserialize<'de> for Instruction
impl<'de> Deserialize<'de> for Instruction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !RefUnwindSafe for Instruction
impl !UnwindSafe for Instruction
impl Freeze for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnsafeUnpin for Instruction
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSpanned for T
impl<T> IntoSpanned for T
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more