just add some variants of push-flag / push-named rather than providing both args

This commit is contained in:
Devyn Cairns 2024-07-09 05:37:49 -07:00
parent aebdadc674
commit dcbfff8eb8
5 changed files with 62 additions and 33 deletions

View File

@ -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(()),

View File

@ -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) => {

View File

@ -386,22 +386,45 @@ fn eval_instruction<D: DebugContext>(
});
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,

View File

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

View File

@ -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,