Merge branch 'testnet3' of github.com:AleoHQ/leo into feat/codegen-for-function-calls

This commit is contained in:
collin 2022-08-05 11:51:37 -07:00
commit 64152eb2f7
10 changed files with 138 additions and 181 deletions

View File

@ -136,124 +136,32 @@ jobs:
paths: project/ paths: project/
- clear_environment: - clear_environment:
cache_key: leo-executable-cache cache_key: leo-executable-cache
#
# leo-new:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo new
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-new.sh
#
# leo-init:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo init
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-init.sh
#
# leo-clean:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo clean
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-clean.sh
#
# leo-setup:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo setup
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-setup.sh
# leo-add-remove: leo-new:
# docker: docker:
# - image: cimg/rust:1.62 - image: cimg/rust:1.62
# resource_class: xlarge resource_class: xlarge
# steps: steps:
# - attach_workspace: - attach_workspace:
# at: /home/circleci/project/ at: /home/circleci/project/
# - run: - run:
# name: leo add & remove name: leo new
# command: | command: |
# export LEO=/home/circleci/project/project/bin/leo export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-add-remove.sh ./project/.circleci/leo-new.sh
# todo (collin): uncomment after compiler refactor leo-clean:
# leo-check-constraints: docker:
# docker: - image: cimg/rust:1.62
# - image: cimg/rust:1.62 resource_class: xlarge
# resource_class: xlarge steps:
# steps: - attach_workspace:
# - attach_workspace: at: /home/circleci/project/
# at: /home/circleci/project/ - run:
# - run: name: leo clean
# name: leo check constraints for Pedersen Hash command: |
# command: | export LEO=/home/circleci/project/project/bin/leo
# export LEO=/home/circleci/project/project/bin/leo ./project/.circleci/leo-clean.sh
# ./project/.circleci/leo-check-constraints.sh
#
# leo-login-logout:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo login & logout
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-login-logout.sh
#
# leo-clone:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo clone
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-clone.sh
#
# leo-publish:
# docker:
# - image: cimg/rust:1.62
# resource_class: xlarge
# steps:
# - attach_workspace:
# at: /home/circleci/project/
# - run:
# name: leo publish
# command: |
# export LEO=/home/circleci/project/project/bin/leo
# ./project/.circleci/leo-publish.sh
workflows: workflows:
version: 2 version: 2
@ -262,30 +170,9 @@ workflows:
- check-style - check-style
- clippy - clippy
- leo-executable - leo-executable
# - leo-new: - leo-new:
# requires: requires:
# - leo-executable - leo-executable
# - leo-init: - leo-clean:
# requires: requires:
# - leo-executable - leo-executable
# - leo-clean:
# requires:
# - leo-executable
# - leo-setup:
# requires:
# - leo-executable
# - leo-add-remove:
# requires:
# - leo-executable
# - leo-check-constraints:
# requires:
# - leo-executable
# - leo-login-logout:
# requires:
# - leo-executable
# - leo-clone:
# requires:
# - leo-executable
# - leo-publish:
# requires:
# - leo-executable

View File

@ -1,38 +1,23 @@
# leo new hello-world # Create a new Leo program named `foo`.
$LEO new foo
$LEO new hello-world
ls -la ls -la
cd hello-world && ls -la cd foo && ls -la
# Run `leo build`.
$LEO build $LEO build
# Assert that the 'outputs' folder is not empty # Assert that the 'build' folder exists.
if [ "$(ls -A build)" ]; then
cd outputs || exit 1 echo "build is not empty"
if [ "$(ls -A $DIR)" ]; then
echo "$DIR is not empty"
else else
echo "$DIR is empty" echo "build is empty"
exit 1 exit 1
fi fi
cd ..
# leo clean
# Run `leo clean`
$LEO clean $LEO clean
cd outputs && ls -la
cd ..
# Assert that the 'outputs' folder is empty
if [ "$(ls -A outputs)" ]; then
echo "outputs is not empty"
exit 1
else
echo "outputs is empty"
fi
# Assert that the 'build' folder is empty
# Assert that the 'build' folder is empty.
if [ "$(ls -A build)" ]; then if [ "$(ls -A build)" ]; then
echo "build is not empty" echo "build is not empty"
exit 1 exit 1

View File

@ -1,7 +1,7 @@
# Create a new foo project. # Create a new Leo program named `foo`.
$LEO new foo $LEO new foo
ls -la ls -la
cd foo && ls -la cd foo && ls -la
# Try to compile and run the template project. # Try to run `leo build`.
$LEO run $LEO run

View File

@ -184,13 +184,18 @@ atomic-literal = numeric-literal
/ address-literal / address-literal
/ string-literal / string-literal
symbol = "!" / "&&" / "||" symbol = "!"
/ "&&" / "||"
/ "==" / "!=" / "==" / "!="
/ "<" / "<=" / ">" / ">=" / "<" / "<=" / ">" / ">="
/ "&" / "|" / "^" / "&" / "|" / "^"
/ "<<" / ">>" / "<<" / ">>"
/ "+" / "-" / "*" / "/" / "%" / "**" / "+" / "-" / "*" / "/" / "%" / "**"
/ "=" / "="
/ "+=" / "-=" / "*=" / "/=" / "%=" / "**="
/ "<<=" / ">>="
/ "&=" / "|=" / "^="
/ "&&=" / "||="
/ "(" / ")" / "(" / ")"
/ "[" / "]" / "[" / "]"
/ "{" / "}" / "{" / "}"
@ -375,6 +380,19 @@ loop-statement = %s"for" identifier ":" type
block block
assignment-operator = "=" assignment-operator = "="
/ "+="
/ "-="
/ "*="
/ "/="
/ "%="
/ "**="
/ "<<="
/ ">>="
/ "&="
/ "|="
/ "^="
/ "&&="
/ "||="
assignment-statement = expression assignment-operator expression ";" assignment-statement = expression assignment-operator expression ";"

25
examples/README.md Normal file
View File

@ -0,0 +1,25 @@
# Leo Examples
This directory includes the following Leo code examples:
1. Hello World -> Basic Sum of two u32
2. Groups -> Basic operations over groups
3. Core -> Core circuits functions over a field type
4. Bubblesort -> Sorting algorithms over a tuple
5. Import point -> Import code from an other file
6. Message -> Initialization of a circuit type
7. Token -> Record example
## Build Guide
To compile each example, run:
```bash
leo build
```
When you run this command for the first time the snarkvm parameters (universal setup) will be downloaded, these are necessary to run the circuits.
To run each program, run:
```bash
leo run main
```
This command will look in the input file inputs/*.in where should find a section [main] and use the variables as inputs to the program.

View File

@ -9,5 +9,11 @@ leo build
To run this program, run: To run this program, run:
```bash ```bash
leo run leo run main
``` ```
## Overview
This example shows how to sort an array.
It takes the input data from inputs/bubblesort.in

View File

@ -9,5 +9,27 @@ leo build
To run this program, run: To run this program, run:
```bash ```bash
leo run leo run main
``` ```
## Overview
This example shows how to do basic operations over groups.
It takes the input data from inputs/groups.in
## Documentation Group Element
The set of affine points on the elliptic curve passed into the Leo compiler forms a group. Leo supports this set as a primitive data type. Group elements are special since their values can be defined as coordinate pairs ```(x, y)group```. The group type keyword group must be used when specifying a pair of group coordinates since implicit syntax would collide with normal tuple (a, b) values.
```
let b = 0group; // the zero of the group
let a = 1group; // the group generator
let c = 2group; // 2 * the group generator
let d = (0, 1)group; // coordinate notation
```

View File

@ -9,5 +9,10 @@ leo build
To run this program, run: To run this program, run:
```bash ```bash
leo run leo run main
``` ```
## Overview
This example shows how to sum two u32 numbers.
It takes the input data from inputs/helloworld.in

View File

@ -42,6 +42,8 @@ use tracing::span::Span;
/// require Build command output as their input. /// require Build command output as their input.
#[derive(StructOpt, Clone, Debug, Default)] #[derive(StructOpt, Clone, Debug, Default)]
pub struct BuildOptions { pub struct BuildOptions {
#[structopt(long, help = "Enables offline mode.")]
pub offline: bool,
#[structopt(long, help = "Enable spans in AST snapshots.")] #[structopt(long, help = "Enable spans in AST snapshots.")]
pub enable_spans: bool, pub enable_spans: bool,
#[structopt(long, help = "Writes all AST snapshots for the different compiler phases.")] #[structopt(long, help = "Writes all AST snapshots for the different compiler phases.")]
@ -115,7 +117,7 @@ impl Command for Build {
let build_directory = BuildDirectory::open(&package_path)?; let build_directory = BuildDirectory::open(&package_path)?;
// Initialize error handler // Initialize error handler
let handler = leo_errors::emitter::Handler::default(); let handler = Handler::default();
// Fetch paths to all .leo files in the source directory. // Fetch paths to all .leo files in the source directory.
let source_files = SourceDirectory::files(&package_path)?; let source_files = SourceDirectory::files(&package_path)?;
@ -178,8 +180,12 @@ impl Command for Build {
std::env::set_current_dir(&build_directory) std::env::set_current_dir(&build_directory)
.map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?;
// Call the `aleo build` command from the Aleo SDK. // Call the `aleo build` command with the appropriate from the Aleo SDK.
let command = AleoBuild::try_parse_from(&[ALEO_CLI_COMMAND]).map_err(CliError::failed_to_execute_aleo_build)?; let mut args = vec![ALEO_CLI_COMMAND];
if self.compiler_options.offline {
args.push("--offline");
}
let command = AleoBuild::try_parse_from(&args).map_err(CliError::failed_to_execute_aleo_build)?;
let result = command.parse().map_err(CliError::failed_to_execute_aleo_build)?; let result = command.parse().map_err(CliError::failed_to_execute_aleo_build)?;
// Log the result of the build // Log the result of the build

View File

@ -76,6 +76,9 @@ impl Command for Run {
.map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?;
// Call the `aleo run` command from the Aleo SDK. // Call the `aleo run` command from the Aleo SDK.
if self.compiler_options.offline {
arguments.push(String::from("--offline"));
}
let command = AleoRun::try_parse_from(&arguments).map_err(CliError::failed_to_parse_aleo_run)?; let command = AleoRun::try_parse_from(&arguments).map_err(CliError::failed_to_parse_aleo_run)?;
let res = command.parse().map_err(CliError::failed_to_execute_aleo_run)?; let res = command.parse().map_err(CliError::failed_to_execute_aleo_run)?;