more efficient tracebacks

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2024-06-11 17:08:08 -07:00
parent 8f0e2512cc
commit 9796c20c5d
2 changed files with 6 additions and 7 deletions

View file

@ -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 {

View file

@ -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<Ctr, Traceback> {
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<Ctr, Traceback> {
} 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, Traceback> {
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()),
},