mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 15:15:47 +03:00
Merge branch 'master' of https://github.com/AleoHQ/language into fix/namespace
This commit is contained in:
commit
0a990bdb4e
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -1,5 +1,8 @@
|
||||
# The Leo Programming Language
|
||||
|
||||
[![Build Status](https://travis-ci.com/AleoHQ/leo.svg?token=Xy7ht9JdPvr4xSgbPruF&branch=master)](https://travis-ci.com/AleoHQ/leo)
|
||||
[![codecov](https://codecov.io/gh/AleoHQ/leo/branch/master/graph/badge.svg?token=S6MWO60SYL)](https://codecov.io/gh/AleoHQ/leo)
|
||||
|
||||
## Compiler Architecture
|
||||
|
||||
<!-- generated by mermaid compile action - START -->
|
||||
@ -16,7 +19,7 @@ graph LR
|
||||
|
||||
Pass2 -- statements --> Pass4(Synthesizer)
|
||||
|
||||
Pass4 -- constraints --> Pass5(Circuit)
|
||||
Pass4 -- constraints --> Pass5(Program)
|
||||
```
|
||||
|
||||
</details>
|
||||
|
@ -4,7 +4,7 @@ use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[pest_ast(rule(Rule::circuit_definition))]
|
||||
#[pest_ast(rule(Rule::circuit))]
|
||||
pub struct Circuit<'ast> {
|
||||
pub identifier: Identifier<'ast>,
|
||||
pub members: Vec<CircuitMember<'ast>>,
|
||||
|
@ -4,7 +4,7 @@
|
||||
assignee = { identifier ~ access_assignee* }
|
||||
|
||||
// Declared in common/file.rs
|
||||
file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ circuit_definition* ~ NEWLINE* ~ function_definition* ~ NEWLINE* ~ test_function* ~ NEWLINE* ~ EOI }
|
||||
file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ circuit* ~ NEWLINE* ~ function_definition* ~ NEWLINE* ~ test_function* ~ NEWLINE* ~ EOI }
|
||||
|
||||
// Declared in common/identifier.rs
|
||||
identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||
@ -177,7 +177,7 @@ access_static_member = { "::" ~ identifier }
|
||||
/// Circuits
|
||||
|
||||
// Declared in circuits/circuit_definition.rs
|
||||
circuit_definition = { "circuit" ~ identifier ~ "{" ~ NEWLINE* ~ circuit_member* ~ NEWLINE* ~ "}" ~ NEWLINE* }
|
||||
circuit = { "circuit" ~ identifier ~ "{" ~ NEWLINE* ~ circuit_member* ~ NEWLINE* ~ "}" ~ NEWLINE* }
|
||||
|
||||
// Declared in circuits/circuit_field.rs
|
||||
circuit_field = { identifier ~ ":" ~ expression }
|
||||
|
@ -616,7 +616,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
}
|
||||
|
||||
if let Some(ConstrainedValue::CircuitDefinition(circuit_definition)) = self.get_mut(&program_identifier) {
|
||||
let circuit_identifier = circuit_definition.identifier.clone();
|
||||
let circuit_identifier = circuit_definition.circuit_name.clone();
|
||||
let mut resolved_members = vec![];
|
||||
for member in circuit_definition.members.clone().into_iter() {
|
||||
match member {
|
||||
@ -764,14 +764,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
}
|
||||
_ => {
|
||||
return Err(ExpressionError::undefined_member_access(
|
||||
circuit.identifier.to_string(),
|
||||
circuit.circuit_name.to_string(),
|
||||
circuit_member.to_string(),
|
||||
span,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(ConstrainedValue::Function(Some(circuit.identifier), function))
|
||||
Ok(ConstrainedValue::Function(Some(circuit.circuit_name), function))
|
||||
}
|
||||
|
||||
fn enforce_function_call_expression<CS: ConstraintSystem<F>>(
|
||||
|
@ -3,6 +3,7 @@
|
||||
use crate::{constraints::ConstrainedValue, GroupType};
|
||||
|
||||
use snarkos_models::curves::{Field, PrimeField};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct ConstrainedProgram<F: Field + PrimeField, G: GroupType<F>> {
|
||||
|
12
compiler/tests/circuits/member_field_and_function.leo
Normal file
12
compiler/tests/circuits/member_field_and_function.leo
Normal file
@ -0,0 +1,12 @@
|
||||
circuit Foo {
|
||||
foo: u32
|
||||
|
||||
static function bar() -> u32 {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
function main() -> u32 {
|
||||
let f = Foo { foo: 1 };
|
||||
return f.foo + Foo::bar()
|
||||
}
|
@ -114,6 +114,14 @@ fn test_member_field_fail() {
|
||||
fail_undefined_member(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_field_and_function() {
|
||||
let bytes = include_bytes!("member_field_and_function.leo");
|
||||
let program = parse_program(bytes).unwrap();
|
||||
|
||||
output_one(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_function() {
|
||||
let bytes = include_bytes!("member_function.leo");
|
||||
|
@ -5,29 +5,26 @@ use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Circuit {
|
||||
pub identifier: Identifier,
|
||||
pub circuit_name: Identifier,
|
||||
pub members: Vec<CircuitMember>,
|
||||
}
|
||||
|
||||
impl<'ast> From<AstCircuit<'ast>> for Circuit {
|
||||
fn from(circuit: AstCircuit<'ast>) -> Self {
|
||||
let variable = Identifier::from(circuit.identifier);
|
||||
let circuit_name = Identifier::from(circuit.identifier);
|
||||
let members = circuit
|
||||
.members
|
||||
.into_iter()
|
||||
.map(|member| CircuitMember::from(member))
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
identifier: variable,
|
||||
members,
|
||||
}
|
||||
Self { circuit_name, members }
|
||||
}
|
||||
}
|
||||
|
||||
impl Circuit {
|
||||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "circuit {} {{ \n", self.identifier)?;
|
||||
write!(f, "circuit {} {{ \n", self.circuit_name)?;
|
||||
for field in self.members.iter() {
|
||||
write!(f, " {}\n", field)?;
|
||||
}
|
||||
|
@ -198,14 +198,14 @@ impl<'ast> fmt::Display for Expression {
|
||||
|
||||
impl<'ast> From<CircuitInlineExpression<'ast>> for Expression {
|
||||
fn from(expression: CircuitInlineExpression<'ast>) -> Self {
|
||||
let variable = Identifier::from(expression.identifier);
|
||||
let circuit_name = Identifier::from(expression.identifier);
|
||||
let members = expression
|
||||
.members
|
||||
.into_iter()
|
||||
.map(|member| CircuitFieldDefinition::from(member))
|
||||
.collect::<Vec<CircuitFieldDefinition>>();
|
||||
|
||||
Expression::Circuit(variable, members, Span::from(expression.span))
|
||||
Expression::Circuit(circuit_name, members, Span::from(expression.span))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user