mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-20 18:31:08 +03:00
Merge branch 'master' of github.com:AleoHQ/leo into feature/theorem-tests
This commit is contained in:
commit
8b44cfa9c7
5
.gitignore
vendored
5
.gitignore
vendored
@ -8,3 +8,8 @@
|
||||
**/.crates.toml
|
||||
**/.crates2.json
|
||||
**/bin/
|
||||
|
||||
# Emacs gitignore files
|
||||
*~
|
||||
\#*\#
|
||||
.\#*
|
||||
|
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -46,9 +46,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.41"
|
||||
version = "1.0.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61"
|
||||
checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
@ -1222,6 +1222,7 @@ dependencies = [
|
||||
"leo-imports",
|
||||
"leo-input",
|
||||
"leo-package",
|
||||
"leo-parser",
|
||||
"leo-state",
|
||||
"leo-synthesizer",
|
||||
"notify",
|
||||
@ -2800,9 +2801,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.2.18"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5"
|
||||
checksum = "ab69019741fca4d98be3c62d2b75254528b5432233fd8a4d2739fec20278de48"
|
||||
dependencies = [
|
||||
"ansi_term 0.12.1",
|
||||
"chrono",
|
||||
|
@ -61,6 +61,10 @@ version = "1.5.2"
|
||||
path = "./package"
|
||||
version = "1.5.2"
|
||||
|
||||
[dependencies.leo-parser]
|
||||
path = "./parser"
|
||||
version = "1.5.2"
|
||||
|
||||
[dependencies.leo-state]
|
||||
path = "./state"
|
||||
version = "1.5.2"
|
||||
@ -145,7 +149,7 @@ version = "0.5"
|
||||
version = "0.1"
|
||||
|
||||
[dependencies.tracing-subscriber]
|
||||
version = "0.2"
|
||||
version = "0.2.19"
|
||||
features = [ "fmt" ]
|
||||
|
||||
[dependencies.zip]
|
||||
|
@ -1,3 +1,3 @@
|
||||
function main(a: address, b: address, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: field, b: field, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: group, b: group, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i128, b: i128, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i128, b: i128, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i16, b: i16, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i16, b: i16, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i32, b: i32, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i32, b: i32, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i64, b: i64, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i64, b: i64, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i8, b: i8, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: i8, b: i8, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u128, b: u128, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u128, b: u128, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u16, b: u16, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u16, b: u16, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u32, b: u32, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u32, b: u32, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u64, b: u64, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u64, b: u64, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u8, b: u8, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
function main(a: u8, b: u8, c: bool) {
|
||||
console.assert(a != b == c);
|
||||
console.assert((a != b) == c);
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::{FormattedError, IntegerType, LeoError, Span};
|
||||
use leo_ast::{FormattedError, LeoError, Span};
|
||||
|
||||
use snarkvm_gadgets::errors::{SignedIntegerError, UnsignedIntegerError};
|
||||
use snarkvm_r1cs::SynthesisError;
|
||||
@ -68,7 +68,7 @@ impl IntegerError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn integer_type_mismatch(expected: &IntegerType, received: IntegerType, span: &Span) -> Self {
|
||||
pub fn integer_type_mismatch(expected: String, received: String, span: &Span) -> Self {
|
||||
let message = format!("expected data type `{}`, found `{}`", expected, received);
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use crate::{
|
||||
address::Address,
|
||||
errors::FunctionError,
|
||||
errors::{FunctionError, IntegerError},
|
||||
program::ConstrainedProgram,
|
||||
value::{
|
||||
boolean::input::bool_from_input,
|
||||
@ -101,9 +101,19 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
Ok(ConstrainedValue::Field(FieldType::constant(cs, value, span)?))
|
||||
}
|
||||
(Type::Group, InputValue::Group(value)) => Ok(ConstrainedValue::Group(G::constant(&value.into(), span)?)),
|
||||
(Type::Integer(integer_type), InputValue::Integer(_, value)) => Ok(ConstrainedValue::Integer(
|
||||
Integer::new(&ConstInt::parse(integer_type, &value, span)?),
|
||||
)),
|
||||
(Type::Integer(integer_type), InputValue::Integer(input_type, value)) => {
|
||||
let parsed = ConstInt::parse(integer_type, &value, span)?;
|
||||
let parsed_type = parsed.get_int_type();
|
||||
let input_type = input_type.into();
|
||||
if std::mem::discriminant(&parsed_type) != std::mem::discriminant(&input_type) {
|
||||
return Err(FunctionError::from(IntegerError::integer_type_mismatch(
|
||||
input_type.to_string(),
|
||||
parsed_type.to_string(),
|
||||
span,
|
||||
)));
|
||||
}
|
||||
Ok(ConstrainedValue::Integer(Integer::new(&parsed)))
|
||||
}
|
||||
(Type::Array(type_, arr_len), InputValue::Array(values)) => {
|
||||
if *arr_len != values.len() {
|
||||
return Err(FunctionError::invalid_input_array_dimensions(
|
||||
|
@ -247,6 +247,9 @@ impl<F: PrimeField> ToBytesGadget<F> for FieldType<F> {
|
||||
|
||||
impl<F: PrimeField> std::fmt::Display for FieldType<F> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self.get_value().ok_or(std::fmt::Error))
|
||||
match self.get_value().ok_or(std::fmt::Error) {
|
||||
Ok(value) => write!(f, "{}", value),
|
||||
value => write!(f, "{:?}", value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -539,8 +539,11 @@ impl One for EdwardsGroupType {
|
||||
impl std::fmt::Display for EdwardsGroupType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
EdwardsGroupType::Constant(constant) => write!(f, "{:?}", constant),
|
||||
EdwardsGroupType::Allocated(allocated) => write!(f, "{:?}", allocated),
|
||||
EdwardsGroupType::Constant(constant) => write!(f, "({}, {})group", constant.x, constant.y),
|
||||
EdwardsGroupType::Allocated(allocated) => match (allocated.x.get_value(), allocated.y.get_value()) {
|
||||
(Some(x), Some(y)) => write!(f, "({}, {})group", x, y),
|
||||
allocated => write!(f, "{:?}", allocated),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +160,11 @@ impl Integer {
|
||||
if let InputValue::Integer(type_, number) = input {
|
||||
let asg_type = IntegerType::from(type_);
|
||||
if std::mem::discriminant(&asg_type) != std::mem::discriminant(integer_type) {
|
||||
return Err(IntegerError::integer_type_mismatch(integer_type, asg_type, span));
|
||||
return Err(IntegerError::integer_type_mismatch(
|
||||
integer_type.to_string(),
|
||||
asg_type.to_string(),
|
||||
span,
|
||||
));
|
||||
}
|
||||
Some(number)
|
||||
} else {
|
||||
|
@ -96,8 +96,8 @@ impl<'a, F: PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<'a, F
|
||||
.unwrap_or_else(|| "[allocated]".to_string())
|
||||
),
|
||||
ConstrainedValue::Char(ref value) => write!(f, "{}", value),
|
||||
ConstrainedValue::Field(ref value) => write!(f, "{:?}", value),
|
||||
ConstrainedValue::Group(ref value) => write!(f, "{:?}", value),
|
||||
ConstrainedValue::Field(ref value) => write!(f, "{}", value),
|
||||
ConstrainedValue::Group(ref value) => write!(f, "{}", value),
|
||||
ConstrainedValue::Integer(ref value) => write!(f, "{}", value),
|
||||
|
||||
// Data type wrappers
|
||||
|
@ -17,7 +17,7 @@ DRAFT
|
||||
|
||||
# Summary
|
||||
|
||||
This proposal suggests adding countdown loops and inclusive loop ranges into Leo language.
|
||||
This proposal suggests adding countdown loops and inclusive loop ranges into the Leo language.
|
||||
|
||||
# Motivation
|
||||
|
||||
@ -122,9 +122,36 @@ function shaker_sort(a: [u32; 10], const rounds: u32) -> [u32; 10] {
|
||||
}
|
||||
```
|
||||
|
||||
## Possible Future Extension
|
||||
|
||||
While the ability to designate the ending bound of a loop as either exclusive or inclusive is critical as discussed below,
|
||||
we could also consider adding the ability to designate the starting bound of a loop as either exclusive or inclusive.
|
||||
If we do that, we run into a sort of asymmetry in the defaults for starting and ending bounds:
|
||||
the default for the starting bound is inclusive, while the default for ending bounds is exclusive.
|
||||
|
||||
The most symmetric but verbose approach is exemplified as follows:
|
||||
* `0=..=5` for `0 1 2 3 4 5`
|
||||
* `0<..=5` for `1 2 3 4 5`
|
||||
* `0=..<5` for `0 1 2 3 4`
|
||||
* `0<..<5` for `1 2 3 4`
|
||||
* `5=..=0` for `5 4 3 2 1 0`
|
||||
* `5>..=0` for `4 3 2 1 0`
|
||||
* `5=..>0` for `5 4 3 2 1`
|
||||
* `5>..>0` for `4 3 2 1`
|
||||
That is, this approach makes exclusivensss an inclusiveness implicit.
|
||||
The use of `<` vs. `>` also indicates a loop direction, which can be inferred anyhow when the `const` bounds are resolved,
|
||||
so that would entail an additional consistency check,
|
||||
namely that the inequality sign/signs is/are consistent with the inferred loop direction.
|
||||
|
||||
Within the symmetric approach above, there are different options for defaults.
|
||||
The most symmetric default would be perhaps `=` for both bounds,
|
||||
but that would be a different behavior from current Leo.
|
||||
We could instead go for different defaults for starting and ending bounds,
|
||||
i.e. `=` for the starting bound and `<` or `>` (depending on direction) for the ending bound.
|
||||
|
||||
# Drawbacks
|
||||
|
||||
-
|
||||
No obvious drawback.
|
||||
|
||||
# Effect on Ecosystem
|
||||
|
||||
|
@ -466,7 +466,7 @@ described above.
|
||||
newline = line-feed / carriage-return / carriage-return line-feed
|
||||
```
|
||||
|
||||
Go to: _[line-feed](#user-content-line-feed), [carriage-return](#user-content-carriage-return)_;
|
||||
Go to: _[carriage-return](#user-content-carriage-return), [line-feed](#user-content-line-feed)_;
|
||||
|
||||
|
||||
Line terminators form whitespace, along with spaces and horizontal tabs.
|
||||
@ -476,7 +476,7 @@ Line terminators form whitespace, along with spaces and horizontal tabs.
|
||||
whitespace = space / horizontal-tab / newline
|
||||
```
|
||||
|
||||
Go to: _[space](#user-content-space), [newline](#user-content-newline), [horizontal-tab](#user-content-horizontal-tab)_;
|
||||
Go to: _[newline](#user-content-newline), [space](#user-content-space), [horizontal-tab](#user-content-horizontal-tab)_;
|
||||
|
||||
|
||||
There are two kinds of comments in Leo, as in other languages.
|
||||
@ -494,7 +494,7 @@ the ones used in the Java language reference.
|
||||
comment = block-comment / end-of-line-comment
|
||||
```
|
||||
|
||||
Go to: _[block-comment](#user-content-block-comment), [end-of-line-comment](#user-content-end-of-line-comment)_;
|
||||
Go to: _[end-of-line-comment](#user-content-end-of-line-comment), [block-comment](#user-content-block-comment)_;
|
||||
|
||||
|
||||
<a name="block-comment"></a>
|
||||
@ -511,7 +511,7 @@ rest-of-block-comment = "*" rest-of-block-comment-after-star
|
||||
/ not-star rest-of-block-comment
|
||||
```
|
||||
|
||||
Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star)_;
|
||||
Go to: _[not-star](#user-content-not-star), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [rest-of-block-comment](#user-content-rest-of-block-comment)_;
|
||||
|
||||
|
||||
<a name="rest-of-block-comment-after-star"></a>
|
||||
@ -521,7 +521,7 @@ rest-of-block-comment-after-star = "/"
|
||||
/ not-star-or-slash rest-of-block-comment
|
||||
```
|
||||
|
||||
Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash)_;
|
||||
Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_;
|
||||
|
||||
|
||||
<a name="end-of-line-comment"></a>
|
||||
@ -633,13 +633,22 @@ Go to: _[letter](#user-content-letter)_;
|
||||
|
||||
A package name consists of one or more segments separated by single dashes,
|
||||
where each segment is a non-empty sequence of lowercase letters and digits.
|
||||
Similarly to an identifier, a package name must not be a keyword
|
||||
and must not be or start with `aleo1`.
|
||||
|
||||
<a name="package-name"></a>
|
||||
```abnf
|
||||
package-name = 1*( lowercase-letter / digit )
|
||||
package-name = lowercase-letter *( lowercase-letter / digit )
|
||||
*( "-" 1*( lowercase-letter / digit ) )
|
||||
; but not a keyword or aleo1...
|
||||
```
|
||||
|
||||
Go to: _[lowercase-letter](#user-content-lowercase-letter)_;
|
||||
|
||||
|
||||
Note that, grammatically, identifiers are also package names.
|
||||
They are disambiguated from context, based on the syntactic grammar.
|
||||
|
||||
Annotations have names, which are identifiers immediately preceded by `@`.
|
||||
|
||||
<a name="annotation-name"></a>
|
||||
@ -753,7 +762,7 @@ and Unicode escapes with one to six hexadecimal digits
|
||||
character-literal = single-quote character-literal-element single-quote
|
||||
```
|
||||
|
||||
Go to: _[single-quote](#user-content-single-quote), [character-literal-element](#user-content-character-literal-element)_;
|
||||
Go to: _[character-literal-element](#user-content-character-literal-element), [single-quote](#user-content-single-quote)_;
|
||||
|
||||
|
||||
<a name="character-literal-element"></a>
|
||||
@ -764,7 +773,7 @@ character-literal-element = not-single-quote-or-backslash
|
||||
/ unicode-character-escape
|
||||
```
|
||||
|
||||
Go to: _[unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_;
|
||||
Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash)_;
|
||||
|
||||
|
||||
<a name="single-quote-escape"></a>
|
||||
@ -819,7 +828,7 @@ simple-character-escape = single-quote-escape
|
||||
/ null-character-escape
|
||||
```
|
||||
|
||||
Go to: _[null-character-escape](#user-content-null-character-escape), [carriage-return-escape](#user-content-carriage-return-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [backslash-escape](#user-content-backslash-escape), [line-feed-escape](#user-content-line-feed-escape)_;
|
||||
Go to: _[line-feed-escape](#user-content-line-feed-escape), [carriage-return-escape](#user-content-carriage-return-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [backslash-escape](#user-content-backslash-escape)_;
|
||||
|
||||
|
||||
<a name="ascii-character-escape"></a>
|
||||
@ -827,7 +836,7 @@ Go to: _[null-character-escape](#user-content-null-character-escape), [carriage-
|
||||
ascii-character-escape = %s"\x" octal-digit hexadecimal-digit
|
||||
```
|
||||
|
||||
Go to: _[octal-digit](#user-content-octal-digit), [hexadecimal-digit](#user-content-hexadecimal-digit)_;
|
||||
Go to: _[hexadecimal-digit](#user-content-hexadecimal-digit), [octal-digit](#user-content-octal-digit)_;
|
||||
|
||||
|
||||
<a name="unicode-character-escape"></a>
|
||||
@ -858,7 +867,7 @@ string-literal-element = not-double-quote-or-backslash
|
||||
/ unicode-character-escape
|
||||
```
|
||||
|
||||
Go to: _[ascii-character-escape](#user-content-ascii-character-escape), [not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape)_;
|
||||
Go to: _[not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape), [simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape)_;
|
||||
|
||||
|
||||
The ones above are all the atomic literals
|
||||
@ -878,7 +887,7 @@ atomic-literal = untyped-literal
|
||||
/ string-literal
|
||||
```
|
||||
|
||||
Go to: _[product-group-literal](#user-content-product-group-literal), [field-literal](#user-content-field-literal), [untyped-literal](#user-content-untyped-literal), [boolean-literal](#user-content-boolean-literal), [address-literal](#user-content-address-literal), [unsigned-literal](#user-content-unsigned-literal), [character-literal](#user-content-character-literal), [signed-literal](#user-content-signed-literal), [string-literal](#user-content-string-literal)_;
|
||||
Go to: _[field-literal](#user-content-field-literal), [untyped-literal](#user-content-untyped-literal), [boolean-literal](#user-content-boolean-literal), [signed-literal](#user-content-signed-literal), [product-group-literal](#user-content-product-group-literal), [string-literal](#user-content-string-literal), [address-literal](#user-content-address-literal), [character-literal](#user-content-character-literal), [unsigned-literal](#user-content-unsigned-literal)_;
|
||||
|
||||
|
||||
After defining the (mostly) alphanumeric tokens above,
|
||||
@ -922,7 +931,7 @@ token = keyword
|
||||
/ symbol
|
||||
```
|
||||
|
||||
Go to: _[symbol](#user-content-symbol), [identifier](#user-content-identifier), [package-name](#user-content-package-name), [keyword](#user-content-keyword), [atomic-literal](#user-content-atomic-literal), [annotation-name](#user-content-annotation-name)_;
|
||||
Go to: _[annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword), [symbol](#user-content-symbol), [identifier](#user-content-identifier), [package-name](#user-content-package-name), [atomic-literal](#user-content-atomic-literal)_;
|
||||
|
||||
|
||||
|
||||
@ -979,7 +988,7 @@ group-type = %s"group"
|
||||
arithmetic-type = integer-type / field-type / group-type
|
||||
```
|
||||
|
||||
Go to: _[integer-type](#user-content-integer-type), [group-type](#user-content-group-type), [field-type](#user-content-field-type)_;
|
||||
Go to: _[integer-type](#user-content-integer-type), [field-type](#user-content-field-type), [group-type](#user-content-group-type)_;
|
||||
|
||||
|
||||
The arithmetic types, along with the boolean, address, and character types,
|
||||
@ -1005,7 +1014,7 @@ character-type = %s"char"
|
||||
scalar-type = boolean-type / arithmetic-type / address-type / character-type
|
||||
```
|
||||
|
||||
Go to: _[arithmetic-type](#user-content-arithmetic-type), [boolean-type](#user-content-boolean-type), [character-type](#user-content-character-type), [address-type](#user-content-address-type)_;
|
||||
Go to: _[arithmetic-type](#user-content-arithmetic-type), [address-type](#user-content-address-type), [boolean-type](#user-content-boolean-type), [character-type](#user-content-character-type)_;
|
||||
|
||||
|
||||
Circuit types are denoted by identifiers and the keyword `Self`.
|
||||
@ -1022,7 +1031,7 @@ self-type = %s"Self"
|
||||
circuit-type = identifier / self-type
|
||||
```
|
||||
|
||||
Go to: _[self-type](#user-content-self-type), [identifier](#user-content-identifier)_;
|
||||
Go to: _[identifier](#user-content-identifier), [self-type](#user-content-self-type)_;
|
||||
|
||||
|
||||
A tuple type consists of zero, two, or more component types.
|
||||
@ -1045,7 +1054,7 @@ or a tuple of one or more dimensions.
|
||||
array-type = "[" type ";" array-dimensions "]"
|
||||
```
|
||||
|
||||
Go to: _[array-dimensions](#user-content-array-dimensions), [type](#user-content-type)_;
|
||||
Go to: _[type](#user-content-type), [array-dimensions](#user-content-array-dimensions)_;
|
||||
|
||||
|
||||
<a name="array-dimensions"></a>
|
||||
@ -1066,7 +1075,7 @@ i.e. types whose values contain (sub-)values
|
||||
aggregate-type = tuple-type / array-type / circuit-type
|
||||
```
|
||||
|
||||
Go to: _[array-type](#user-content-array-type), [tuple-type](#user-content-tuple-type), [circuit-type](#user-content-circuit-type)_;
|
||||
Go to: _[tuple-type](#user-content-tuple-type), [circuit-type](#user-content-circuit-type), [array-type](#user-content-array-type)_;
|
||||
|
||||
|
||||
Scalar and aggregate types form all the types.
|
||||
@ -1076,7 +1085,7 @@ Scalar and aggregate types form all the types.
|
||||
type = scalar-type / aggregate-type
|
||||
```
|
||||
|
||||
Go to: _[aggregate-type](#user-content-aggregate-type), [scalar-type](#user-content-scalar-type)_;
|
||||
Go to: _[scalar-type](#user-content-scalar-type), [aggregate-type](#user-content-aggregate-type)_;
|
||||
|
||||
|
||||
The lexical grammar given earlier defines product group literals.
|
||||
@ -1112,7 +1121,7 @@ A literal is either an atomic one or an affine group literal.
|
||||
literal = atomic-literal / affine-group-literal
|
||||
```
|
||||
|
||||
Go to: _[atomic-literal](#user-content-atomic-literal), [affine-group-literal](#user-content-affine-group-literal)_;
|
||||
Go to: _[affine-group-literal](#user-content-affine-group-literal), [atomic-literal](#user-content-atomic-literal)_;
|
||||
|
||||
|
||||
The following rule is not directly referenced in the rules for expressions
|
||||
@ -1125,7 +1134,7 @@ a group literal is either a product group literal or an affine group literal.
|
||||
group-literal = product-group-literal / affine-group-literal
|
||||
```
|
||||
|
||||
Go to: _[product-group-literal](#user-content-product-group-literal), [affine-group-literal](#user-content-affine-group-literal)_;
|
||||
Go to: _[affine-group-literal](#user-content-affine-group-literal), [product-group-literal](#user-content-product-group-literal)_;
|
||||
|
||||
|
||||
As often done in grammatical language syntax specifications,
|
||||
@ -1154,7 +1163,7 @@ primary-expression = identifier
|
||||
/ circuit-expression
|
||||
```
|
||||
|
||||
Go to: _[literal](#user-content-literal), [identifier](#user-content-identifier), [tuple-expression](#user-content-tuple-expression), [array-expression](#user-content-array-expression), [circuit-expression](#user-content-circuit-expression), [expression](#user-content-expression)_;
|
||||
Go to: _[literal](#user-content-literal), [array-expression](#user-content-array-expression), [identifier](#user-content-identifier), [circuit-expression](#user-content-circuit-expression), [expression](#user-content-expression), [tuple-expression](#user-content-tuple-expression)_;
|
||||
|
||||
|
||||
Tuple expressions construct tuples.
|
||||
@ -1215,7 +1224,7 @@ Go to: _[array-dimensions](#user-content-array-dimensions), [expression](#user-c
|
||||
array-construction = array-inline-construction / array-repeat-construction
|
||||
```
|
||||
|
||||
Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_;
|
||||
Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_;
|
||||
|
||||
|
||||
<a name="array-expression"></a>
|
||||
@ -1243,7 +1252,7 @@ circuit-construction = circuit-type "{"
|
||||
"}"
|
||||
```
|
||||
|
||||
Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [circuit-type](#user-content-circuit-type)_;
|
||||
Go to: _[circuit-type](#user-content-circuit-type), [circuit-inline-element](#user-content-circuit-inline-element)_;
|
||||
|
||||
|
||||
<a name="circuit-inline-element"></a>
|
||||
@ -1251,7 +1260,7 @@ Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [circuit
|
||||
circuit-inline-element = identifier ":" expression / identifier
|
||||
```
|
||||
|
||||
Go to: _[identifier](#user-content-identifier), [expression](#user-content-expression)_;
|
||||
Go to: _[expression](#user-content-expression), [identifier](#user-content-identifier)_;
|
||||
|
||||
|
||||
<a name="circuit-expression"></a>
|
||||
@ -1302,7 +1311,7 @@ postfix-expression = primary-expression
|
||||
/ postfix-expression "[" [expression] ".." [expression] "]"
|
||||
```
|
||||
|
||||
Go to: _[postfix-expression](#user-content-postfix-expression), [expression](#user-content-expression), [identifier](#user-content-identifier), [primary-expression](#user-content-primary-expression), [function-arguments](#user-content-function-arguments), [circuit-type](#user-content-circuit-type), [natural](#user-content-natural)_;
|
||||
Go to: _[postfix-expression](#user-content-postfix-expression), [expression](#user-content-expression), [circuit-type](#user-content-circuit-type), [function-arguments](#user-content-function-arguments), [identifier](#user-content-identifier), [natural](#user-content-natural), [primary-expression](#user-content-primary-expression)_;
|
||||
|
||||
|
||||
Unary operators have the highest operator precedence.
|
||||
@ -1330,7 +1339,7 @@ exponential-expression = unary-expression
|
||||
/ unary-expression "**" exponential-expression
|
||||
```
|
||||
|
||||
Go to: _[unary-expression](#user-content-unary-expression), [exponential-expression](#user-content-exponential-expression)_;
|
||||
Go to: _[exponential-expression](#user-content-exponential-expression), [unary-expression](#user-content-unary-expression)_;
|
||||
|
||||
|
||||
Next in precedence come multiplication and division, both left-associative.
|
||||
@ -1378,11 +1387,11 @@ the rule below makes them left-associative.
|
||||
<a name="equality-expression"></a>
|
||||
```abnf
|
||||
equality-expression = ordering-expression
|
||||
/ equality-expression "==" ordering-expression
|
||||
/ equality-expression "!=" ordering-expression
|
||||
/ ordering-expression "==" ordering-expression
|
||||
/ ordering-expression "!=" ordering-expression
|
||||
```
|
||||
|
||||
Go to: _[equality-expression](#user-content-equality-expression), [ordering-expression](#user-content-ordering-expression)_;
|
||||
Go to: _[ordering-expression](#user-content-ordering-expression)_;
|
||||
|
||||
|
||||
Next come conjunctive expressions, left-associative.
|
||||
@ -1393,7 +1402,7 @@ conjunctive-expression = equality-expression
|
||||
/ conjunctive-expression "&&" equality-expression
|
||||
```
|
||||
|
||||
Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [equality-expression](#user-content-equality-expression)_;
|
||||
Go to: _[equality-expression](#user-content-equality-expression), [conjunctive-expression](#user-content-conjunctive-expression)_;
|
||||
|
||||
|
||||
Next come disjunctive expressions, left-associative.
|
||||
@ -1404,7 +1413,7 @@ disjunctive-expression = conjunctive-expression
|
||||
/ disjunctive-expression "||" conjunctive-expression
|
||||
```
|
||||
|
||||
Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conjunctive-expression](#user-content-conjunctive-expression)_;
|
||||
Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [disjunctive-expression](#user-content-disjunctive-expression)_;
|
||||
|
||||
|
||||
Finally we have conditional expressions.
|
||||
@ -1417,7 +1426,7 @@ conditional-expression = disjunctive-expression
|
||||
":" conditional-expression
|
||||
```
|
||||
|
||||
Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression), [expression](#user-content-expression)_;
|
||||
Go to: _[conditional-expression](#user-content-conditional-expression), [disjunctive-expression](#user-content-disjunctive-expression), [expression](#user-content-expression)_;
|
||||
|
||||
|
||||
Those above are all the expressions.
|
||||
@ -1450,7 +1459,7 @@ statement = expression-statement
|
||||
/ block
|
||||
```
|
||||
|
||||
Go to: _[constant-declaration](#user-content-constant-declaration), [variable-declaration](#user-content-variable-declaration), [conditional-statement](#user-content-conditional-statement), [loop-statement](#user-content-loop-statement), [block](#user-content-block), [assignment-statement](#user-content-assignment-statement), [console-statement](#user-content-console-statement), [expression-statement](#user-content-expression-statement), [return-statement](#user-content-return-statement)_;
|
||||
Go to: _[console-statement](#user-content-console-statement), [constant-declaration](#user-content-constant-declaration), [expression-statement](#user-content-expression-statement), [variable-declaration](#user-content-variable-declaration), [conditional-statement](#user-content-conditional-statement), [loop-statement](#user-content-loop-statement), [return-statement](#user-content-return-statement), [assignment-statement](#user-content-assignment-statement), [block](#user-content-block)_;
|
||||
|
||||
|
||||
<a name="block"></a>
|
||||
@ -1493,7 +1502,7 @@ variable-declaration = %s"let" identifier-or-identifiers [ ":" type ]
|
||||
"=" expression ";"
|
||||
```
|
||||
|
||||
Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_;
|
||||
Go to: _[expression](#user-content-expression), [type](#user-content-type), [identifier-or-identifiers](#user-content-identifier-or-identifiers)_;
|
||||
|
||||
|
||||
<a name="constant-declaration"></a>
|
||||
@ -1525,7 +1534,7 @@ Note that blocks are required in all branches, not merely statements.
|
||||
branch = %s"if" expression block
|
||||
```
|
||||
|
||||
Go to: _[expression](#user-content-expression), [block](#user-content-block)_;
|
||||
Go to: _[block](#user-content-block), [expression](#user-content-expression)_;
|
||||
|
||||
|
||||
<a name="conditional-statement"></a>
|
||||
@ -1535,7 +1544,7 @@ conditional-statement = branch
|
||||
/ branch %s"else" conditional-statement
|
||||
```
|
||||
|
||||
Go to: _[conditional-statement](#user-content-conditional-statement), [branch](#user-content-branch), [block](#user-content-block)_;
|
||||
Go to: _[block](#user-content-block), [branch](#user-content-branch), [conditional-statement](#user-content-conditional-statement)_;
|
||||
|
||||
|
||||
A loop statement implicitly defines a loop variable
|
||||
@ -1547,7 +1556,7 @@ The body is a block.
|
||||
loop-statement = %s"for" identifier %s"in" expression ".." expression block
|
||||
```
|
||||
|
||||
Go to: _[expression](#user-content-expression), [identifier](#user-content-identifier), [block](#user-content-block)_;
|
||||
Go to: _[block](#user-content-block), [identifier](#user-content-identifier), [expression](#user-content-expression)_;
|
||||
|
||||
|
||||
An assignment statement is straightforward.
|
||||
@ -1591,7 +1600,7 @@ console-call = assert-call
|
||||
/ print-call
|
||||
```
|
||||
|
||||
Go to: _[assert-call](#user-content-assert-call), [print-call](#user-content-print-call)_;
|
||||
Go to: _[print-call](#user-content-print-call), [assert-call](#user-content-assert-call)_;
|
||||
|
||||
|
||||
<a name="assert-call"></a>
|
||||
@ -1609,7 +1618,7 @@ print-function = %s"debug" / %s"error" / %s"log"
|
||||
|
||||
<a name="print-arguments"></a>
|
||||
```abnf
|
||||
print-arguments = "(" [ string-literal *( "," expression ) ] ")"
|
||||
print-arguments = "(" string-literal *( "," expression ) ")"
|
||||
```
|
||||
|
||||
Go to: _[string-literal](#user-content-string-literal)_;
|
||||
@ -1650,7 +1659,7 @@ function-declaration = *annotation %s"function" identifier
|
||||
block
|
||||
```
|
||||
|
||||
Go to: _[function-parameters](#user-content-function-parameters), [type](#user-content-type), [block](#user-content-block), [identifier](#user-content-identifier)_;
|
||||
Go to: _[identifier](#user-content-identifier), [block](#user-content-block), [function-parameters](#user-content-function-parameters), [type](#user-content-type)_;
|
||||
|
||||
|
||||
<a name="function-parameters"></a>
|
||||
@ -1660,7 +1669,7 @@ function-parameters = self-parameter
|
||||
/ function-inputs
|
||||
```
|
||||
|
||||
Go to: _[self-parameter](#user-content-self-parameter), [function-inputs](#user-content-function-inputs)_;
|
||||
Go to: _[function-inputs](#user-content-function-inputs), [self-parameter](#user-content-self-parameter)_;
|
||||
|
||||
|
||||
<a name="self-parameter"></a>
|
||||
@ -1724,7 +1733,7 @@ allowing member variables and member functions to be intermixed.
|
||||
|
||||
<a name="circuit-declaration"></a>
|
||||
```abnf
|
||||
circuit-declaration = *annotation %s"circuit" identifier
|
||||
circuit-declaration = %s"circuit" identifier
|
||||
"{" [ member-variable-declarations ]
|
||||
*member-function-declaration "}"
|
||||
```
|
||||
@ -1777,7 +1786,7 @@ declaration = import-declaration
|
||||
/ constant-declaration
|
||||
```
|
||||
|
||||
Go to: _[circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [function-declaration](#user-content-function-declaration), [import-declaration](#user-content-import-declaration)_;
|
||||
Go to: _[import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration), [circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration)_;
|
||||
|
||||
|
||||
<a name="file"></a>
|
||||
@ -1808,4 +1817,3 @@ It does not apply to the lines of the languages described by the grammar.
|
||||
ABNF grammars may describe any kind of languages,
|
||||
with any kind of line terminators,
|
||||
or even without line terminators at all (e.g. for "binary" languages).
|
||||
|
||||
|
@ -452,9 +452,15 @@ identifier = letter *( letter / digit / "_" ) ; but not a keyword or aleo1...
|
||||
|
||||
; A package name consists of one or more segments separated by single dashes,
|
||||
; where each segment is a non-empty sequence of lowercase letters and digits.
|
||||
; Similarly to an identifier, a package name must not be a keyword
|
||||
; and must not be or start with `aleo1`.
|
||||
|
||||
package-name = 1*( lowercase-letter / digit )
|
||||
package-name = lowercase-letter *( lowercase-letter / digit )
|
||||
*( "-" 1*( lowercase-letter / digit ) )
|
||||
; but not a keyword or aleo1...
|
||||
|
||||
; Note that, grammatically, identifiers are also package names.
|
||||
; They are disambiguated from context, based on the syntactic grammar.
|
||||
|
||||
; Annotations have names, which are identifiers immediately preceded by `@`.
|
||||
|
||||
@ -848,8 +854,8 @@ ordering-expression = additive-expression
|
||||
; the rule below makes them left-associative.
|
||||
|
||||
equality-expression = ordering-expression
|
||||
/ equality-expression "==" ordering-expression
|
||||
/ equality-expression "!=" ordering-expression
|
||||
/ ordering-expression "==" ordering-expression
|
||||
/ ordering-expression "!=" ordering-expression
|
||||
|
||||
; Next come conjunctive expressions, left-associative.
|
||||
|
||||
@ -962,7 +968,7 @@ assert-call = %s"assert" "(" expression ")"
|
||||
|
||||
print-function = %s"debug" / %s"error" / %s"log"
|
||||
|
||||
print-arguments = "(" [ string-literal *( "," expression ) ] ")"
|
||||
print-arguments = "(" string-literal *( "," expression ) ")"
|
||||
|
||||
print-call = print-function print-arguments
|
||||
|
||||
@ -1020,7 +1026,7 @@ member-function-declaration = function-declaration
|
||||
; this may be relaxed after the backward compatibility is removed,
|
||||
; allowing member variables and member functions to be intermixed.
|
||||
|
||||
circuit-declaration = *annotation %s"circuit" identifier
|
||||
circuit-declaration = %s"circuit" identifier
|
||||
"{" [ member-variable-declarations ]
|
||||
*member-function-declaration "}"
|
||||
|
||||
|
@ -38,6 +38,8 @@ use tracing::span::Span;
|
||||
/// require Build command output as their input.
|
||||
#[derive(StructOpt, Clone, Debug)]
|
||||
pub struct BuildOptions {
|
||||
#[structopt(long, help = "Disable canonicaliztion compiler optimization")]
|
||||
pub disable_canonicalization: bool,
|
||||
#[structopt(long, help = "Disable constant folding compiler optimization")]
|
||||
pub disable_constant_folding: bool,
|
||||
#[structopt(long, help = "Disable dead code elimination compiler optimization")]
|
||||
@ -57,6 +59,7 @@ pub struct BuildOptions {
|
||||
impl Default for BuildOptions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
disable_canonicalization: true,
|
||||
disable_constant_folding: true,
|
||||
disable_code_elimination: true,
|
||||
disable_all_optimizations: true,
|
||||
@ -78,7 +81,7 @@ impl From<BuildOptions> for CompilerOptions {
|
||||
}
|
||||
} else {
|
||||
CompilerOptions {
|
||||
canonicalization_enabled: true,
|
||||
canonicalization_enabled: !options.disable_canonicalization,
|
||||
constant_folding_enabled: !options.disable_constant_folding,
|
||||
dead_code_elimination_enabled: !options.disable_code_elimination,
|
||||
}
|
||||
@ -162,6 +165,12 @@ impl Command for Build {
|
||||
// Log compilation of files to console
|
||||
tracing::info!("Compiling main program... ({:?})", main_file_path);
|
||||
|
||||
if self.compiler_options.disable_canonicalization && self.compiler_options.enable_canonicalized_theorem {
|
||||
tracing::warn!(
|
||||
"Can not ask for canonicalization theorem without having canonicalization compiler feature enabled."
|
||||
);
|
||||
}
|
||||
|
||||
// Load the program at `main_file_path`
|
||||
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input(
|
||||
package_name.clone(),
|
||||
|
@ -20,6 +20,7 @@ use leo_package::{
|
||||
outputs::OutputsDirectory,
|
||||
root::{ZipFile, AUTHOR_PLACEHOLDER},
|
||||
};
|
||||
use leo_parser::KEYWORD_TOKENS;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use structopt::StructOpt;
|
||||
@ -47,6 +48,10 @@ impl Command for Publish {
|
||||
let manifest = context.manifest()?;
|
||||
|
||||
let package_name = manifest.get_package_name();
|
||||
if KEYWORD_TOKENS.iter().any(|keyword| keyword.to_string() == package_name) {
|
||||
return Err(anyhow!("Cannot name a package after a keyword"));
|
||||
}
|
||||
|
||||
let package_version = manifest.get_package_version();
|
||||
|
||||
match (
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use std::{fmt, sync::Once};
|
||||
|
||||
use anyhow::Result;
|
||||
use colored::Colorize;
|
||||
use tracing::{event::Event, subscriber::Subscriber};
|
||||
use tracing_subscriber::{
|
||||
@ -181,17 +182,23 @@ where
|
||||
|
||||
let mut message = "".to_string();
|
||||
|
||||
let scope = context.scope();
|
||||
for span in scope {
|
||||
message += span.metadata().name();
|
||||
match context.lookup_current() {
|
||||
Some(span_ref) => {
|
||||
let scope = span_ref.scope();
|
||||
|
||||
let ext = span.extensions();
|
||||
let fields = &ext
|
||||
.get::<FormattedFields<N>>()
|
||||
.expect("Unable to find FormattedFields in extensions; this is a bug");
|
||||
if !fields.is_empty() {
|
||||
message += &format!("{{{}}}", fields);
|
||||
for span in scope {
|
||||
message += span.metadata().name();
|
||||
|
||||
let ext = span.extensions();
|
||||
let fields = &ext
|
||||
.get::<FormattedFields<N>>()
|
||||
.expect("Unable to find FormattedFields in extensions; this is a bug");
|
||||
if !fields.is_empty() {
|
||||
message += &format!("{{{}}}", fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => return Err(std::fmt::Error),
|
||||
}
|
||||
|
||||
write!(writer, "{:>10} ", colored_string(meta.level(), &message)).expect("Error writing event");
|
||||
@ -203,10 +210,13 @@ where
|
||||
}
|
||||
|
||||
/// Initialize logger with custom format and verbosity.
|
||||
pub fn init_logger(_app_name: &'static str, verbosity: usize) {
|
||||
pub fn init_logger(_app_name: &'static str, verbosity: usize) -> Result<()> {
|
||||
// This line enables Windows 10 ANSI coloring API.
|
||||
#[cfg(target_family = "windows")]
|
||||
ansi_term::enable_ansi_support();
|
||||
match ansi_term::enable_ansi_support() {
|
||||
Ok(_) => {}
|
||||
Err(_) => return Err(anyhow::anyhow!("Error: Failed to enable ansi_support")),
|
||||
};
|
||||
|
||||
let subscriber = FmtSubscriber::builder()
|
||||
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
|
||||
@ -226,4 +236,5 @@ pub fn init_logger(_app_name: &'static str, verbosity: usize) {
|
||||
START.call_once(|| {
|
||||
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
12
leo/main.rs
12
leo/main.rs
@ -38,7 +38,7 @@ use commands::{
|
||||
Watch,
|
||||
};
|
||||
|
||||
use anyhow::Error;
|
||||
use anyhow::Result;
|
||||
use std::{path::PathBuf, process::exit};
|
||||
use structopt::{clap::AppSettings, StructOpt};
|
||||
|
||||
@ -185,13 +185,13 @@ fn main() {
|
||||
}
|
||||
|
||||
/// Run command with custom build arguments.
|
||||
fn run_with_args(opt: Opt) -> Result<(), Error> {
|
||||
fn run_with_args(opt: Opt) -> Result<()> {
|
||||
if !opt.quiet {
|
||||
// Init logger with optional debug flag.
|
||||
logger::init_logger("leo", match opt.debug {
|
||||
false => 1,
|
||||
true => 2,
|
||||
});
|
||||
})?;
|
||||
}
|
||||
|
||||
// Get custom root folder and create context for it.
|
||||
@ -225,7 +225,7 @@ fn run_with_args(opt: Opt) -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_error<T>(res: Result<T, Error>) -> T {
|
||||
fn handle_error<T>(res: Result<T>) -> T {
|
||||
match res {
|
||||
Ok(t) => t,
|
||||
Err(err) => {
|
||||
@ -239,13 +239,13 @@ fn handle_error<T>(res: Result<T, Error>) -> T {
|
||||
mod cli_tests {
|
||||
use crate::{run_with_args, Opt};
|
||||
|
||||
use anyhow::Error;
|
||||
use anyhow::Result;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use test_dir::{DirBuilder, FileType, TestDir};
|
||||
|
||||
// Runs Command from cmd-like argument "leo run --arg1 --arg2".
|
||||
fn run_cmd(args: &str, path: &Option<PathBuf>) -> Result<(), Error> {
|
||||
fn run_cmd(args: &str, path: &Option<PathBuf>) -> Result<()> {
|
||||
let args = args.split(' ').collect::<Vec<&str>>();
|
||||
let mut opts = Opt::from_iter_safe(args)?;
|
||||
|
||||
|
@ -36,6 +36,19 @@ use crate::{
|
||||
/// - relative to source dir - where Cargo.toml is located
|
||||
const PEDERSEN_HASH_PATH: &str = "./examples/pedersen-hash/";
|
||||
|
||||
#[test]
|
||||
pub fn init_logger() -> Result<()> {
|
||||
crate::logger::init_logger("test_init_logger", 1)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn format_event() -> Result<()> {
|
||||
crate::logger::init_logger("test_format_event", 1)?;
|
||||
tracing::info!("test");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn build_pedersen_hash() -> Result<()> {
|
||||
(Build {
|
||||
|
@ -100,6 +100,10 @@ impl SyntaxError {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn unexpected_statement(got: String, expected: &str, span: &Span) -> Self {
|
||||
Self::new_from_span(format!("expected '{}', got '{}'", expected, got), span)
|
||||
}
|
||||
|
||||
pub fn unexpected_str(got: &Token, expected: &str, span: &Span) -> Self {
|
||||
Self::new_from_span(format!("expected '{}', got '{}'", expected, got.to_string()), span)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
extern crate thiserror;
|
||||
|
||||
pub(crate) mod tokenizer;
|
||||
pub use tokenizer::KEYWORD_TOKENS;
|
||||
pub(crate) use tokenizer::*;
|
||||
|
||||
pub mod errors;
|
||||
|
@ -187,7 +187,7 @@ impl ParserContext {
|
||||
///
|
||||
pub fn parse_equality_expression(&mut self) -> SyntaxResult<Expression> {
|
||||
let mut expr = self.parse_ordering_expression()?;
|
||||
while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) {
|
||||
if let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) {
|
||||
let right = self.parse_ordering_expression()?;
|
||||
expr = Expression::Binary(BinaryExpression {
|
||||
span: expr.span() + right.span(),
|
||||
|
@ -102,11 +102,20 @@ impl ParserContext {
|
||||
let end_span;
|
||||
let arguments = if self.eat(Token::LeftParen).is_some() {
|
||||
let mut args = Vec::new();
|
||||
let mut comma = false;
|
||||
loop {
|
||||
if let Some(end) = self.eat(Token::RightParen) {
|
||||
if comma {
|
||||
return Err(SyntaxError::unexpected(
|
||||
&Token::RightParen,
|
||||
&[Token::Ident("identifier".into()), Token::Int("number".into())],
|
||||
&end.span,
|
||||
));
|
||||
}
|
||||
end_span = end.span;
|
||||
break;
|
||||
}
|
||||
comma = false;
|
||||
if let Some(ident) = self.eat_identifier() {
|
||||
args.push(ident.name);
|
||||
} else if let Some((int, _)) = self.eat_int() {
|
||||
@ -115,10 +124,11 @@ impl ParserContext {
|
||||
let token = self.peek()?;
|
||||
return Err(SyntaxError::unexpected_str(&token.token, "ident or int", &token.span));
|
||||
}
|
||||
if self.eat(Token::Comma).is_none() {
|
||||
if self.eat(Token::Comma).is_none() && !comma {
|
||||
end_span = self.expect(Token::RightParen)?;
|
||||
break;
|
||||
}
|
||||
comma = true;
|
||||
}
|
||||
args
|
||||
} else {
|
||||
|
@ -185,7 +185,17 @@ impl ParserContext {
|
||||
self.fuzzy_struct_state = false;
|
||||
let body = self.parse_block()?;
|
||||
let next = if self.eat(Token::Else).is_some() {
|
||||
Some(Box::new(self.parse_statement()?))
|
||||
let s = self.parse_statement()?;
|
||||
match s {
|
||||
Statement::Block(_) | Statement::Conditional(_) => Some(Box::new(s)),
|
||||
s => {
|
||||
return Err(SyntaxError::unexpected_statement(
|
||||
s.to_string(),
|
||||
"Block or Conditional",
|
||||
s.span(),
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -22,6 +22,7 @@
|
||||
pub(crate) mod token;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use self::token::KEYWORD_TOKENS;
|
||||
pub(crate) use self::token::*;
|
||||
|
||||
pub(crate) mod lexer;
|
||||
|
@ -1,3 +1,3 @@
|
||||
function main(a: group, b: group, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
console.assert((a == b) == c);
|
||||
}
|
@ -8,5 +8,5 @@ function main(y: bool) -> bool {
|
||||
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
|
||||
const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ function main(y: bool) -> bool {
|
||||
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
|
||||
const b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const actual = arr[..2]; // Should produce [0, 1]
|
||||
|
||||
return expected == actual == y;
|
||||
return (expected == actual) == y;
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ function main(y: bool) -> bool {
|
||||
const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline
|
||||
const b: [u32; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -12,5 +12,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ function main(y: bool) -> bool {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
const b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -12,5 +12,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -12,5 +12,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const b: [u8; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -12,5 +12,5 @@ function main(y: bool) -> bool{
|
||||
|
||||
const b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer
|
||||
|
||||
return a == b == y;
|
||||
return (a == b) == y;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ circuit Foo {
|
||||
function main(y: bool) -> bool {
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
return 1u8 == f.use_a() == true;
|
||||
return (1u8 == f.use_a()) == true;
|
||||
}
|
||||
|
@ -25,5 +25,5 @@ function main(const x: u8, y: bool) -> bool {
|
||||
const a = Foo { x };
|
||||
const b = Foo::new(x);
|
||||
|
||||
return b.x == a.x == y;
|
||||
return (b.x == a.x) == y;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ circuit Foo {
|
||||
function main(y: bool) -> bool {
|
||||
const a = Foo { x: 1u32 };
|
||||
|
||||
return a.echo() == 1u32 == true;
|
||||
return (a.echo() == 1u32) == true;
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ circuit Foo {
|
||||
function main(y: bool) -> bool {
|
||||
const a = Foo::echo(1u32);
|
||||
|
||||
return a == 1u32 == y;
|
||||
return (a == 1u32) == y;
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ circuit Foo {
|
||||
function main(y: bool) -> bool {
|
||||
const a = Foo { x: 1u32 };
|
||||
|
||||
return a.x == 1u32 == y;
|
||||
return (a.x == 1u32) == y;
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ function main(y: bool) -> bool {
|
||||
const a = Foo { foo: 1 };
|
||||
const b = a.foo + Foo::bar();
|
||||
|
||||
return b == 2u32 == y;
|
||||
return (b == 2u32) == y;
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ function main(y: bool) -> bool {
|
||||
f.set_a(1u8);
|
||||
f.set_a(2u8);
|
||||
|
||||
return f.a == 2u8 == y;
|
||||
return (f.a == 2u8) == y;
|
||||
}
|
||||
|
@ -22,5 +22,5 @@ function main(y: bool) -> bool {
|
||||
f.set_a(false, 2u8);
|
||||
f.set_a(true, 2u8);
|
||||
|
||||
return f.a == 2u8 == y;
|
||||
return (f.a == 2u8) == y;
|
||||
}
|
||||
|
@ -14,5 +14,5 @@ function main(y: bool) -> bool {
|
||||
f.a = 1u8;
|
||||
f.a = 2u8;
|
||||
|
||||
return f.a == 2u8 == true;
|
||||
return (f.a == 2u8) == true;
|
||||
}
|
||||
|
@ -25,5 +25,5 @@ function main(y: bool) -> bool {
|
||||
const t = TestMe {x: 6u8}.test_me();
|
||||
const u = my_fn().test_me();
|
||||
const v = TestMe::new().test_me();
|
||||
return v == 2u8 == y;
|
||||
return (v == 2u8) == y;
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ function main(y: bool) -> bool {
|
||||
const a = Foo { f: 1u32 };
|
||||
const b = a.bar();
|
||||
|
||||
return b == 1u32 == y;
|
||||
return (b == 1u32) == y;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ function main(y: bool) -> bool {
|
||||
a += one();
|
||||
}
|
||||
|
||||
return a == 10u32 == y;
|
||||
return (a == 10u32) == y;
|
||||
}
|
||||
|
@ -17,5 +17,5 @@ function iteration() -> u32 {
|
||||
function main(y: bool) -> bool {
|
||||
const total = iteration() + iteration();
|
||||
|
||||
return total == 20 == y;
|
||||
return (total == 20) == y;
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ function one() -> bool {
|
||||
function main(y: bool) -> bool {
|
||||
const a = one() && one();
|
||||
|
||||
return a == true == y;
|
||||
return (a == true) == y;
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ function one() -> u32 {
|
||||
}
|
||||
|
||||
function main(y: bool) -> bool {
|
||||
return one() == 1u32 == y;
|
||||
return (one() == 1u32) == y;
|
||||
}
|
||||
|
@ -21,5 +21,5 @@ function main(y: bool) -> bool {
|
||||
const a = 1u32;
|
||||
bad_mutate(a);
|
||||
|
||||
return a == 1u32 == y; // <- value `a` is still `1u32`
|
||||
return (a == 1u32) == y; // <- value `a` is still `1u32`
|
||||
}
|
||||
|
@ -6,5 +6,5 @@
|
||||
import test-import.foo as bar;
|
||||
|
||||
function main(y: bool) -> bool {
|
||||
return bar() == 1u32 == y;
|
||||
return (bar() == 1u32) == y;
|
||||
}
|
||||
|
@ -6,5 +6,5 @@
|
||||
import test-import.foo;
|
||||
|
||||
function main(y: bool) -> bool {
|
||||
return foo() == 1u32 == true;
|
||||
return (foo() == 1u32) == true;
|
||||
}
|
||||
|
@ -27,5 +27,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const car = Car { c: 1u32 };
|
||||
|
||||
return car.c == 1u32 == y;
|
||||
return (car.c == 1u32) == y;
|
||||
}
|
||||
|
@ -20,5 +20,5 @@ function main(y: bool) -> bool {
|
||||
|
||||
const car = Car { c: 1u32 };
|
||||
|
||||
return car.c == 1u32 == y;
|
||||
return (car.c == 1u32) == y;
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ import test-import.(
|
||||
function main(y: bool) -> bool {
|
||||
const a = Point { x: 1u32, y: 0u32 };
|
||||
|
||||
return a.x == 1u32 == y;
|
||||
return (a.x == 1u32) == y;
|
||||
}
|
||||
|
@ -8,5 +8,5 @@ import test-import.*;
|
||||
function main(y: bool) -> bool {
|
||||
const a = Point { x: 1u32, y: 0u32 };
|
||||
|
||||
return foo() == 1u32 == y;
|
||||
return (foo() == 1u32) == y;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/const_input_non_const.in
|
||||
*/
|
||||
|
||||
function main(a: u32) {
|
||||
let b = a * 2;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/var_in_both_sections_fail.in
|
||||
*/
|
||||
|
||||
function main(const a: u32) {
|
||||
let b = a * 2;
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/different_types_signed_fail.in
|
||||
input_file: input/different_types_const_signed_fail.in
|
||||
input_file: input/main_fail_type.in
|
||||
*/
|
||||
|
||||
function main(const a: i32) {
|
@ -2,8 +2,6 @@
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/different_types_const_unsigned_fail.in
|
||||
input_file: input/different_types_unsigned_fail.in
|
||||
input_file: input/main_fail_type.in
|
||||
*/
|
||||
|
||||
function main(const a: u32) {
|
@ -1,9 +1,7 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/different_types_signed_fail.in
|
||||
input_file: input/different_types_const_signed_fail.in
|
||||
input_file: input/var_in_both_sections_fail.in
|
||||
input_file: input/different_types_fail_signed.in
|
||||
*/
|
||||
|
||||
function main(a: i32) {
|
||||
|
@ -1,9 +1,7 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/different_types_const_unsigned_fail.in
|
||||
input_file: input/different_types_unsigned_fail.in
|
||||
input_file: input/var_in_both_sections_fail.in
|
||||
*/
|
||||
|
||||
function main(a: u32) {
|
@ -0,0 +1,2 @@
|
||||
[constants]
|
||||
a: u32 = 2;
|
@ -0,0 +1,2 @@
|
||||
[main]
|
||||
a: u32 = 2;
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/non_const_input_const.in
|
||||
*/
|
||||
|
||||
function main(aconst : u32) {
|
||||
let b = a * 2;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: input/var_in_both_sections_fail.in
|
||||
*/
|
||||
|
||||
function main(a: u32) {
|
||||
let b = a * 2;
|
||||
}
|
@ -5,5 +5,5 @@ input_file: input/main.in
|
||||
*/
|
||||
|
||||
function main(const a: bool, b: bool) -> bool {
|
||||
return a == true == b;
|
||||
return (a == true) == b;
|
||||
}
|
||||
|
@ -6,5 +6,5 @@ input_file: input/main_array.in
|
||||
|
||||
function main(const x: [i16; 1], y: bool) -> bool {
|
||||
console.log("{}", x);
|
||||
return x[0] == 0 == y;
|
||||
return (x[0] == 0) == y;
|
||||
}
|
||||
|
@ -5,5 +5,5 @@ input_file: input/main_multiple.in
|
||||
*/
|
||||
|
||||
function main(const a: bool, const b: bool, y: bool) -> bool {
|
||||
return a != b == y;
|
||||
return (a != b) == y;
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ inputs:
|
||||
*/
|
||||
|
||||
function main(a: i128, b: i128, c: bool) -> bool {
|
||||
return a == b == c;
|
||||
return (a == b) == c;
|
||||
}
|
||||
|
@ -21,5 +21,5 @@ inputs:
|
||||
*/
|
||||
|
||||
function main(a: i128, b: i128, c: bool) -> bool{
|
||||
return a != b == c;
|
||||
return (a != b) == c;
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ input_file: ../input/dummy.in
|
||||
function main(y: bool) -> bool{
|
||||
const a = -128i128;
|
||||
const b = -a;
|
||||
return b == -a == y;
|
||||
return (b == -a) == y;
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ inputs:
|
||||
function main(y: bool) -> bool {
|
||||
const a = 0i128;
|
||||
|
||||
return -a == 0i128 == y;
|
||||
return (-a == 0i128) == y;
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ inputs:
|
||||
*/
|
||||
|
||||
function main(a: i16, b: i16, c: bool) -> bool {
|
||||
return a == b == c;
|
||||
return (a == b) == c;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user