Skip to content

Commit

Permalink
Add newline param to print oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
grasshopper47 committed Nov 29, 2023
1 parent 9c96b98 commit 575b2c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 3 additions & 4 deletions noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ mod test;
// Thus, the only argument to the `print` oracle is expected to always be an ident

#[oracle(print)]
unconstrained fn print_oracle<T>(_input: T) {}
unconstrained fn print_oracle<T>(_input: T, _newline: bool) {}

unconstrained pub fn print<T>(input: T) {
print_oracle(input);
print_oracle(input, false);
}

unconstrained pub fn println<T>(input: T) {
print(f"{input}
"); // skip a 2nd oracle call; use multi-line format to insert a newline
print_oracle(input, true);
}

#[foreign(recursive_aggregation)]
Expand Down
8 changes: 7 additions & 1 deletion tooling/nargo/src/ops/foreign_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ impl DefaultForeignCallExecutor {

fn execute_print(foreign_call_inputs: &[ForeignCallParam]) -> Result<(), ForeignCallError> {
let display_values: PrintableValueDisplay = foreign_call_inputs.try_into()?;
print!("{display_values}");

if foreign_call_inputs[1].unwrap_value().is_zero() {
print!("{display_values}");
} else {
println!("{display_values}");
}

Ok(())
}
}
Expand Down

0 comments on commit 575b2c0

Please sign in to comment.