Skip to content

Commit

Permalink
name format string instruction fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jan 9, 2024
1 parent 39fa464 commit 320df56
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl From<Instr> for InstrRep {
Instr::Call(index) => Self::Call(index),
Instr::PushFunc(func) => Self::PushFunc(func),
Instr::Switch { count, sig, span } => Self::Switch(count, sig, span),
Instr::Format(strings, span) => Self::Format(strings, span),
Instr::Format { parts, span } => Self::Format(parts, span),
Instr::Dynamic(func) => Self::Dynamic(func),
Instr::Unpack { count, span, unbox } => Self::Unpack(count, span, unbox),
Instr::PushTempFunctions(count) => Self::PushTempFunctions(count),
Expand Down Expand Up @@ -348,7 +348,7 @@ impl From<InstrRep> for Instr {
InstrRep::Call(index) => Self::Call(index),
InstrRep::PushFunc(func) => Self::PushFunc(func),
InstrRep::Switch(count, sig, span) => Self::Switch { count, sig, span },
InstrRep::Format(strings, span) => Self::Format(strings, span),
InstrRep::Format(parts, span) => Self::Format { parts, span },
InstrRep::Dynamic(func) => Self::Dynamic(func),
InstrRep::Unpack(count, span, unbox) => Self::Unpack { count, span, unbox },
InstrRep::PushTempFunctions(count) => Self::PushTempFunctions(count),
Expand Down
2 changes: 1 addition & 1 deletion src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'a> VirtualEnv<'a> {
}
self.handle_args_outputs(sig.args + 1, sig.outputs)?;
}
Instr::Format(parts, _) => {
Instr::Format { parts, .. } => {
self.handle_args_outputs(parts.len().saturating_sub(1), 1)?
}
Instr::Dynamic(f) => self.handle_sig(f.signature)?,
Expand Down
4 changes: 2 additions & 2 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ code:
let signature = Signature::new(frags.len() - 1, 1);
let parts = frags.into_iter().map(Into::into).collect();
let span = self.add_span(word.span.clone());
let instr = Instr::Format(parts, span);
let instr = Instr::Format { parts, span };
if call {
self.push_instr(instr)
} else {
Expand Down Expand Up @@ -825,7 +825,7 @@ code:
}
}
parts.push(curr_part);
let instr = Instr::Format(parts, span);
let instr = Instr::Format { parts, span };
if call {
self.push_instr(instr)
} else {
Expand Down
10 changes: 7 additions & 3 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ pub enum Instr {
sig: Signature,
span: usize,
},
Format(EcoVec<EcoString>, usize),
/// Do a format string
Format {
parts: EcoVec<EcoString>,
span: usize,
},
/// Call a dynamic function
Dynamic(DynamicFunction),
Unpack {
Expand Down Expand Up @@ -140,7 +144,7 @@ impl PartialEq for Instr {
(Self::Prim(a, _), Self::Prim(b, _)) => a == b,
(Self::ImplPrim(a, _), Self::ImplPrim(b, _)) => a == b,
(Self::Call(a), Self::Call(b)) => a == b,
(Self::Format(a, _), Self::Format(b, _)) => a == b,
(Self::Format { parts: a, .. }, Self::Format { parts: b, .. }) => a == b,
(Self::PushFunc(a), Self::PushFunc(b)) => a == b,
(Self::PushTemp { count: a, .. }, Self::PushTemp { count: b, .. }) => a == b,
(Self::PopTemp { count: a, .. }, Self::PopTemp { count: b, .. }) => a == b,
Expand Down Expand Up @@ -217,7 +221,7 @@ impl fmt::Display for Instr {
Instr::PushTempFunctions(count) => write!(f, "<push {count} functions>"),
Instr::PopTempFunctions(count) => write!(f, "<pop {count} functions>"),
Instr::GetTempFunction { offset, .. } => write!(f, "<get function at {offset}>"),
Instr::Format(parts, _) => {
Instr::Format { parts, .. } => {
write!(f, "$\"")?;
for (i, part) in parts.iter().enumerate() {
if i > 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ code:
env.rt.function_stack.push(f.clone());
Ok(())
}),
Instr::Format(parts, span) => {
Instr::Format { parts, span } => {
let parts = parts.clone();
self.with_span(*span, |env| {
let mut s = String::new();
Expand Down

0 comments on commit 320df56

Please sign in to comment.