Merge branch 'master' of github.com:AleoHQ/leo into login_command

This commit is contained in:
Sergey Isaev 2020-08-07 12:48:40 +03:00
commit b2c40649f6
16 changed files with 124 additions and 45 deletions

22
Cargo.lock generated
View File

@ -1284,7 +1284,7 @@ checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
[[package]]
name = "snarkos-algorithms"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"blake2",
"derivative",
@ -1304,7 +1304,7 @@ dependencies = [
[[package]]
name = "snarkos-curves"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"derivative",
"rand",
@ -1319,7 +1319,7 @@ dependencies = [
[[package]]
name = "snarkos-derives"
version = "0.1.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"proc-macro2 1.0.19",
"quote 1.0.7",
@ -1329,7 +1329,7 @@ dependencies = [
[[package]]
name = "snarkos-dpc"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"blake2",
"derivative",
@ -1350,7 +1350,7 @@ dependencies = [
[[package]]
name = "snarkos-errors"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"base58",
"bech32",
@ -1363,7 +1363,7 @@ dependencies = [
[[package]]
name = "snarkos-gadgets"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"derivative",
"digest 0.8.1",
@ -1378,7 +1378,7 @@ dependencies = [
[[package]]
name = "snarkos-models"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"bincode",
"derivative",
@ -1394,7 +1394,7 @@ dependencies = [
[[package]]
name = "snarkos-objects"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"base58",
"bech32",
@ -1415,7 +1415,7 @@ dependencies = [
[[package]]
name = "snarkos-parameters"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"hex",
"snarkos-algorithms",
@ -1427,12 +1427,12 @@ dependencies = [
[[package]]
name = "snarkos-profiler"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
[[package]]
name = "snarkos-utilities"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#90d41a91b6a431a6cf506a395247e22a3e98b488"
dependencies = [
"bincode",
"rand",

View File

@ -15,6 +15,7 @@ impl From<Error<Rule>> for SyntaxError {
Rule::type_integer => "`u32`".to_owned(),
Rule::type_field => "`field`".to_owned(),
Rule::type_group => "`group`".to_owned(),
Rule::address => "an aleo address: `aleo1...`".to_owned(),
Rule::file => "an import, circuit, or function".to_owned(),
Rule::identifier => "a variable name".to_owned(),
Rule::type_ => "a type".to_owned(),

View File

@ -1,4 +1,4 @@
use crate::{ast::Rule, common::SpreadOrExpression, values::Value, SpanDef};
use crate::{ast::Rule, common::SpreadOrExpression, values::PositiveNumber, SpanDef};
use pest::Span;
use pest_ast::FromPest;
@ -8,7 +8,7 @@ use serde::Serialize;
#[pest_ast(rule(Rule::expression_array_initializer))]
pub struct ArrayInitializerExpression<'ast> {
pub expression: Box<SpreadOrExpression<'ast>>,
pub count: Value<'ast>,
pub count: PositiveNumber<'ast>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,

View File

@ -169,7 +169,7 @@ type_self = { "Self" }
type_circuit = { identifier }
// Declared in types/array_type.rs
type_array = { type_data ~ ("[" ~ value ~ "]")+ }
type_array = { type_data ~ ("[" ~ positive_number ~ "]")+ }
type_list = _{ (type_ ~ ("," ~ type_)*)? }
@ -188,6 +188,9 @@ value = {
// Declared in values/number_value.rs
value_number = @{ (("-" ~ ASCII_NONZERO_DIGIT) | "0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT* }
// Declared in values/number_positive.rs
positive_number = @{ ("0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT*}
// Declared in values/number_implicit_value.rs
value_implicit = { value_number }
@ -206,7 +209,7 @@ group_tuple = {"(" ~ value_number ~ "," ~ value_number ~ ")"}
group_single_or_tuple = {value_number | group_tuple}
// Declared in values/address.rs
address = @{ (LOWERCASE_LETTER | ASCII_DIGIT)* }
address = @{ "aleo" ~ ASCII_DIGIT ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} }
// Declared in values/address_value.rs
value_address = { type_address ~ "(" ~ address ~ ")" }
@ -271,7 +274,7 @@ expression_tuple = _{ (expression ~ ("," ~ expression)*)? }
expression = { expression_term ~ (operation_binary ~ expression_term)* }
// Declared in expressions/array_initializer_expression.rs
expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ value ~ "]" }
expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ positive_number ~ "]" }
// Declared in expressions/array_inline_expression.rs
expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"}
@ -294,12 +297,11 @@ statement = {
(statement_return
| statement_conditional
| statement_for
| (statement_multiple_assignment
| statement_multiple_assignment
| statement_macro
| statement_definition
| statement_assign
| statement_expression
)
) ~ NEWLINE*
}

View File

@ -1,4 +1,4 @@
use crate::{ast::Rule, types::DataType, values::Value, SpanDef};
use crate::{ast::Rule, types::DataType, values::PositiveNumber, SpanDef};
use pest::Span;
use pest_ast::FromPest;
@ -8,7 +8,7 @@ use serde::Serialize;
#[pest_ast(rule(Rule::type_array))]
pub struct ArrayType<'ast> {
pub _type: DataType,
pub dimensions: Vec<Value<'ast>>,
pub dimensions: Vec<PositiveNumber<'ast>>,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,

View File

@ -22,5 +22,8 @@ pub use number_implicit_value::*;
pub mod number_value;
pub use number_value::*;
pub mod positive_number;
pub use positive_number::*;
pub mod value;
pub use value::*;

View File

@ -0,0 +1,25 @@
use crate::{
ast::{span_into_string, Rule},
span::SpanDef,
};
use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::positive_number))]
pub struct PositiveNumber<'ast> {
#[pest_ast(outer(with(span_into_string)))]
pub value: String,
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}
impl<'ast> fmt::Display for PositiveNumber<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value)
}
}

View File

@ -0,0 +1,3 @@
function main() {
let owner = address();
}

View File

@ -0,0 +1,3 @@
function main() {
let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88);
}

View File

@ -13,11 +13,27 @@ fn test_valid() {
}
#[test]
fn test_invalid() {
let bytes = include_bytes!("invalid.leo");
let program = parse_program(bytes).unwrap();
fn test_invalid_prefix() {
let bytes = include_bytes!("invalid_prefix.leo");
let syntax_error = parse_program(bytes).is_err();
let _output = expect_compiler_error(program);
assert!(syntax_error);
}
#[test]
fn test_invalid_length() {
let bytes = include_bytes!("invalid_length.leo");
let syntax_error = parse_program(bytes).is_err();
assert!(syntax_error);
}
#[test]
fn test_empty() {
let bytes = include_bytes!("empty.leo");
let syntax_error = parse_program(bytes).is_err();
assert!(syntax_error);
}
#[test]

View File

@ -0,0 +1,3 @@
function main(a: u8[3]) {
assert_eq!(a, [1u8; -3]);
}

View File

@ -42,6 +42,14 @@ fn test_registers() {
// Expressions
#[test]
fn test_type_fail() {
let program_bytes = include_bytes!("type_fail.leo");
let syntax_error = parse_program(program_bytes).is_err();
assert!(syntax_error);
}
#[test]
fn test_inline() {
let program_bytes = include_bytes!("inline.leo");
@ -68,6 +76,15 @@ fn test_initializer() {
assert_satisfied(program);
}
#[test]
fn test_initializer_fail() {
let program_bytes = include_bytes!("initializer_fail.leo");
let input_bytes = include_bytes!("input/three_ones.in");
let syntax_error = parse_program_with_input(program_bytes, input_bytes).is_err();
assert!(syntax_error);
}
#[test]
fn test_spread() {
let program_bytes = include_bytes!("spread.leo");

View File

@ -0,0 +1,3 @@
let main() {
let a: u32[-2] = [0u32; 2];
}

View File

@ -13,11 +13,19 @@ use leo_ast::{
TernaryExpression,
},
operations::BinaryOperation,
values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberImplicitValue, Value},
values::{
AddressValue,
BooleanValue,
FieldValue,
GroupValue,
IntegerValue,
NumberImplicitValue,
PositiveNumber as LeoPositiveNumber,
Value,
},
};
use leo_ast::values::AddressValue;
use leo_input::values::NumberValue;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -104,21 +112,16 @@ impl Expression {
}
impl<'ast> Expression {
pub(crate) fn get_count_from_value(count: Value<'ast>) -> usize {
match count {
Value::Integer(integer) => integer
.number
.value
.parse::<usize>()
.expect("Unable to read array size"),
Value::Implicit(number) => number.number.value.parse::<usize>().expect("Unable to read array size"),
size => unimplemented!("Array size should be an integer {}", size),
}
}
pub(crate) fn get_count_from_number(number: NumberValue<'ast>) -> usize {
number.value.parse::<usize>().expect("Unable to read array size")
}
pub(crate) fn get_count_from_positive_number(number: LeoPositiveNumber<'ast>) -> usize {
number
.value
.parse::<usize>()
.expect("Array size should be a positive number")
}
}
impl<'ast> fmt::Display for Expression {
@ -403,7 +406,7 @@ impl<'ast> From<ArrayInlineExpression<'ast>> for Expression {
impl<'ast> From<ArrayInitializerExpression<'ast>> for Expression {
fn from(array: ArrayInitializerExpression<'ast>) -> Self {
let count = Expression::get_count_from_value(array.count);
let count = Expression::get_count_from_positive_number(array.count);
let expression = Box::new(SpreadOrExpression::from(*array.expression));
Expression::Array(vec![expression; count], Span::from(array.span))

View File

@ -101,7 +101,7 @@ impl<'ast> From<ArrayType<'ast>> for Type {
let dimensions = array_type
.dimensions
.into_iter()
.map(|row| Expression::get_count_from_value(row))
.map(|row| Expression::get_count_from_positive_number(row))
.collect();
Type::Array(element_type, dimensions)