-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(brillig): Added cast instruction (#1649)
* feat: added cast instruction * docs: add comment on cast * docs: added comment on cast instruction * simplify convert_cast * Alvaro to review * feat: do casts as no ops instead --------- Co-authored-by: kevaundray <kevtheappdev@gmail.com>
- Loading branch information
1 parent
2893855
commit 3050b44
Showing
6 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_cast/Nargo.toml
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
Empty file.
50 changes: 50 additions & 0 deletions
50
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_cast/src/main.nr
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Tests a very simple Brillig function. | ||
// | ||
// The features being tested are cast operations on brillig | ||
fn main() { | ||
bool_casts(); | ||
field_casts(); | ||
uint_casts(); | ||
int_casts(); | ||
mixed_casts(); | ||
} | ||
|
||
unconstrained fn bool_casts() { | ||
assert(false == 0 as bool); | ||
assert(true == 1 as bool); | ||
assert(true == 3 as bool); | ||
} | ||
|
||
unconstrained fn field_casts() { | ||
assert(5 as u8 as Field == 5); | ||
assert(16 as u4 as Field == 0); | ||
} | ||
|
||
unconstrained fn uint_casts() { | ||
let x: u32 = 100; | ||
assert(x as u2 == 0); | ||
assert(x as u4 == 4); | ||
assert(x as u6 == 36); | ||
assert(x as u8 == 100); | ||
assert(x as u64 == 100); | ||
assert(x as u126 == 100); | ||
} | ||
|
||
unconstrained fn int_casts() { | ||
let x: i32 = 100; | ||
assert(x as i2 == 0); | ||
assert(x as i4 == 4); | ||
assert(x as i6 == -28 as i6); | ||
assert(x as i8 == 100); | ||
assert(x as i8 == 100); | ||
assert(x as i8 == 100); | ||
} | ||
|
||
|
||
unconstrained fn mixed_casts() { | ||
assert(100 as u32 as i32 as u32 == 100); | ||
assert(13 as u4 as i2 as u32 == 1); | ||
assert(15 as u4 as i2 as u32 == 3); | ||
assert(1 as u8 as bool == true); | ||
assert(true as i8 == 1); | ||
} |
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