From 320df565111901771349333f293bdc299ae90845 Mon Sep 17 00:00:00 2001 From: Kai Schmidt Date: Tue, 9 Jan 2024 08:12:32 -0800 Subject: [PATCH] name format string instruction fields --- src/assembly.rs | 4 ++-- src/check.rs | 2 +- src/compile.rs | 4 ++-- src/function.rs | 10 +++++++--- src/run.rs | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/assembly.rs b/src/assembly.rs index e4c848fca..c686d5f8f 100644 --- a/src/assembly.rs +++ b/src/assembly.rs @@ -308,7 +308,7 @@ impl From 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), @@ -348,7 +348,7 @@ impl From 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), diff --git a/src/check.rs b/src/check.rs index a1aec37fa..2e693bc1f 100644 --- a/src/check.rs +++ b/src/check.rs @@ -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)?, diff --git a/src/compile.rs b/src/compile.rs index fc24efd49..0fc4749bc 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -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 { @@ -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 { diff --git a/src/function.rs b/src/function.rs index d370d6681..bbda6eed7 100644 --- a/src/function.rs +++ b/src/function.rs @@ -58,7 +58,11 @@ pub enum Instr { sig: Signature, span: usize, }, - Format(EcoVec, usize), + /// Do a format string + Format { + parts: EcoVec, + span: usize, + }, /// Call a dynamic function Dynamic(DynamicFunction), Unpack { @@ -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, @@ -217,7 +221,7 @@ impl fmt::Display for Instr { Instr::PushTempFunctions(count) => write!(f, ""), Instr::PopTempFunctions(count) => write!(f, ""), Instr::GetTempFunction { offset, .. } => write!(f, ""), - Instr::Format(parts, _) => { + Instr::Format { parts, .. } => { write!(f, "$\"")?; for (i, part) in parts.iter().enumerate() { if i > 0 { diff --git a/src/run.rs b/src/run.rs index 7e49b8007..95f0db924 100644 --- a/src/run.rs +++ b/src/run.rs @@ -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();