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::StoreEnv { key: _, src } => allocate(&[*src], &[]),
Instruction::PushPositional { src } => allocate(&[*src], &[]), Instruction::PushPositional { src } => allocate(&[*src], &[]),
Instruction::AppendRest { src } => allocate(&[*src], &[]), Instruction::AppendRest { src } => allocate(&[*src], &[]),
Instruction::PushFlag { name: _, short: _ } => Ok(()), Instruction::PushFlag { name: _ } => Ok(()),
Instruction::PushNamed { Instruction::PushShortFlag { short: _ } => Ok(()),
name: _, Instruction::PushNamed { name: _, src } => allocate(&[*src], &[]),
short: _, Instruction::PushShortNamed { short: _, src } => allocate(&[*src], &[]),
src,
} => allocate(&[*src], &[]),
Instruction::PushParserInfo { name: _, info: _ } => Ok(()), Instruction::PushParserInfo { name: _, info: _ } => Ok(()),
Instruction::RedirectOut { mode: _ } => Ok(()), Instruction::RedirectOut { mode: _ } => Ok(()),
Instruction::RedirectErr { mode: _ } => Ok(()), Instruction::RedirectErr { mode: _ } => Ok(()),

View File

@ -153,22 +153,24 @@ pub(crate) fn compile_call(
builder.set_last_ast(ast_ref); builder.set_last_ast(ast_ref);
} }
CompiledArg::Named(name, short, Some(reg), span, ast_ref) => { CompiledArg::Named(name, short, Some(reg), span, ast_ref) => {
let name = builder.data(name)?; if !name.is_empty() {
let short = builder.data(short.unwrap_or(""))?; let name = builder.data(name)?;
builder.push( builder.push(Instruction::PushNamed { name, src: reg }.into_spanned(span))?;
Instruction::PushNamed { } else {
name, let short = builder.data(short.unwrap_or(""))?;
short, builder
src: reg, .push(Instruction::PushShortNamed { short, src: reg }.into_spanned(span))?;
} }
.into_spanned(span),
)?;
builder.set_last_ast(ast_ref); builder.set_last_ast(ast_ref);
} }
CompiledArg::Named(name, short, None, span, ast_ref) => { CompiledArg::Named(name, short, None, span, ast_ref) => {
let name = builder.data(name)?; if !name.is_empty() {
let short = builder.data(short.unwrap_or(""))?; let name = builder.data(name)?;
builder.push(Instruction::PushFlag { name, short }.into_spanned(span))?; 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); builder.set_last_ast(ast_ref);
} }
CompiledArg::Spread(reg, span, ast_ref) => { CompiledArg::Spread(reg, span, ast_ref) => {

View File

@ -386,22 +386,45 @@ fn eval_instruction<D: DebugContext>(
}); });
Ok(Continue) Ok(Continue)
} }
Instruction::PushFlag { name, short } => { Instruction::PushFlag { name } => {
let data = ctx.data.clone(); let data = ctx.data.clone();
ctx.stack.arguments.push(Argument::Flag { ctx.stack.arguments.push(Argument::Flag {
data, data,
name: *name, 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, short: *short,
span: *span, span: *span,
}); });
Ok(Continue) Ok(Continue)
} }
Instruction::PushNamed { name, short, src } => { Instruction::PushNamed { name, src } => {
let val = ctx.collect_reg(*src, *span)?; let val = ctx.collect_reg(*src, *span)?;
let data = ctx.data.clone(); let data = ctx.data.clone();
ctx.stack.arguments.push(Argument::Named { ctx.stack.arguments.push(Argument::Named {
data, data,
name: *name, 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, short: *short,
span: *span, span: *span,
val, val,

View File

@ -112,15 +112,21 @@ impl<'a> fmt::Display for FmtInstruction<'a> {
Instruction::AppendRest { src } => { Instruction::AppendRest { src } => {
write!(f, "{:WIDTH$} {src}", "append-rest") write!(f, "{:WIDTH$} {src}", "append-rest")
} }
Instruction::PushFlag { name, short } => { Instruction::PushFlag { name } => {
let name = FmtData(self.data, *name); let name = FmtData(self.data, *name);
let short = FmtData(self.data, *short); write!(f, "{:WIDTH$} {name}", "push-flag")
write!(f, "{:WIDTH$} {name}, {short}", "push-flag")
} }
Instruction::PushNamed { name, short, src } => { Instruction::PushShortFlag { short } => {
let name = FmtData(self.data, *name);
let short = FmtData(self.data, *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 } => { Instruction::PushParserInfo { name, info } => {
let name = FmtData(self.data, *name); 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). /// Add a list of args to the next (internal) call (spread/rest).
AppendRest { src: RegId }, AppendRest { src: RegId },
/// Add a named arg with no value to the next (internal) call. /// 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. /// Add a named arg with a value to the next (internal) call.
PushNamed { PushNamed { name: DataSlice, src: RegId },
name: DataSlice, /// Add a short named arg with a value to the next (internal) call.
short: DataSlice, PushShortNamed { short: DataSlice, src: RegId },
src: RegId,
},
/// Add parser info to the next (internal) call. /// Add parser info to the next (internal) call.
PushParserInfo { PushParserInfo {
name: DataSlice, name: DataSlice,