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![]) Traceback(vec![])
} }
pub fn with_trace(&self, item: TraceItem) -> Traceback { pub fn with_trace(mut self, item: TraceItem) -> Traceback {
let mut next = Traceback(self.0.clone()); self.0.push(item);
next.0.push(item); self
next
} }
pub fn depth(&self) -> usize { 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"; in this example, do-another-operation will not be called";
fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> { fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
let mut cursor = 0; 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 { let result = ast.circuit(&mut |form: &Ctr| -> bool {
cursor += 1; cursor += 1;
let operand: &Seg; 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 { } else if let Ctr::Integer(i) = *s.car {
return i==0; return i==0;
} else { } else {
err_trace = err_trace.with_trace( err_trace = err_trace.clone().with_trace(
("circuit", "impossible condition") ("circuit", "impossible condition")
.into()); .into());
} }
@ -366,7 +366,7 @@ fn circuit_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
Ctr::Integer(i) => return i == 0, 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")) ("circuit", format!("form {cursor} did not evaluate to a boolean"))
.into()), .into()),
}, },