diff --git a/src/classic/clvm_tools/cmds.rs b/src/classic/clvm_tools/cmds.rs index c392535d5..70e2ccb5a 100644 --- a/src/classic/clvm_tools/cmds.rs +++ b/src/classic/clvm_tools/cmds.rs @@ -740,6 +740,9 @@ pub fn cldb(args: &[String]) { output.push(cvt_subtree); }; + #[cfg(feature = "debug-print")] + cldbrun.set_print_only(only_print); + loop { if cldbrun.is_ended() { println!("{}", yamlette_string(&output)); diff --git a/src/compiler/cldb.rs b/src/compiler/cldb.rs index b36c64390..14ff0dfd7 100644 --- a/src/compiler/cldb.rs +++ b/src/compiler/cldb.rs @@ -110,6 +110,7 @@ pub struct CldbRun { to_print: BTreeMap, in_expr: bool, row: usize, + print_only: bool, outputs_to_step: HashMap, } @@ -168,9 +169,14 @@ impl CldbRun { in_expr: false, row: 0, outputs_to_step: HashMap::::new(), + print_only: false, } } + pub fn set_print_only(&mut self, pronly: bool) { + self.print_only = pronly; + } + pub fn is_ended(&self) -> bool { self.ended } @@ -179,6 +185,16 @@ impl CldbRun { self.final_result.clone() } + #[cfg(feature = "debug-print")] + pub fn should_print_basic_output(&self) -> bool { + !self.print_only + } + + #[cfg(not(feature = "debug-print"))] + pub fn should_print_basic_output(&self) -> bool { + true + } + pub fn step(&mut self, allocator: &mut Allocator) -> Option> { let mut produce_result = false; let mut result = BTreeMap::new(); @@ -197,23 +213,27 @@ impl CldbRun { match &new_step { Ok(RunStep::OpResult(l, x, _p)) => { if self.in_expr { - self.to_print - .insert("Result-Location".to_string(), l.to_string()); - self.to_print.insert("Value".to_string(), x.to_string()); - self.to_print - .insert("Row".to_string(), self.row.to_string()); - if let Ok(n) = x.get_number() { - self.outputs_to_step.insert( - n, - PriorResult { - reference: self.row, - // value: x.clone(), // for future - }, - ); + if self.should_print_basic_output() { + self.to_print + .insert("Result-Location".to_string(), l.to_string()); + self.to_print.insert("Value".to_string(), x.to_string()); + self.to_print + .insert("Row".to_string(), self.row.to_string()); + + if let Ok(n) = x.get_number() { + self.outputs_to_step.insert( + n, + PriorResult { + reference: self.row, + // value: x.clone(), // for future + }, + ); + } + swap(&mut self.to_print, &mut result); + produce_result = true; } + self.in_expr = false; - swap(&mut self.to_print, &mut result); - produce_result = true; } } Ok(RunStep::Done(l, x)) => { @@ -228,12 +248,16 @@ impl CldbRun { } Ok(RunStep::Step(_sexp, _c, _p)) => {} Ok(RunStep::Op(sexp, c, a, None, _p)) => { - self.to_print - .insert("Operator-Location".to_string(), a.loc().to_string()); - self.to_print - .insert("Operator".to_string(), sexp.to_string()); + let should_print_basic_output = self.should_print_basic_output(); + if should_print_basic_output { + self.to_print + .insert("Operator-Location".to_string(), a.loc().to_string()); + self.to_print + .insert("Operator".to_string(), sexp.to_string()); + } + if let Ok(v) = sexp.get_number() { - if v == 11_u32.to_bigint().unwrap() { + if v == 11_u32.to_bigint().unwrap() && should_print_basic_output { // Build source tree for hashes. let arg_associations = get_arg_associations(&self.outputs_to_step, a.clone()); @@ -247,17 +271,21 @@ impl CldbRun { .insert("Print-Location".to_string(), loc.to_string()); self.to_print .insert("Print".to_string(), outputs.to_string()); + swap(&mut self.to_print, &mut result); + produce_result = true; } } } - self.env.add_context( - sexp.borrow(), - c.borrow(), - Some(a.clone()), - &mut self.to_print, - ); - self.env.add_function(sexp, &mut self.to_print); - self.in_expr = true; + if should_print_basic_output { + self.env.add_context( + sexp.borrow(), + c.borrow(), + Some(a.clone()), + &mut self.to_print, + ); + self.env.add_function(sexp, &mut self.to_print); + self.in_expr = true; + } } Ok(RunStep::Op(_sexp, _c, _a, Some(_v), _p)) => {} Err(RunFailure::RunExn(l, s)) => {