Skip to content

Commit

Permalink
Merge pull request #44 from Chia-Network/20230928-print-improve-speed
Browse files Browse the repository at this point in the history
Improve printing speed
  • Loading branch information
prozacchiwawa authored Sep 29, 2023
2 parents 63f0fd5 + 13cc4ec commit 8d3f09f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/classic/clvm_tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
84 changes: 56 additions & 28 deletions src/compiler/cldb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct CldbRun {
to_print: BTreeMap<String, String>,
in_expr: bool,
row: usize,
print_only: bool,

outputs_to_step: HashMap<Number, PriorResult>,
}
Expand Down Expand Up @@ -168,9 +169,14 @@ impl CldbRun {
in_expr: false,
row: 0,
outputs_to_step: HashMap::<Number, PriorResult>::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
}
Expand All @@ -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<BTreeMap<String, String>> {
let mut produce_result = false;
let mut result = BTreeMap::new();
Expand All @@ -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)) => {
Expand All @@ -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());
Expand All @@ -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)) => {
Expand Down

0 comments on commit 8d3f09f

Please sign in to comment.