fix parser info: actually add it to the call

This commit is contained in:
Devyn Cairns 2024-07-03 00:17:09 -07:00
parent 3c33a3f4eb
commit 52ec0c3b1d
No known key found for this signature in database
7 changed files with 28 additions and 3 deletions

View File

@ -147,6 +147,7 @@ impl BlockBuilder {
Instruction::AppendRest { src } => self.free_register(*src)?,
Instruction::PushFlag { name: _ } => (),
Instruction::PushNamed { name: _, src } => self.free_register(*src)?,
Instruction::PushParserInfo { name: _, info: _ } => (),
Instruction::RedirectOut { mode } | Instruction::RedirectErr { mode } => match mode {
RedirectMode::File { path, .. } => self.free_register(*path)?,
_ => (),

View File

@ -119,6 +119,13 @@ pub(crate) fn compile_call(
}
}
// Add any parser info from the call
for (name, info) in &call.parser_info {
let name = builder.data(name)?;
let info = Box::new(info.clone());
builder.push(Instruction::PushParserInfo { name, info }.into_spanned(call.head))?;
}
if let Some(mode) = redirect_modes.out {
builder.push(mode.map(|mode| Instruction::RedirectOut { mode }))?;
}

View File

@ -319,6 +319,14 @@ fn eval_instruction(
});
Ok(Continue)
}
Instruction::PushParserInfo { name, info } => {
ctx.stack.arguments.push(Argument::ParserInfo {
data: ctx.data.clone(),
name: *name,
info: info.clone(),
});
Ok(Continue)
}
Instruction::RedirectOut { mode } => {
let out_dest = eval_redirection(ctx, mode, *span)?;
ctx.redirect_out = Some(out_dest);

View File

@ -28,7 +28,7 @@ pub enum Argument {
name: DataSlice,
// TODO: rather than `Expression`, this would probably be best served by a specific enum
// type for this purpose.
expr: Box<Expression>,
info: Box<Expression>,
},
}

View File

@ -192,7 +192,7 @@ impl Call {
Argument::ParserInfo {
data,
name: name_slice,
expr,
info: expr,
} if &data[*name_slice] == name.as_bytes() => Some(expr.as_ref()),
_ => None,
})

View File

@ -105,6 +105,10 @@ impl<'a> fmt::Display for FmtInstruction<'a> {
let name = FmtData(self.data, *name);
write!(f, "{:WIDTH$} {name}, {src}", "push-named")
}
Instruction::PushParserInfo { name, info } => {
let name = FmtData(self.data, *name);
write!(f, "{:WIDTH$} {name}, {info:?}", "push-parser-info")
}
Instruction::RedirectOut { mode } => {
write!(f, "{:WIDTH$} {mode}", "redirect-out")
}

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use crate::{
ast::{CellPath, Operator, RangeInclusion},
ast::{CellPath, Expression, Operator, RangeInclusion},
engine::EngineState,
BlockId, DeclId, RegId, Span, VarId,
};
@ -90,6 +90,11 @@ pub enum Instruction {
PushFlag { name: DataSlice },
/// Add a named arg with a value to the next call.
PushNamed { name: DataSlice, src: RegId },
/// Add parser info to the next call.
PushParserInfo {
name: DataSlice,
info: Box<Expression>,
},
/// Set the redirection for stdout for the next call (only)
RedirectOut { mode: RedirectMode },
/// Set the redirection for stderr for the next call (only)