-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(std_lib): println statements (#630)
* preliminary strings work, type added to Hir and abi * nargo build working for simple str types * initial strings work. can input to abi and compare string literal. strings currently mock array functionality * little cleanup and test addition * cargo clippy and fixed decoding of public string values in toml * some pr comments, moving to use str keyword * clarifying comment for string toml type to input value * pr comments * starting log work * update missing type from monomorphisation ast * update display for string types * preliminary logging work, can log strings and arrays stored in idents. need to create Log directive for more accurate logging logic * switch to using Log directive * switch to using builtin function for println rather than having a new opcode in ssa * some missing cleanup to remove Log operation from SSA * fix convert type for new string type * cargo fmt * fix up some minor PR nitpicks * decode method for string of field into abi string * small cleanuo * println for blackbox func output now working. need to still do some final testing and cleanup * little cleanup and additional comments * parsing toml now follow abi * additional parser error and some comments * fix usage of to_bytes with master merge * working string inputs inside struct inputs to main * cargo clippy cleanup * remove unused err * additional test case for type directed toml parsing * use remote acvm repo, do not merge as need to wait for acvm to be updated first * update cargo lock * clippy * more cargo clippy fixes * chore: remove unwanted dependency to old acir crate * remove old comments * add nocapture flag to test and start println output on new line * use refactored SsaContext methods * switc to show-logs over nocapture flag for printing test output * cargo clippy changes * remove comment * PR comments * some more pr comments, prepend 0x to hex strings and removed prepended inputs * format_field_str method so that we have even number of digits in hex str * added comment to format_field_string * cargo clippy * bring back cached_witness() method on InternalVar * cargo fmt --------- Co-authored-by: TomAFrench <tom@tomfren.ch>
- Loading branch information
1 parent
0108ac6
commit d5d1be2
Showing
17 changed files
with
312 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
message = "hello world" | ||
y = 5 | ||
hex_as_string = "0x41" | ||
hex_as_field = "0x41" | ||
hex_as_field = "0x41" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,56 @@ | ||
fn main(message : pub str<11>, hex_as_string : str<4>, hex_as_field : Field) { | ||
use dep::std; | ||
|
||
fn main(message : pub str<11>, y : Field, hex_as_string : str<4>, hex_as_field : Field) { | ||
let mut bad_message = "hello world"; | ||
|
||
constrain message == "hello world"; | ||
bad_message = "helld world"; | ||
let x = 10; | ||
let z = x * 5; | ||
std::println(10); | ||
|
||
std::println(z); // x * 5 in println not yet supported | ||
std::println(x); | ||
|
||
let array = [1, 2, 3, 5, 8]; | ||
constrain y == 5; // Change to y != 5 to see how the later print statements are not called | ||
std::println(array); | ||
|
||
std::println(bad_message); | ||
constrain message != bad_message; | ||
|
||
let hash = std::hash::pedersen([x]); | ||
std::println(hash); | ||
|
||
constrain hex_as_string == "0x41"; | ||
// constrain hex_as_string != 0x41; This will fail with a type mismatch between str[4] and Field | ||
constrain hex_as_field == 0x41; | ||
} | ||
|
||
#[test] | ||
fn test_prints_strings() { | ||
let message = "hello world!"; | ||
|
||
std::println(message); | ||
std::println("goodbye world"); | ||
} | ||
|
||
#[test] | ||
fn test_prints_array() { | ||
let array = [1, 2, 3, 5, 8]; | ||
|
||
// TODO: Printing structs currently not supported | ||
// let s = Test { a: 1, b: 2, c: [3, 4] }; | ||
// std::println(s); | ||
|
||
std::println(array); | ||
|
||
let hash = std::hash::pedersen(array); | ||
std::println(hash); | ||
} | ||
|
||
struct Test { | ||
a: Field, | ||
b: Field, | ||
c: [Field; 2], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.