From 9796c20c5dbae2f1e88a78530ed3348908c6865f Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Tue, 11 Jun 2024 17:08:08 -0700 Subject: [PATCH] more efficient tracebacks Signed-off-by: Ava Affine --- src/error.rs | 7 +++---- src/stl/control.rs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/error.rs b/src/error.rs index aaddc77..7df44c3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -35,10 +35,9 @@ impl Traceback { Traceback(vec![]) } - pub fn with_trace(&self, item: TraceItem) -> Traceback { - let mut next = Traceback(self.0.clone()); - next.0.push(item); - next + pub fn with_trace(mut self, item: TraceItem) -> Traceback { + self.0.push(item); + self } pub fn depth(&self) -> usize { diff --git a/src/stl/control.rs b/src/stl/control.rs index 2544603..0d45cce 100644 --- a/src/stl/control.rs +++ b/src/stl/control.rs @@ -330,7 +330,7 @@ example: (circuit (eq? (do-operation) myresult) in this example, do-another-operation will not be called"; fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result { let mut cursor = 0; - let mut err_trace = Traceback::new(); + let mut err_trace: Traceback = Traceback::new(); let result = ast.circuit(&mut |form: &Ctr| -> bool { cursor += 1; let operand: &Seg; @@ -358,7 +358,7 @@ fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result { } else if let Ctr::Integer(i) = *s.car { return i==0; } else { - err_trace = err_trace.with_trace( + err_trace = err_trace.clone().with_trace( ("circuit", "impossible condition") .into()); } @@ -366,7 +366,7 @@ fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result { Ctr::Integer(i) => return i == 0, - _ => err_trace = err_trace.with_trace( + _ => err_trace = err_trace.clone().with_trace( ("circuit", format!("form {cursor} did not evaluate to a boolean")) .into()), },