From dcbfff8eb8a87fe2512bccfe8838b06801e09eef Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Tue, 9 Jul 2024 05:37:49 -0700 Subject: [PATCH] just add some variants of push-flag / push-named rather than providing both args --- crates/nu-engine/src/compile/builder.rs | 10 ++++----- crates/nu-engine/src/compile/call.rs | 28 +++++++++++++------------ crates/nu-engine/src/eval_ir.rs | 27 ++++++++++++++++++++++-- crates/nu-protocol/src/ir/display.rs | 18 ++++++++++------ crates/nu-protocol/src/ir/mod.rs | 12 +++++------ 5 files changed, 62 insertions(+), 33 deletions(-) diff --git a/crates/nu-engine/src/compile/builder.rs b/crates/nu-engine/src/compile/builder.rs index c3d0b758c1..dd850321e5 100644 --- a/crates/nu-engine/src/compile/builder.rs +++ b/crates/nu-engine/src/compile/builder.rs @@ -170,12 +170,10 @@ impl BlockBuilder { Instruction::StoreEnv { key: _, src } => allocate(&[*src], &[]), Instruction::PushPositional { src } => allocate(&[*src], &[]), Instruction::AppendRest { src } => allocate(&[*src], &[]), - Instruction::PushFlag { name: _, short: _ } => Ok(()), - Instruction::PushNamed { - name: _, - short: _, - src, - } => allocate(&[*src], &[]), + Instruction::PushFlag { name: _ } => Ok(()), + Instruction::PushShortFlag { short: _ } => Ok(()), + Instruction::PushNamed { name: _, src } => allocate(&[*src], &[]), + Instruction::PushShortNamed { short: _, src } => allocate(&[*src], &[]), Instruction::PushParserInfo { name: _, info: _ } => Ok(()), Instruction::RedirectOut { mode: _ } => Ok(()), Instruction::RedirectErr { mode: _ } => Ok(()), diff --git a/crates/nu-engine/src/compile/call.rs b/crates/nu-engine/src/compile/call.rs index 8a75c20a78..d9f1b8e581 100644 --- a/crates/nu-engine/src/compile/call.rs +++ b/crates/nu-engine/src/compile/call.rs @@ -153,22 +153,24 @@ pub(crate) fn compile_call( builder.set_last_ast(ast_ref); } CompiledArg::Named(name, short, Some(reg), span, ast_ref) => { - let name = builder.data(name)?; - let short = builder.data(short.unwrap_or(""))?; - builder.push( - Instruction::PushNamed { - name, - short, - src: reg, - } - .into_spanned(span), - )?; + if !name.is_empty() { + let name = builder.data(name)?; + builder.push(Instruction::PushNamed { name, src: reg }.into_spanned(span))?; + } else { + let short = builder.data(short.unwrap_or(""))?; + builder + .push(Instruction::PushShortNamed { short, src: reg }.into_spanned(span))?; + } builder.set_last_ast(ast_ref); } CompiledArg::Named(name, short, None, span, ast_ref) => { - let name = builder.data(name)?; - let short = builder.data(short.unwrap_or(""))?; - builder.push(Instruction::PushFlag { name, short }.into_spanned(span))?; + if !name.is_empty() { + let name = builder.data(name)?; + builder.push(Instruction::PushFlag { name }.into_spanned(span))?; + } else { + let short = builder.data(short.unwrap_or(""))?; + builder.push(Instruction::PushShortFlag { short }.into_spanned(span))?; + } builder.set_last_ast(ast_ref); } CompiledArg::Spread(reg, span, ast_ref) => { diff --git a/crates/nu-engine/src/eval_ir.rs b/crates/nu-engine/src/eval_ir.rs index 225a2dbfc1..02f3ec3683 100644 --- a/crates/nu-engine/src/eval_ir.rs +++ b/crates/nu-engine/src/eval_ir.rs @@ -386,22 +386,45 @@ fn eval_instruction( }); Ok(Continue) } - Instruction::PushFlag { name, short } => { + Instruction::PushFlag { name } => { let data = ctx.data.clone(); ctx.stack.arguments.push(Argument::Flag { data, name: *name, + short: DataSlice::empty(), + span: *span, + }); + Ok(Continue) + } + Instruction::PushShortFlag { short } => { + let data = ctx.data.clone(); + ctx.stack.arguments.push(Argument::Flag { + data, + name: DataSlice::empty(), short: *short, span: *span, }); Ok(Continue) } - Instruction::PushNamed { name, short, src } => { + Instruction::PushNamed { name, src } => { let val = ctx.collect_reg(*src, *span)?; let data = ctx.data.clone(); ctx.stack.arguments.push(Argument::Named { data, name: *name, + short: DataSlice::empty(), + span: *span, + val, + ast: ast.clone().map(|ast_ref| ast_ref.0), + }); + Ok(Continue) + } + Instruction::PushShortNamed { short, src } => { + let val = ctx.collect_reg(*src, *span)?; + let data = ctx.data.clone(); + ctx.stack.arguments.push(Argument::Named { + data, + name: DataSlice::empty(), short: *short, span: *span, val, diff --git a/crates/nu-protocol/src/ir/display.rs b/crates/nu-protocol/src/ir/display.rs index 213d2c836b..3bc7a94c9d 100644 --- a/crates/nu-protocol/src/ir/display.rs +++ b/crates/nu-protocol/src/ir/display.rs @@ -112,15 +112,21 @@ impl<'a> fmt::Display for FmtInstruction<'a> { Instruction::AppendRest { src } => { write!(f, "{:WIDTH$} {src}", "append-rest") } - Instruction::PushFlag { name, short } => { + Instruction::PushFlag { name } => { let name = FmtData(self.data, *name); - let short = FmtData(self.data, *short); - write!(f, "{:WIDTH$} {name}, {short}", "push-flag") + write!(f, "{:WIDTH$} {name}", "push-flag") } - Instruction::PushNamed { name, short, src } => { - let name = FmtData(self.data, *name); + Instruction::PushShortFlag { short } => { let short = FmtData(self.data, *short); - write!(f, "{:WIDTH$} {name}, {short}, {src}", "push-named") + write!(f, "{:WIDTH$} {short}", "push-short-flag") + } + Instruction::PushNamed { name, src } => { + let name = FmtData(self.data, *name); + write!(f, "{:WIDTH$} {name}, {src}", "push-named") + } + Instruction::PushShortNamed { short, src } => { + let short = FmtData(self.data, *short); + write!(f, "{:WIDTH$} {short}, {src}", "push-short-named") } Instruction::PushParserInfo { name, info } => { let name = FmtData(self.data, *name); diff --git a/crates/nu-protocol/src/ir/mod.rs b/crates/nu-protocol/src/ir/mod.rs index f0d3ecd406..8f1a387107 100644 --- a/crates/nu-protocol/src/ir/mod.rs +++ b/crates/nu-protocol/src/ir/mod.rs @@ -134,13 +134,13 @@ pub enum Instruction { /// Add a list of args to the next (internal) call (spread/rest). AppendRest { src: RegId }, /// Add a named arg with no value to the next (internal) call. - PushFlag { name: DataSlice, short: DataSlice }, + PushFlag { name: DataSlice }, + /// Add a short named arg with no value to the next (internal) call. + PushShortFlag { short: DataSlice }, /// Add a named arg with a value to the next (internal) call. - PushNamed { - name: DataSlice, - short: DataSlice, - src: RegId, - }, + PushNamed { name: DataSlice, src: RegId }, + /// Add a short named arg with a value to the next (internal) call. + PushShortNamed { short: DataSlice, src: RegId }, /// Add parser info to the next (internal) call. PushParserInfo { name: DataSlice,