Merge pull request #1919 from AleoHQ/code-gen

Implement code generation for Aleo instructions
This commit is contained in:
Collin Chin 2022-07-12 23:09:32 -07:00 committed by GitHub
commit 74ae110e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
848 changed files with 4360 additions and 10373 deletions

View File

@ -46,7 +46,7 @@ commands:
jobs:
check-style:
docker:
- image: cimg/rust:1.59.0
- image: cimg/rust:1.61
resource_class: xlarge
steps:
- checkout
@ -61,7 +61,7 @@ jobs:
clippy:
docker:
- image: cimg/rust:1.59.0
- image: cimg/rust:1.61
resource_class: xlarge
steps:
- checkout
@ -70,13 +70,16 @@ jobs:
- run:
name: Clippy
no_output_timeout: 35m
command: cargo clippy --all-features --examples --all --benches
command: |
rustup toolchain install nightly-x86_64-unknown-linux-gnu
cargo +nightly clippy --workspace --all-targets -- -D warnings
cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings
- clear_environment:
cache_key: leo-clippy-cache
# code-cov:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# environment:
# RUSTC_BOOTSTRAP: 1
@ -118,7 +121,7 @@ jobs:
leo-executable:
docker:
- image: cimg/rust:1.59.0
- image: cimg/rust:1.61
resource_class: xlarge
steps:
- checkout
@ -136,7 +139,7 @@ jobs:
#
# leo-new:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -149,7 +152,7 @@ jobs:
#
# leo-init:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -162,7 +165,7 @@ jobs:
#
# leo-clean:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -175,7 +178,7 @@ jobs:
#
# leo-setup:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -188,7 +191,7 @@ jobs:
# leo-add-remove:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -202,7 +205,7 @@ jobs:
# todo (collin): uncomment after compiler refactor
# leo-check-constraints:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -215,7 +218,7 @@ jobs:
#
# leo-login-logout:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -228,7 +231,7 @@ jobs:
#
# leo-clone:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:
@ -241,7 +244,7 @@ jobs:
#
# leo-publish:
# docker:
# - image: cimg/rust:1.59.0
# - image: cimg/rust:1.61
# resource_class: xlarge
# steps:
# - attach_workspace:

1472
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ path = "leo/main.rs"
members = [
"compiler/compiler",
"docs/grammar",
"leo/errors",
"errors",
"leo/package",
"tests/test-framework",
]
@ -39,7 +39,7 @@ path = "./compiler/compiler"
version = "1.5.3"
[dependencies.leo-errors]
path = "./leo/errors"
path = "./errors"
version = "1.5.3"
[dependencies.leo-package]
@ -47,18 +47,24 @@ path = "./leo/package"
version = "1.5.3"
[dependencies.leo-span]
path = "./leo/span"
path = "./compiler/span"
version = "1.5.3"
[dependencies.snarkvm-utilities]
[dependencies.aleo]
git = "https://github.com/AleoHQ/aleo.git"
rev = "a0895e0"
[dependencies.snarkvm]
#path = "../snarkVM"
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "51633e2"
rev = "f25e0b2"
features = ["circuit", "console"]
[dependencies.backtrace]
version = "0.3.66"
[dependencies.clap]
version = "3.2.8"
version = "3.1"
features = ["derive", "env"]
[dependencies.color-backtrace]

View File

@ -19,15 +19,15 @@ edition = "2021"
rust-version = "1.56"
[dependencies.leo-errors]
path = "../../leo/errors"
path = "../../errors"
version = "1.5.3"
[dependencies.leo-span]
path = "../../leo/span"
path = "../span"
version = "1.5.3"
[dependencies.indexmap]
version = "1.8.0"
version = "1.9"
features = [ "serde-1" ]
[dependencies.serde]

View File

@ -24,12 +24,19 @@ pub struct CircuitVariableInitializer {
/// The expression to initialize the field with.
/// When `None`, a binding, in scope, with the name will be used instead.
pub expression: Option<Expression>,
/// `true` if the circuit is a `record` type.
pub is_record: bool,
}
impl fmt::Display for CircuitVariableInitializer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(expr) = &self.expression {
write!(f, "{}: {}", self.identifier, expr)
write!(f, "{}: {}", self.identifier, expr)?;
if self.is_record {
write!(f, "private")
} else {
write!(f, "")
}
} else {
write!(f, "{}", self.identifier)
}
@ -52,12 +59,15 @@ pub struct CircuitExpression {
impl fmt::Display for CircuitExpression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {{ ", self.name)?;
for member in self.members.iter() {
write!(f, "{}", member)?;
write!(f, ", ")?;
}
write!(f, "}}")
write!(
f,
"{{{}}}",
self.members
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(", ")
)
}
}

View File

@ -46,10 +46,10 @@ impl fmt::Display for Literal {
match &self {
Self::Address(address, _) => write!(f, "{}", address),
Self::Boolean(boolean, _) => write!(f, "{}", boolean),
Self::Field(field, _) => write!(f, "{}", field),
Self::Group(group) => write!(f, "{}", group),
Self::Field(field, _) => write!(f, "{}field", field),
Self::Group(group) => write!(f, "{}group", group),
Self::Integer(type_, value, _) => write!(f, "{}{}", value, type_),
Self::Scalar(scalar, _) => write!(f, "{}", scalar),
Self::Scalar(scalar, _) => write!(f, "{}scalar", scalar),
Self::String(string, _) => write!(f, "{}", string),
}
}

View File

@ -19,11 +19,10 @@ use crate::{normalize_json_value, remove_key_from_json};
use super::*;
use leo_errors::{AstError, Result};
/// Input data which includes [`ProgramInput`] and [`ProgramState`].
/// Input data which includes [`ProgramInput`].
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Input {
pub program_input: ProgramInput,
pub program_state: ProgramState,
}
impl Input {
@ -34,13 +33,26 @@ impl Input {
}
/// A raw unprocessed input or state file data. Used for future conversion
/// into [`ProgramInput`] or [`ProgramState`].
/// into [`ProgramInput`].
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct InputAst {
pub sections: Vec<Section>,
}
impl InputAst {
/// Returns all values of the input AST for execution with `leo run`.
pub fn values(&self) -> Vec<String> {
self.sections
.iter()
.flat_map(|section| {
section
.definitions
.iter()
.map(|definition| definition.value.to_string())
})
.collect::<Vec<_>>()
}
/// Serializes the `Input` into a JSON Value.
pub fn to_json_value(&self) -> Result<serde_json::Value> {
Ok(serde_json::to_value(&self).map_err(|e| AstError::failed_to_convert_ast_to_json_value(&e))?)

View File

@ -26,9 +26,6 @@ pub use input_value::*;
pub mod program_input;
pub use program_input::*;
pub mod program_state;
pub use program_state::*;
pub mod section;
pub use section::*;

View File

@ -20,24 +20,17 @@ use super::*;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ProgramInput {
pub main: Definitions,
pub registers: Definitions,
}
impl TryFrom<InputAst> for ProgramInput {
type Error = LeoError;
fn try_from(input: InputAst) -> Result<Self> {
let mut main = IndexMap::new();
let mut registers = IndexMap::new();
for section in input.sections {
let target = match section.name {
sym::main => &mut main,
sym::registers => &mut registers,
_ => {
return Err(
InputError::unexpected_section(&["main", "registers"], section.name, section.span).into(),
)
}
_ => return Err(InputError::unexpected_section(&["main"], section.name, section.span).into()),
};
for definition in section.definitions {
@ -48,6 +41,6 @@ impl TryFrom<InputAst> for ProgramInput {
}
}
Ok(ProgramInput { main, registers })
Ok(ProgramInput { main })
}
}

View File

@ -1,50 +0,0 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 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 super::*;
/// Processed Program state.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ProgramState {
pub state: Definitions,
}
impl TryFrom<InputAst> for ProgramState {
type Error = LeoError;
fn try_from(input: InputAst) -> Result<Self> {
let mut state = IndexMap::new();
for section in input.sections {
if matches!(section.name, sym::state | sym::record | sym::state_leaf) {
for definition in section.definitions {
state.insert(
definition.name.name,
InputValue::try_from((definition.type_, definition.value))?,
);
}
} else {
return Err(InputError::unexpected_section(
&["state", "record", "state_leaf"],
section.name,
section.span,
)
.into());
}
}
Ok(ProgramState { state })
}
}

View File

@ -74,6 +74,18 @@ impl Ast {
Self { ast: program }
}
/// Set the program name to the given string.
pub fn set_program_name(mut self, name: String) -> Self {
self.ast.name = name;
self
}
/// Set the network name to the given string.
pub fn set_network(mut self, network: String) -> Self {
self.ast.network = network;
self
}
/// Returns a reference to the inner program AST representation.
pub fn as_repr(&self) -> &Program {
&self.ast

View File

@ -256,6 +256,7 @@ pub trait ProgramReconstructor: StatementReconstructor {
fn reconstruct_program(&mut self, input: Program) -> Program {
Program {
name: input.name,
network: input.network,
expected_input: input.expected_input,
functions: input
.functions

View File

@ -27,8 +27,9 @@ use std::fmt;
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Program {
/// The name of the program.
/// Empty after parsing.
pub name: String,
/// The network of the program.
pub network: String,
/// Expected main function inputs.
/// Empty after parsing.
pub expected_input: Vec<FunctionInput>,
@ -52,25 +53,15 @@ impl fmt::Display for Program {
}
}
impl Program {
/// Constructs an empty program with `name`.
pub fn new(name: String) -> Self {
impl Default for Program {
/// Constructs an empty program node.
fn default() -> Self {
Self {
name,
name: String::new(),
network: String::new(),
expected_input: vec![],
functions: IndexMap::new(),
circuits: IndexMap::new(),
}
}
/// Extract the name of the program.
pub fn name(&self) -> &str {
&self.name
}
/// Sets the name of the program.
pub fn set_name(mut self, name: String) -> Self {
self.name = name;
self
}
}

View File

@ -23,7 +23,7 @@ path = "../ast"
version = "1.5.3"
[dependencies.leo-errors]
path = "../../leo/errors"
path = "../../errors"
version = "1.5.3"
[dependencies.leo-passes]
@ -34,13 +34,13 @@ version = "1.5.3"
path = "../parser"
version = "1.5.3"
[dependencies.leo-span]
path = "../span"
version = "1.5.3"
[dependencies.sha2]
version = "0.10"
[dependencies.leo-span]
path = "../../leo/span"
version = "1.5.3"
[dev-dependencies.leo-test-framework]
path = "../../tests/test-framework"
version = "1.4.0"

View File

@ -41,6 +41,10 @@ pub struct Compiler<'a> {
main_file_path: PathBuf,
/// The path to where the compiler outputs all generated files.
output_directory: PathBuf,
/// The program name,
pub program_name: String,
/// The network name,
pub network: String,
/// The AST for the program.
pub ast: Ast,
/// The input ast for the program if it exists.
@ -54,6 +58,8 @@ impl<'a> Compiler<'a> {
/// Returns a new Leo compiler.
///
pub fn new(
program_name: String,
network: String,
handler: &'a Handler,
main_file_path: PathBuf,
output_directory: PathBuf,
@ -63,7 +69,9 @@ impl<'a> Compiler<'a> {
handler,
main_file_path,
output_directory,
ast: Ast::new(Program::new("Initial".to_string())),
program_name,
network,
ast: Ast::new(Program::default()),
input_ast: None,
output_options: output_options.unwrap_or_default(),
}
@ -91,7 +99,9 @@ impl<'a> Compiler<'a> {
let prg_sf = with_session_globals(|s| s.source_map.new_source(program_string, name));
// Use the parser to construct the abstract syntax tree (ast).
let ast: leo_ast::Ast = leo_parser::parse_ast(self.handler, &prg_sf.src, prg_sf.start_pos)?;
let mut ast: leo_ast::Ast = leo_parser::parse_ast(self.handler, &prg_sf.src, prg_sf.start_pos)?;
ast = ast.set_program_name(self.program_name.clone());
ast = ast.set_network(self.network.clone());
if self.output_options.ast_initial {
// Write the AST snapshot post parsing.
@ -166,6 +176,19 @@ impl<'a> Compiler<'a> {
Ok(st)
}
///
/// Returns a compiled Leo program and prints the resulting bytecode.
/// TODO: Remove when code generation is ready to be integrated into the compiler.
///
pub fn compile_and_generate_instructions(&mut self) -> Result<(SymbolTable, String)> {
self.parse_program()?;
let symbol_table = self.compiler_stages()?;
let bytecode = CodeGenerator::do_pass((&self.ast, self.handler))?;
Ok((symbol_table, bytecode))
}
///
/// Returns a compiled Leo program.
///

View File

@ -41,6 +41,8 @@ fn new_compiler(handler: &Handler, main_file_path: PathBuf) -> Compiler<'_> {
fs::create_dir_all(output_dir.clone()).unwrap();
Compiler::new(
String::from("test"),
String::from("testnet3"),
handler,
main_file_path,
output_dir,

View File

@ -25,12 +25,12 @@ path = "../ast"
version = "1.5.3"
[dependencies.leo-errors]
path = "../../leo/errors"
path = "../../errors"
version = "1.5.3"
[dependencies.leo-span]
path = "../../leo/span"
path = "../span"
version = "1.5.3"
[dependencies]
indexmap = "1.7.0"
[dependencies.indexmap]
version = "1.9"

View File

@ -1,6 +1,6 @@
# leo-core
[![Crates.io](https://img.shields.io/crates/v/leo-ast.svg?color=neon)](https://crates.io/crates/leo-ast)
[![Crates.io](https://img.shields.io/crates/v/leo-ast.svg?color=neon)](https://crates.io/crates/leo-core)
[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS)
[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md)

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: inputs/index.in
*/
function main (x: u32) -> bool {
const y = [aleo1x0rh2cudq93fhukrsce8sgvcphddv4qs0clph64stpg0hstfds9qjvxcg6; 3];
let z = y[x];
return z == y[0];
}

View File

@ -1,17 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file:
- inputs/dummy.in
*/
type Int = u32;
circuit Int {
x: u8;
}
function main(y: bool) -> bool {
return y;
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file:
- inputs/dummy.in
*/
type int = u32;
function int() {}
function main(y: bool) -> bool {
return y;
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file:
- inputs/dummy.in
*/
type int = u32;
const int = 8u8;
function main(y: bool) -> bool {
return y;
}

View File

@ -1,17 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/basic.in
*/
type int = u32;
function main(x: u32, y: bool) -> bool {
let a: int = x;
let b: int = 2;
let c: int = a + b;
return a == 1u32 && b == 2u32
&& c == 3u32 && y;
}

View File

@ -1,19 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/basic.in
*/
type int = u32;
type number = int;
function main(x: u32, y: bool) -> bool {
let a: int = x;
let b: number = 2u32;
let c: number = 3;
let d: u32 = a + b + c;
return a == 1u32 && b == 2u32
&& c == 3u32 && d == 6u32 && y;
}

View File

@ -1,25 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/basic.in
*/
type int = u32;
circuit Foo {
a: u32;
}
circuit Bar {
a: int;
}
function main(x: u32, y: bool) -> bool {
let a: int = x;
let f: Foo = Foo { a };
let b: Bar = Bar { a };
return a == 1u32 && f.a == 1u32
&& b.a == 1u32 && y;
}

View File

@ -1,13 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file:
- inputs/dummy.in
*/
type int = u32;
type int = u8;
function main(y: bool) -> bool {
return y;
}

View File

@ -1,23 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/dummy.in
*/
type int = u32;
function return_int_triary() -> (int, int, int) {
return (1, 2, 3);
}
function return_int_array() -> [int; 3] {
return [0u32; 3];
}
function main(y: bool) -> bool {
let a: (int, int, int) = return_int_triary();
let b: [int; 3] = return_int_array();
return y;
}

View File

@ -1,6 +0,0 @@
[main]
x: u32 = 1;
y: bool = true;
[registers]
r0: bool = false;

View File

@ -1,5 +0,0 @@
[main]
y: bool = true;
[registers]
r0: bool = false;

View File

@ -1,6 +0,0 @@
[main]
x: u8 = 1;
y: bool = true;
[registers]
r0: bool = false;

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/basic.in
*/
type x = u32;
function main(x: x, y: bool) -> bool {
return y;
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/dummy.in
*/
type int = u32;
function main(y: bool) -> bool {
let int: int = 1u32;
return y;
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file:
- inputs/wrong_type_fail.in
*/
type int = u32;
function main(x: u8, y: bool) -> bool {
let a: int = x;
return a == 1u32 && y;
}

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/array_range_access_fail.in
*/
function main (
const x: u32
) {
const y = [1u8; 3];
const z: [u8; 2] = y[..1u32][..x];
}

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() {
let a = [true; (0)];
}

View File

@ -1,35 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- input/complex_access.in
*/
circuit Circ {
f: u32
}
function main (a: [u8; 8], b: u32, c: [[u8; 3]; 3], d: [(u8, u32); 1], e: [u8; (3, 4)] ) -> bool {
a[0..3][b] = 93;
a[2..6][1] = 87;
a[2..6][1] *= 2;
a[2..3] = [42u8];
a[6..][0] = 43u8;
a[0..1][0..1] = [200];
c[0..2][0] = [1u8; 3];
c[1..][1][1..2][0] = 126;
c[1..][0] = [42, 43, 44];
c[Circ {f: 0}.f..1][0][0] += 2;
d[..1][0].1 = 1;
e[0..][0] = [22; 4];
e[0..][0][0] = 33;
return
a == [200u8, 93, 42, 174, 5, 6, 43, 8]
&& c == [[3u8, 1, 1], [42, 43, 44], [7, 126, 9]]
&& d == [(0u8, 1u32)]
&& e == [[33u8, 22, 22, 22], [0, 0, 0, 0], [0, 0, 0, 0]];
}

View File

@ -1,11 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- input/six_zeros.in
- input/count_to_6.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [0u8; (3, 2)];
}

View File

@ -1,11 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- input/six_zeros.in
- input/count_to_6.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [[1u8, 2], [3, 4], [5, 6]];
}

View File

@ -1,2 +0,0 @@
[constants]
x: u32 = 1u32;

View File

@ -1,9 +0,0 @@
[main]
a: [u8; 8] = [1u8, 2, 3, 4, 5, 6, 7, 8];
b: u32 = 1;
c: [[u8; 3]; 3] = [[1u8, 2, 3], [4, 5, 6], [7, 8, 9]];
d: [(u8, u32); 1] = [(0u8, 0u32)];
e: [u8; (3, 4)] = [0u8; (3, 4)];
[registers]
out: bool = true;

View File

@ -1,5 +0,0 @@
[main]
a: [[u8; 2]; 3] = [[1, 2], [3, 4], [5, 6]];
[registers]
x: bool = false;

View File

@ -1,6 +0,0 @@
[main]
y: bool = true;
n: bool = false;
[registers]
r0: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [0u8; (2, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [[0u8; 2]; 3];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [[0u8; 3]; 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [0u8; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [0u8; (2, 3)];
[registers]
x: bool = false;

View File

@ -1,8 +0,0 @@
[main]
a: [u8; 3] = [1, 1, 1];
[registers]
r: [u8; 3] = [1u8, 1u8, 1u8];
[registers]
x: bool = false;

View File

@ -1,8 +0,0 @@
[main]
a: [u8; 3] = [1, 1, 1]; // doesn't match arr below
[registers]
r: [u8; 3] = [0u8, 0u8, 0u8];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [0; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; 3] = [1, 1, 1];
[registers]
x: bool = false;

View File

@ -1,6 +0,0 @@
[main]
a: [[u8; 2]; 3] = [[0; 2]; 3];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[u8; 2]; 3] = [0; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [[0; 2]; 3];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [0; (3, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (4, 3, 2)] = [0; (4, 3, 2)];
[registers]
x: bool = false;

View File

@ -1,5 +0,0 @@
[main]
a: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
[registers]
x: bool = false;

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/input_nested_3x2.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [[0u8; 2]; 3];
}

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/input_nested_3x2_fail.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [[0u8; 2]; 3)]; // This should be written the right way as this test is for the input file.
}

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/input_tuple_3x2.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [0u8; (3, 2)];
}

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/input_tuple_3x2_fail.in
*/
function main(a: [u8; (3, 2)]) -> bool {
return a == [0u8; (3, 2)];
}

View File

@ -1,10 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() -> bool {
const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions
return false;
}

View File

@ -1,11 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() -> bool {
const arr: [u8; (2, 2)] = [[1u8, 1u8],
[1u8]]; // incorrect dimensions
return false;
}

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
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;
}

View File

@ -1,10 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() -> bool {
const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions
return false;
}

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(n: bool) -> bool {
const x = [false; (2, 2)];
const z: bool = x[0][0];
return n == z;
}

View File

@ -1,13 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
// Multidimensional array syntax in leo
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;
}

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
// Multidimensional array syntax in leo
function main(y: bool) -> bool {
const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
return false;
}

View File

@ -1,11 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file:
- input/registers_ones.in
- input/registers_zeros.in
*/
function main(a: [u8; 3]) -> [u8; 3] {
return input.registers.r == a ? [3,2,1] : [1,2,3];
}

View File

@ -1,11 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/three_ones.in
*/
// `{from}..{to}` copies the elements of one array into another exclusively
function main(a: [u8; 3]) -> bool {
const b = [1u8; 4];
return a == b[0..3];
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8];
const expected: [u32; 2] = [0, 1];
const actual = arr[..2]; // Should produce [0, 1]
return (expected == actual) == y;
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/three_ones.in
*/
// A spread operator `...` copies the elements of one array into another
function main(a: [u8; 3]) -> bool {
const b = [1u8, 1u8];
const c = [1u8, ...b];
const d = [...b, 1u8];
return a == c && d == a;
}

View File

@ -1,10 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/three_ones.in
*/
function main (a: [u8; 3]) -> bool {
let y = a[0..[0u8; 2] == [0u8; 2]? 2u8 : 2u8];
return y == [1u8, 1];
}

View File

@ -1,13 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
// Multidimensional array syntax in leo
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;
}

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
// Multidimensional array syntax in leo
function main() {
const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
}

View File

@ -1,8 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const a: [u8; -2] = [0u32; 2];
}

View File

@ -1,11 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/input_tuple_3x2.in
*/
function main(a: [[u8; 2]; 3]) -> bool {
const b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
return a == b;
}

View File

@ -1,14 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/type_tuple_value_nested_4x3x2.in
*/
function main(a: [[[u8; 2]; 3]; 4]) -> bool {
const b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
return a == b;
}

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/type_nested_value_nested_3x2.in
*/
function main(a: [[u8; 2]; 3]) -> bool {
const c = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
const b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer
return b == a && a == c;
}

View File

@ -1,8 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering)
}

View File

@ -1,16 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
const b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer
return (a == b) == y;
}

View File

@ -1,8 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
}

View File

@ -1,12 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
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;
}

View File

@ -1,8 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering)
}

View File

@ -1,16 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
const b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer
return (a == b) == y;
}

View File

@ -1,8 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering)
}

View File

@ -1,13 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer
return (a == b) == y;
}

View File

@ -1,9 +0,0 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function main() {
const b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering)
}

View File

@ -1,16 +0,0 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
*/
function main(y: bool) -> bool {
const a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]],
[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline
const b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer
return (a == b) == y;
}

View File

@ -1,8 +0,0 @@
/*
namespace: Compile
expectation: Fail
*/
function main() {
const b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering)
}

Some files were not shown because too many files have changed in this diff Show More