Skip to content

Commit

Permalink
Merge pull request #26901 from AleoHQ/feat/leo-deploy
Browse files Browse the repository at this point in the history
Leo Deploy
  • Loading branch information
d0cd authored Feb 12, 2024
2 parents e0632d6 + 95d95f2 commit a2e3155
Show file tree
Hide file tree
Showing 753 changed files with 5,930 additions and 5,054 deletions.
486 changes: 243 additions & 243 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ version = "1.0"
[dependencies.serial_test]
version = "3.0.0"

#[dependencies.snarkos-cli]
#version = "2.2.4"

#[dependencies.snarkos-cli]
#version = "2.2.4"

[dependencies.snarkvm]
workspace = true
features = [ "circuit", "console" ]
Expand Down
8 changes: 4 additions & 4 deletions compiler/ast/src/access/associated_function_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 crate::{Expression, Identifier, Node, NodeID, Type};
use crate::{Expression, Identifier, Node, NodeID};
use leo_span::Span;

use serde::{Deserialize, Serialize};
Expand All @@ -23,8 +23,8 @@ use std::fmt;
/// An access expression to an associated function in a struct, e.g.`Pedersen64::hash()`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AssociatedFunction {
/// The inner struct type.
pub ty: Type,
/// The inner struct variant.
pub variant: Identifier,
/// The static struct member function that is being accessed.
pub name: Identifier,
/// The arguments passed to the function `name`.
Expand All @@ -37,7 +37,7 @@ pub struct AssociatedFunction {

impl fmt::Display for AssociatedFunction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}::{}", self.ty, self.name)
write!(f, "{}::{}", self.variant, self.name)
}
}

Expand Down
14 changes: 4 additions & 10 deletions compiler/ast/src/expressions/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use super::*;
use leo_span::Symbol;

/// A function call expression, e.g.`foo(args)` or `Foo::bar(args)`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -24,8 +25,8 @@ pub struct CallExpression {
pub function: Box<Expression>, // todo: make this identifier?
/// Expressions for the arguments passed to the functions parameters.
pub arguments: Vec<Expression>,
/// The name of the external program call, e.g.`bar` in `bar.leo`.
pub external: Option<Box<Expression>>,
/// The name of the parent program call, e.g.`bar` in `bar.aleo`.
pub program: Option<Symbol>,
/// Span of the entire call `function(arguments)`.
pub span: Span,
/// The ID of the node.
Expand All @@ -34,14 +35,7 @@ pub struct CallExpression {

impl fmt::Display for CallExpression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.external {
Some(external) => {
write!(f, "{external}.leo/{}(", self.function)?;
}
None => {
write!(f, "{}(", self.function)?;
}
}
write!(f, "{}(", self.function)?;

for (i, param) in self.arguments.iter().enumerate() {
write!(f, "{param}")?;
Expand Down
4 changes: 2 additions & 2 deletions compiler/ast/src/functions/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 crate::{Identifier, Node, NodeID, Type};
use crate::{CompositeType, Identifier, Node, NodeID, Type};
use leo_span::Span;

use serde::{Deserialize, Serialize};
Expand All @@ -37,7 +37,7 @@ pub struct External {

impl External {
pub fn type_(&self) -> Type {
Type::Identifier(self.record)
Type::Composite(CompositeType { id: self.record, program: Some(self.program_name.name) })
}
}

Expand Down
10 changes: 5 additions & 5 deletions compiler/ast/src/mapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{Identifier, Node, NodeID, Type};

use leo_span::Span;
use leo_span::{Span, Symbol};

use serde::{Deserialize, Serialize};
use snarkvm::prelude::{Mapping as MappingCore, Network};
Expand All @@ -37,12 +37,12 @@ pub struct Mapping {
pub id: NodeID,
}

impl<N: Network> From<&MappingCore<N>> for Mapping {
fn from(mapping: &MappingCore<N>) -> Self {
impl Mapping {
pub fn from_snarkvm<N: Network>(mapping: &MappingCore<N>, program: Symbol) -> Self {
Self {
identifier: Identifier::from(mapping.name()),
key_type: Type::from(mapping.key().plaintext_type()),
value_type: Type::from(mapping.value().plaintext_type()),
key_type: Type::from_snarkvm(mapping.key().plaintext_type(), program),
value_type: Type::from_snarkvm(mapping.value().plaintext_type(), program),
span: Default::default(),
id: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/ast/src/passes/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub trait FunctionConsumer {
pub trait StructConsumer {
type Output;

fn consume_struct(&mut self, input: Struct) -> Self::Output;
fn consume_struct(&mut self, input: Composite) -> Self::Output;
}

/// A Consumer trait for imported programs in the AST.
Expand Down
6 changes: 3 additions & 3 deletions compiler/ast/src/passes/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub trait ExpressionReconstructor {
fn reconstruct_associated_function(&mut self, input: AssociatedFunction) -> (Expression, Self::AdditionalOutput) {
(
Expression::Access(AccessExpression::AssociatedFunction(AssociatedFunction {
ty: input.ty,
variant: input.variant,
name: input.name,
arguments: input.arguments.into_iter().map(|arg| self.reconstruct_expression(arg).0).collect(),
span: input.span,
Expand Down Expand Up @@ -142,7 +142,7 @@ pub trait ExpressionReconstructor {
Expression::Call(CallExpression {
function: Box::new(self.reconstruct_expression(*input.function).0),
arguments: input.arguments.into_iter().map(|arg| self.reconstruct_expression(arg).0).collect(),
external: input.external,
program: input.program,
span: input.span,
id: input.id,
}),
Expand Down Expand Up @@ -483,7 +483,7 @@ pub trait ProgramReconstructor: StatementReconstructor {
input
}

fn reconstruct_struct(&mut self, input: Struct) -> Struct {
fn reconstruct_struct(&mut self, input: Composite) -> Composite {
input
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/ast/src/passes/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub trait ProgramVisitor<'a>: StatementVisitor<'a> {
self.visit_program(input)
}

fn visit_struct(&mut self, _input: &'a Struct) {}
fn visit_struct(&mut self, _input: &'a Composite) {}

fn visit_mapping(&mut self, _input: &'a Mapping) {}

Expand All @@ -255,5 +255,5 @@ pub trait ProgramVisitor<'a>: StatementVisitor<'a> {

fn visit_function_stub(&mut self, _input: &'a FunctionStub) {}

fn visit_struct_stub(&mut self, _input: &'a Struct) {}
fn visit_struct_stub(&mut self, _input: &'a Composite) {}
}
10 changes: 10 additions & 0 deletions compiler/ast/src/program/program_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crate::Identifier;

use core::fmt;
use leo_span::Symbol;
use serde::{de, de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
use snarkvm::{console::program::ProgramID, prelude::Network};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -99,3 +100,12 @@ impl<N: Network> From<&ProgramID<N>> for ProgramId {
Self { name: Identifier::from(program.name()), network: Identifier::from(program.network()) }
}
}

impl From<Identifier> for ProgramId {
fn from(name: Identifier) -> Self {
Self {
name,
network: Identifier { name: Symbol::intern("aleo"), span: Default::default(), id: Default::default() },
}
}
}
4 changes: 2 additions & 2 deletions compiler/ast/src/program/program_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! A Leo program scope consists of struct, function, and mapping definitions.

use crate::{ConstDeclaration, Function, Mapping, ProgramId, Struct, Stub};
use crate::{Composite, ConstDeclaration, Function, Mapping, ProgramId, Stub};

use leo_span::{Span, Symbol};
use serde::{Deserialize, Serialize};
Expand All @@ -30,7 +30,7 @@ pub struct ProgramScope {
/// A vector of const definitions
pub consts: Vec<(Symbol, ConstDeclaration)>,
/// A vector of struct definitions.
pub structs: Vec<(Symbol, Struct)>,
pub structs: Vec<(Symbol, Composite)>,
/// A vector of mapping definitions.
pub mappings: Vec<(Symbol, Mapping)>,
/// A vector of function definitions.
Expand Down
110 changes: 55 additions & 55 deletions compiler/ast/src/struct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,85 +32,44 @@ use snarkvm::{
},
};

/// A struct type definition, e.g., `struct Foo { my_field: Bar }`.
/// A composite type definition, e.g., `struct Foo { my_field: Bar }` and `record Token { owner: address, amount: u64}`.
/// In some languages these are called `struct`s.
///
/// Type identity is decided by the full path including `struct_name`,
/// as the record is nominal, not structural.
/// The fields are named so `struct Foo(u8, u16)` is not allowed.
#[derive(Clone, Serialize, Deserialize)]
pub struct Struct {
pub struct Composite {
/// The name of the type in the type system in this module.
pub identifier: Identifier,
/// The fields, constant variables, and functions of this structure.
pub members: Vec<Member>,
/// The external program the struct is defined in.
pub external: Option<Symbol>,
/// Was this a `record Foo { ... }`?
/// If so, it wasn't a struct.
/// If so, it wasn't a composite.
pub is_record: bool,
/// The entire span of the struct definition.
/// The entire span of the composite definition.
pub span: Span,
/// The ID of the node.
pub id: NodeID,
}

impl PartialEq for Struct {
impl PartialEq for Composite {
fn eq(&self, other: &Self) -> bool {
self.identifier == other.identifier
}
}

impl Eq for Struct {}
impl Eq for Composite {}

impl Struct {
/// Returns the struct name as a Symbol.
impl Composite {
/// Returns the composite name as a Symbol.
pub fn name(&self) -> Symbol {
self.identifier.name
}
}

impl fmt::Debug for Struct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<Self as fmt::Display>::fmt(self, f)
}
}

impl fmt::Display for Struct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(if self.is_record { "record" } else { "struct" })?;
writeln!(f, " {} {{ ", self.identifier)?;
for field in self.members.iter() {
writeln!(f, " {field}")?;
}
write!(f, " }}")
}
}

crate::simple_node_impl!(Struct);

impl<N: Network> From<&StructType<N>> for Struct {
fn from(input: &StructType<N>) -> Self {
Self {
identifier: Identifier::from(input.name()),
members: input
.members()
.iter()
.map(|(id, type_)| Member {
mode: Mode::None,
identifier: Identifier::from(id),
type_: Type::from(type_),
span: Default::default(),
id: Default::default(),
})
.collect(),
is_record: false,
span: Default::default(),
id: Default::default(),
}
}
}

impl<N: Network> From<&RecordType<N>> for Struct {
fn from(input: &RecordType<N>) -> Self {
pub fn from_external_record<N: Network>(input: &RecordType<N>, external_program: Symbol) -> Self {
Self {
identifier: Identifier::from(input.name()),
members: [
Expand All @@ -128,19 +87,60 @@ impl<N: Network> From<&RecordType<N>> for Struct {
mode: if input.owner().is_public() { Mode::Public } else { Mode::Private },
identifier: Identifier::from(id),
type_: match entry {
Public(t) => Type::from(t),
Private(t) => Type::from(t),
Constant(t) => Type::from(t),
Public(t) => Type::from_snarkvm(t, external_program),
Private(t) => Type::from_snarkvm(t, external_program),
Constant(t) => Type::from_snarkvm(t, external_program),
},
span: Default::default(),
id: Default::default(),
})
.collect_vec(),
]
.concat(),
external: Some(external_program),
is_record: true,
span: Default::default(),
id: Default::default(),
}
}

pub fn from_snarkvm<N: Network>(input: &StructType<N>, program: Symbol) -> Self {
Self {
identifier: Identifier::from(input.name()),
members: input
.members()
.iter()
.map(|(id, type_)| Member {
mode: Mode::None,
identifier: Identifier::from(id),
type_: Type::from_snarkvm(type_, program),
span: Default::default(),
id: Default::default(),
})
.collect(),
external: Some(program),
is_record: false,
span: Default::default(),
id: Default::default(),
}
}
}

impl fmt::Debug for Composite {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<Self as fmt::Display>::fmt(self, f)
}
}

impl fmt::Display for Composite {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(if self.is_record { "record" } else { "struct" })?;
writeln!(f, " {} {{ ", self.identifier)?;
for field in self.members.iter() {
writeln!(f, " {field}")?;
}
write!(f, " }}")
}
}

crate::simple_node_impl!(Composite);
9 changes: 5 additions & 4 deletions compiler/ast/src/stub/finalize_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ impl FinalizeStub {

Self { identifier, input, output, output_type, span, id }
}
}

impl<N: Network, Command: CommandTrait<N>> From<&FinalizeCore<N, Command>> for FinalizeStub {
fn from(finalize: &FinalizeCore<N, Command>) -> Self {
pub fn from_snarkvm<N: Network, Command: CommandTrait<N>>(
finalize: &FinalizeCore<N, Command>,
program: Symbol,
) -> Self {
let mut inputs = Vec::new();

finalize.inputs().iter().enumerate().for_each(|(index, input)| {
Expand All @@ -68,7 +69,7 @@ impl<N: Network, Command: CommandTrait<N>> From<&FinalizeCore<N, Command>> for F
Plaintext(val) => inputs.push(Input::Internal(FunctionInput {
identifier: arg_name,
mode: Mode::None,
type_: Type::from(val),
type_: Type::from_snarkvm(val, program),
span: Default::default(),
id: Default::default(),
})),
Expand Down
Loading

0 comments on commit a2e3155

Please sign in to comment.