resolve merge conflicts

This commit is contained in:
gluaxspeed 2021-09-07 02:59:35 -07:00
commit 8a8b5ab757
67 changed files with 672 additions and 187 deletions

View File

@ -132,6 +132,11 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
} else {
return Err(AsgError::illegal_input_variable_reference(&value.span).into());
}
} else if let Some(gc) = scope.resolve_global_const(&value.name) {
gc.variables
.iter()
.find(|&&v| v.borrow().name.name == value.name)
.unwrap()
} else {
match scope.resolve_variable(&value.name) {
Some(v) => v,

View File

@ -141,9 +141,13 @@ impl<'a> Function<'a> {
.insert("self".to_string(), self_variable);
}
for (name, argument) in self.arguments.iter() {
/* if self.scope.resolve_alias(name).is_some() {
return Err(AsgError::cannot_shadow_name("function input", name, "alias", &argument.get().borrow().name.span).into());
} */
if self.scope.resolve_global_const(name).is_some() {
return Err(AsgError::function_input_cannot_shadow_global_const(
name,
&argument.get().borrow().name.span,
)
.into());
}
self.scope.variables.borrow_mut().insert(name.clone(), argument.get());
}

View File

@ -130,6 +130,29 @@ fn resolve_import_package_access(
}
}
/// Checks whether a given string is found in any other global namespaces.
/// If it is found it returns an error.
fn check_top_level_namespaces<'a>(
name: &str,
span: &Span,
aliases: &IndexMap<String, &'a Alias<'a>>,
functions: &IndexMap<String, &'a Function<'a>>,
circuits: &IndexMap<String, &'a Circuit<'a>>,
global_consts: &IndexMap<String, &'a DefinitionStatement<'a>>,
) -> Result<()> {
if aliases.contains_key(name) {
Err(AsgError::duplicate_alias_definition(name, span).into())
} else if global_consts.contains_key(name) {
Err(AsgError::duplicate_global_const_definition(name, span).into())
} else if functions.contains_key(name) {
Err(AsgError::duplicate_function_definition(name, span).into())
} else if circuits.contains_key(name) {
Err(AsgError::duplicate_circuit_definition(name, span).into())
} else {
Ok(())
}
}
impl<'a> Program<'a> {
/// Returns a new Leo program ASG from the given Leo program AST and its imports.
///
@ -264,44 +287,40 @@ impl<'a> Program<'a> {
scope.functions.borrow_mut().insert(name.name.to_string(), function);
}
for (name, global_const) in program.global_consts.iter() {
global_const
.variable_names
.iter()
.for_each(|variable_name| assert!(name.contains(&variable_name.identifier.name.to_string())));
for (names, global_const) in program.global_consts.iter() {
let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?;
if let Statement::Definition(gc) = gc {
scope.global_consts.borrow_mut().insert(name.clone(), gc);
if let Statement::Definition(def) = gc {
let name = names
.iter()
.enumerate()
.map(|(i, name)| {
assert_eq!(name.name, def.variables.get(i).unwrap().borrow().name.name);
name.name.to_string()
})
.collect::<Vec<String>>()
.join(",");
scope.global_consts.borrow_mut().insert(name, def);
}
}
// Load concrete definitions.
let mut aliases = IndexMap::new();
let mut functions = IndexMap::new();
let mut circuits = IndexMap::new();
let mut global_consts = IndexMap::new();
for (name, alias) in program.aliases.iter() {
assert_eq!(name.name, alias.name.name);
let asg_alias = *scope.aliases.borrow().get(name.name.as_ref()).unwrap();
let name = name.name.to_string();
if aliases.contains_key(&name) {
return Err(AsgError::duplicate_alias_definition(name, &alias.span).into());
}
check_top_level_namespaces(&name, &alias.span, &aliases, &functions, &circuits, &global_consts)?;
aliases.insert(name, asg_alias);
}
let mut global_consts = IndexMap::new();
for (name, global_const) in program.global_consts.iter() {
global_const
.variable_names
.iter()
.for_each(|variable_name| assert!(name.contains(&variable_name.identifier.name.to_string())));
let asg_global_const = *scope.global_consts.borrow().get(name).unwrap();
global_consts.insert(name.clone(), asg_global_const);
}
let mut functions = IndexMap::new();
for (name, function) in program.functions.iter() {
assert_eq!(name.name, function.identifier.name);
let asg_function = *scope.functions.borrow().get(name.name.as_ref()).unwrap();
@ -310,21 +329,50 @@ impl<'a> Program<'a> {
let name = name.name.to_string();
if functions.contains_key(&name) {
return Err(AsgError::duplicate_function_definition(name, &function.span).into());
}
check_top_level_namespaces(&name, &function.span, &aliases, &functions, &circuits, &global_consts)?;
functions.insert(name, asg_function);
}
let mut circuits = IndexMap::new();
for (name, circuit) in program.circuits.iter() {
assert_eq!(name.name, circuit.circuit_name.name);
let asg_circuit = *scope.circuits.borrow().get(name.name.as_ref()).unwrap();
asg_circuit.fill_from_ast(circuit)?;
circuits.insert(name.name.to_string(), asg_circuit);
let name = name.name.to_string();
check_top_level_namespaces(
&name,
&circuit.circuit_name.span,
&aliases,
&functions,
&circuits,
&global_consts,
)?;
circuits.insert(name, asg_circuit);
}
for (names, global_const) in program.global_consts.iter() {
let name = names
.iter()
.map(|name| name.name.to_string())
.collect::<Vec<String>>()
.join(",");
let asg_global_const = *scope.global_consts.borrow().get(&name).unwrap();
check_top_level_namespaces(
&name,
&global_const.span,
&aliases,
&functions,
&circuits,
&global_consts,
)?;
global_consts.insert(name.clone(), asg_global_const);
}
Ok(Program {

View File

@ -151,6 +151,22 @@ impl<'a> Scope<'a> {
}
}
///
/// Returns a reference to the global const definition statement corresponding to the name.
///
/// If the current scope did not have this name present, then the parent scope is checked.
/// If there is no parent scope, then `None` is returned.
///
pub fn resolve_global_const(&self, name: &str) -> Option<&'a DefinitionStatement<'a>> {
if let Some(resolved) = self.global_consts.borrow().get(name) {
Some(*resolved)
} else if let Some(resolved) = self.parent_scope.get() {
resolved.resolve_global_const(name)
} else {
None
}
}
///
/// Returns a new scope given a parent scope.
///

View File

@ -110,10 +110,18 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
}
for (variable, type_) in statement.variable_names.iter().zip(output_types.into_iter()) {
/* let name = variable.identifier.name.as_ref();
if scope.resolve_alias(name).is_some() {
return Err(AsgError::cannot_shadow_name("function input", name, "alias", &variable.identifier.span).into());
} */
let name = variable.identifier.name.as_ref();
if scope.resolve_global_const(name).is_some() {
return Err(
AsgError::function_variable_cannot_shadow_global_const(name, &variable.identifier.span).into(),
);
} else if scope.resolve_variable(name).is_some() {
return Err(AsgError::function_variable_cannot_shadow_other_function_variable(
name,
&variable.identifier.span,
)
.into());
}
variables.push(&*scope.context.alloc_variable(RefCell::new(InnerVariable {
id: scope.context.get_id(),

View File

@ -133,6 +133,19 @@ impl Canonicalizer {
}
}
fn canonicalize_circuit_implied_variable_definition(
&mut self,
member: &CircuitImpliedVariableDefinition,
) -> CircuitImpliedVariableDefinition {
CircuitImpliedVariableDefinition {
identifier: member.identifier.clone(),
expression: member
.expression
.as_ref()
.map(|expr| self.canonicalize_expression(expr)),
}
}
fn canonicalize_expression(&mut self, expression: &Expression) -> Expression {
match expression {
Expression::Unary(unary) => {
@ -270,7 +283,11 @@ impl Canonicalizer {
return Expression::CircuitInit(CircuitInitExpression {
name,
members: circuit_init.members.clone(),
members: circuit_init
.members
.iter()
.map(|member| self.canonicalize_circuit_implied_variable_definition(member))
.collect(),
span: circuit_init.span.clone(),
});
}
@ -292,7 +309,11 @@ impl Canonicalizer {
Expression::Call(call) => {
return Expression::Call(CallExpression {
function: Box::new(self.canonicalize_expression(&call.function)),
arguments: call.arguments.clone(),
arguments: call
.arguments
.iter()
.map(|arg| self.canonicalize_expression(arg))
.collect(),
span: call.span.clone(),
});
}
@ -447,11 +468,31 @@ impl Canonicalizer {
}
}
fn canonicalize_function_input(&mut self, input: &FunctionInput) -> FunctionInput {
if let FunctionInput::Variable(variable) = input {
if variable.type_.is_self() {
return FunctionInput::Variable(FunctionInputVariable {
identifier: variable.identifier.clone(),
const_: variable.const_,
mutable: variable.mutable,
type_: Type::Identifier(self.circuit_name.as_ref().unwrap().clone()),
span: variable.span.clone(),
});
}
}
input.clone()
}
fn canonicalize_circuit_member(&mut self, circuit_member: &CircuitMember) -> CircuitMember {
match circuit_member {
CircuitMember::CircuitVariable(_, _) => {}
CircuitMember::CircuitFunction(function) => {
let input = function.input.clone();
let input = function
.input
.iter()
.map(|input| self.canonicalize_function_input(input))
.collect();
let output = self.canonicalize_self_type(function.output.as_ref());
let block = self.canonicalize_block(&function.block);

View File

@ -21,25 +21,42 @@ use leo_errors::{AstError, Result, Span};
use indexmap::IndexMap;
pub struct Importer<T>
where
T: ImportResolver,
{
import_resolver: T,
}
pub struct Importer {}
impl<T> Importer<T>
where
T: ImportResolver,
{
pub fn new(import_resolver: T) -> Self {
Self { import_resolver }
}
impl Importer {
pub fn do_pass<T>(program: Program, importer: &mut T) -> Result<Ast>
where
T: ImportResolver,
{
let mut imported_symbols: Vec<(Vec<String>, ImportSymbol, Span)> = vec![];
for import_statement in program.import_statements.iter() {
resolve_import_package(&mut imported_symbols, vec![], &import_statement.package_or_packages);
}
pub fn do_pass(ast: Program, importer: T) -> Result<Ast> {
Ok(Ast::new(
ReconstructingDirector::new(Importer::new(importer)).reduce_program(&ast)?,
))
let mut deduplicated_imports: IndexMap<Vec<String>, Span> = IndexMap::new();
for (package, _symbol, span) in imported_symbols.iter() {
deduplicated_imports.insert(package.clone(), span.clone());
}
let mut wrapped_resolver = CoreImportResolver::new(importer);
let mut resolved_packages: IndexMap<Vec<String>, Program> = IndexMap::new();
for (package, span) in deduplicated_imports {
let pretty_package = package.join(".");
let resolved_package =
match wrapped_resolver.resolve_package(&package.iter().map(|x| &**x).collect::<Vec<_>>()[..], &span)? {
Some(x) => x,
None => return Err(AstError::unresolved_import(pretty_package, &span).into()),
};
resolved_packages.insert(package.clone(), resolved_package);
}
let mut ast = program;
ast.imports = resolved_packages;
Ok(Ast::new(ast))
}
}
@ -108,66 +125,3 @@ fn resolve_import_package_access(
}
}
}
impl<T> ReconstructingReducer for Importer<T>
where
T: ImportResolver,
{
fn in_circuit(&self) -> bool {
false
}
fn swap_in_circuit(&mut self) {}
fn reduce_program(
&mut self,
program: &Program,
expected_input: Vec<FunctionInput>,
import_statements: Vec<ImportStatement>,
empty_imports: IndexMap<Vec<String>, Program>,
aliases: IndexMap<Identifier, Alias>,
circuits: IndexMap<Identifier, Circuit>,
functions: IndexMap<Identifier, Function>,
global_consts: IndexMap<String, DefinitionStatement>,
) -> Result<Program> {
if !empty_imports.is_empty() {
return Err(AstError::injected_programs(empty_imports.len()).into());
}
let mut imported_symbols: Vec<(Vec<String>, ImportSymbol, Span)> = vec![];
for import_statement in import_statements.iter() {
resolve_import_package(&mut imported_symbols, vec![], &import_statement.package_or_packages);
}
let mut deduplicated_imports: IndexMap<Vec<String>, Span> = IndexMap::new();
for (package, _symbol, span) in imported_symbols.iter() {
deduplicated_imports.insert(package.clone(), span.clone());
}
let mut wrapped_resolver = CoreImportResolver::new(&mut self.import_resolver);
let mut resolved_packages: IndexMap<Vec<String>, Program> = IndexMap::new();
for (package, span) in deduplicated_imports {
let pretty_package = package.join(".");
let resolved_package =
match wrapped_resolver.resolve_package(&package.iter().map(|x| &**x).collect::<Vec<_>>()[..], &span)? {
Some(x) => x,
None => return Err(AstError::unresolved_import(pretty_package, &span).into()),
};
resolved_packages.insert(package.clone(), resolved_package);
}
Ok(Program {
name: program.name.clone(),
expected_input,
import_statements,
imports: resolved_packages,
aliases,
circuits,
functions,
global_consts,
})
}
}

View File

@ -0,0 +1,57 @@
// Copyright (C) 2019-2021 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 crate::{DefinitionStatement, Identifier};
use indexmap::IndexMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[allow(clippy::ptr_arg)]
pub fn serialize<S: Serializer>(
global_consts: &IndexMap<Vec<Identifier>, DefinitionStatement>,
serializer: S,
) -> Result<S::Ok, S::Error> {
let joined: IndexMap<String, DefinitionStatement> = global_consts
.into_iter()
.map(|(idents, program)| {
(
idents.iter().map(|i| i.name.to_string()).collect::<Vec<_>>().join(","),
program.clone(),
)
})
.collect();
joined.serialize(serializer)
}
pub fn deserialize<'de, D: Deserializer<'de>>(
deserializer: D,
) -> Result<IndexMap<Vec<Identifier>, DefinitionStatement>, D::Error> {
Ok(IndexMap::<String, DefinitionStatement>::deserialize(deserializer)?
.into_iter()
.map(|(name, program)| {
(
name.split(',')
.map(|ident_name| Identifier {
name: ident_name.into(),
span: Default::default(),
})
.collect::<Vec<Identifier>>(),
program,
)
})
.collect())
}

View File

@ -20,6 +20,8 @@ pub use array_dimensions::*;
pub mod const_self_keyword;
pub use const_self_keyword::*;
pub mod global_consts_json;
pub mod identifier;
pub use identifier::*;

View File

@ -33,7 +33,8 @@ pub struct Program {
pub imports: IndexMap<Vec<String>, Program>,
pub aliases: IndexMap<Identifier, Alias>,
pub circuits: IndexMap<Identifier, Circuit>,
pub global_consts: IndexMap<String, DefinitionStatement>,
#[serde(with = "crate::common::global_consts_json")]
pub global_consts: IndexMap<Vec<Identifier>, DefinitionStatement>,
pub functions: IndexMap<Identifier, Function>,
}

View File

@ -387,7 +387,7 @@ pub trait ReconstructingReducer {
aliases: IndexMap<Identifier, Alias>,
circuits: IndexMap<Identifier, Circuit>,
functions: IndexMap<Identifier, Function>,
global_consts: IndexMap<String, DefinitionStatement>,
global_consts: IndexMap<Vec<Identifier>, DefinitionStatement>,
) -> Result<Program> {
Ok(Program {
name: program.name.clone(),

View File

@ -251,7 +251,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
// Preform import resolution.
ast = leo_ast_passes::Importer::do_pass(
ast.into_repr(),
ImportParser::new(self.main_file_path.clone(), self.imports_map.clone()),
&mut ImportParser::new(self.main_file_path.clone(), self.imports_map.clone()),
)?;
if self.ast_snapshot_options.imports_resolved {

View File

@ -420,6 +420,14 @@ create_errors!(
help: None,
}
/// For when a user defines an circuit with the same name twice.
@formatted
duplicate_circuit_definition {
args: (name: impl Display),
msg: format!("a circuit named \"{}\" already exists in this scope", name),
help: None,
}
/// For when a user defines a function input with the same name twice.
@formatted
duplicate_function_input_definition {
@ -436,11 +444,27 @@ create_errors!(
help: None,
}
/// For when a named identifier is being shadowed.
/// For when a function input shadows a global const.
@formatted
cannot_shadow_name {
args: (type_: impl Display, name: impl Display, location: impl Display),
msg: format!("a {} cannot be named `{}` as a {} with that name already exists in this scope", type_, name, location),
function_input_cannot_shadow_global_const {
args: (name: impl Display),
msg: format!("a function input cannot be named `{}` as a global const with that name already exists in this scope", name),
help: None,
}
/// For when a variable definition shadows a global const.
@formatted
function_variable_cannot_shadow_global_const {
args: (name: impl Display),
msg: format!("a variable cannot be named `{}` as a global const with that name already exists in this scope", name),
help: None,
}
/// For when a variable definition shadows a function input.
@formatted
function_variable_cannot_shadow_other_function_variable {
args: (name: impl Display),
msg: format!("a variable cannot be named `{}` as a function input or variable with that name already exists in this scope", name),
help: None,
}
);

View File

@ -35,7 +35,10 @@ impl ImportParser {
return self.parse_package(package.path(), remaining_segments, span);
}
Self::parse_import_file(package, span)
let program = Self::parse_import_file(package, span)?;
let ast = leo_ast_passes::Importer::do_pass(program, self)?.into_repr();
Ok(ast)
}
///

View File

@ -507,14 +507,13 @@ impl ParserContext {
/// Returns an [`(String, DefinitionStatement)`] AST node if the next tokens represent a global
/// const definition statement and assignment.
///
pub fn parse_global_const_declaration(&mut self) -> Result<(String, DefinitionStatement)> {
pub fn parse_global_const_declaration(&mut self) -> Result<(Vec<Identifier>, DefinitionStatement)> {
let statement = self.parse_definition_statement()?;
let variable_names = statement
.variable_names
.iter()
.map(|variable_name| variable_name.identifier.name.to_string())
.collect::<Vec<String>>()
.join(",");
.map(|variable_name| variable_name.identifier.clone())
.collect::<Vec<Identifier>>();
Ok((variable_names, statement))
}

View File

@ -143,7 +143,7 @@ fn generate_asts(path: PathBuf, text: &str) -> Result<(String, String, String, S
let mut ast = leo_parser::parse_ast(path.clone().into_os_string().into_string().unwrap(), text)?;
let initial = ast.to_json_string()?;
ast = leo_ast_passes::Importer::do_pass(ast.into_repr(), ImportParser::new(path, Default::default()))?;
ast = leo_ast_passes::Importer::do_pass(ast.into_repr(), &mut ImportParser::new(path, Default::default()))?;
let imports_resolved = ast.to_json_string()?;
ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?;

View File

@ -0,0 +1,17 @@
/*
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

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

View File

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

View File

@ -5,23 +5,29 @@ input_file: input/dummy.in
*/
circuit Foo {
x: u32;
x: u32;
function new() -> Self {
let new: Self = Self {
x: 1u32
};
function new() -> Self {
let new: Self = Self {
x: 1u32
};
return new;
}
return new;
}
function etc() {
let y = [0u32, 1, 2, 3];
y[Self {x: 0}.x] += 2;
}
function etc() {
let y = [0u32, 1, 2, 3];
y[Self {x: 0}.x] += 2;
}
function func() {
const x: Self = Foo {x: Self {x: 1}.x};
}
function self_circ(x: Self) {}
}
function main(y: bool) -> bool {
let foo: Foo = Foo::new();
return foo.x == 1u32 && y;
let foo: Foo = Foo::new();
return foo.x == 1u32 && y;
}

View File

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

View File

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

View File

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

View File

@ -5,10 +5,12 @@ input_file: input/dummy.in
*/
function main() {
function main(y: bool) -> bool {
console.log("{}", 1u8);
return y;
}
function main() {
function main(y: bool) -> bool {
console.log("{}", 2u8);
return y;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,13 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function tester(hi: u8) {
const hi = 1u8;
}
function main (y: bool) -> bool {
return y;
}

View File

@ -0,0 +1,13 @@
/*
namespace: Compile
expectation: Fail
input_file: input/dummy.in
*/
function tester(hi: u8) {
const hi = 2u8;
}
function main (y: bool) -> bool {
return y;
}

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@ const complex_group = (_, 1)group;
const field_test: field = 2;
const use_another_const = basic + 1;
const foo = Foo { width: 10, height: 20 };
const uno = uno();
const one = uno();
const character = 'a';
const hello = "Hello, World!";
@ -49,7 +49,7 @@ function main(a: u32) -> bool {
&& use_another_const == 9u32 // use another const test
&& foo.width == 10u32 // circuit test
&& foo.height == 20u32
&& uno == 1u32 // function test
&& one == 1u32 // function test
&& character == 'a' // char test
&& hello == "Hello, World!";
}

View File

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

View File

@ -11,6 +11,8 @@ function main(y: bool) -> bool {
const a = Point { x: 1u32, y: 0u32 };
const hello_alias: char5 = "hello";
const hello = "hello";
const eight = 8u8;
const fab = fab_gen();
return( (foo() == 1u32) && hello_alias == hello) == y;
return( (foo() == 1u32) && hello_alias == hello && EIGHT == eight) == y;
}

View File

@ -8,3 +8,11 @@ function foo() -> u32 {
}
type char5 = [char; 5];
const EIGHT = 8u8;
import nested.c-d.Fab;
function fab_gen() -> Fab {
return Fab { x: 3 };
}

View File

@ -1,3 +1,7 @@
circuit Fab {
x: u8;
}
function cd() -> bool {
return true;
}

View File

@ -5,7 +5,7 @@ input_file: inputs/true_true.in
*/
function main(a: (bool, bool)) -> (bool, bool) {
const a = (true, false);
const b = (true, false);
return (a.0, a.1);
return (b.0, b.1);
}

View File

@ -5,7 +5,7 @@ input_file: inputs/true_true.in
*/
function main(a: (bool, bool)) -> (bool, bool) {
let a = (a.0 ? false : true, a.1 ? false : true);
let b = (a.0 ? false : true, a.1 ? false : true);
return (a.0, a.1);
return (b.0, b.1);
}

View File

@ -5,7 +5,7 @@ input_file: inputs/true_true.in
*/
function main(a: (bool, bool)) -> (bool, bool) {
let (a, b) = (a.0 ? false : true, a.1 ? false : true);
let (b, c) = (a.0 ? false : true, a.1 ? false : true);
return (b, a);
return (c, b);
}

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373044]: a alias named \"Int\" already exists in this scope\n --> compiler-test:6:9\n |\n 6 | circuit Int {\n | ^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:5:1\n |\n 5 | function int() {}\n | ^^^^^^^^^^^^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:5:1\n |\n 5 | const int = 8u8;\n | ^^^^^^^^^^^^^^^"

View File

@ -16,7 +16,7 @@ outputs:
r0:
type: bool
value: "true"
initial_ast: 3802c9e1638389140218e5eacb10d9ee53398ed6c083cfa4c24b7f4218512e45
imports_resolved_ast: 3802c9e1638389140218e5eacb10d9ee53398ed6c083cfa4c24b7f4218512e45
canonicalized_ast: 6c18b527bfd6571cfb1af7113259977040ec35ad2593bbe275011d0b204afe81
type_inferenced_ast: 3f4dc74bea13fe2e97a042f3b4dd7042df725a172a151db628745ee3c7d7cd1a
initial_ast: d8ff1c8c84bc93bbd4e712dde7eb3c9dbe433199f5902b6dc3329cf3ca607811
imports_resolved_ast: d8ff1c8c84bc93bbd4e712dde7eb3c9dbe433199f5902b6dc3329cf3ca607811
canonicalized_ast: 9ef4d52afc2cbbcaa7759af48d1603feb28287d619293135a7856625a37299f7
type_inferenced_ast: f3a91e1cd91f60c94ffe809369eeecb2f22996b6f14c1589a5c7a825519a6b1e

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373044]: a alias named \"Int\" already exists in this scope\n --> compiler-test:3:9\n |\n 3 | circuit Int {\n | ^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373015]: a function named \"Foo\" already exists in this scope\n --> compiler-test:3:9\n |\n 3 | circuit Foo {\n | ^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373045]: a circuit named \"Foo\" already exists in this scope\n --> compiler-test:7:1\n |\n 7 | const Foo = 8u8;\n | ^^^^^^^^^^^^^^^"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373015]: a function named \"main\" already exists in this scope\n --> compiler-test:8:1\n |\n 8 | function main() {\n 9 | ...\n 10 | }\n | ^"
- "Error [EASG0373015]: a function named \"main\" already exists in this scope\n --> compiler-test:9:1\n |\n 9 | function main(y: bool) -> bool {\n 10 | ...\n 11 | ...\n 12 | }\n | ^"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373045]: a function input named \"a\" already exists in this scope\n --> compiler-test:3:23\n |\n 3 | function main(a: u32, a: u32) {\n | ^"
- "Error [EASG0373046]: a function input named \"a\" already exists in this scope\n --> compiler-test:3:23\n |\n 3 | function main(a: u32, a: u32) {\n | ^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | function int() {}\n | ^^^^^^^^^^^^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373015]: a function named \"Foo\" already exists in this scope\n --> compiler-test:5:9\n |\n 5 | circuit Foo {\n | ^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373015]: a function named \"foo\" already exists in this scope\n --> compiler-test:5:1\n |\n 5 | const foo = 8u8;\n | ^^^^^^^^^^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373048]: a function input cannot be named `hi` as a global const with that name already exists in this scope\n --> compiler-test:5:17\n |\n 5 | function tester(hi: u8) {}\n | ^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373050]: a variable cannot be named `hi` as a function input or variable with that name already exists in this scope\n --> compiler-test:4:11\n |\n 4 | const hi = 1u8;\n | ^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373050]: a variable cannot be named `hi` as a function input or variable with that name already exists in this scope\n --> compiler-test:4:11\n |\n 4 | const hi = 2u8;\n | ^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373044]: a alias named \"int\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | const int = 8u8;\n | ^^^^^^^^^^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373045]: a circuit named \"Foo\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | const Foo = 8u8;\n | ^^^^^^^^^^^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373015]: a function named \"two\" already exists in this scope\n --> compiler-test:3:1\n |\n 3 | const two = 2u8;\n | ^^^^^^^^^^^^^^^"

View File

@ -16,7 +16,7 @@ outputs:
r0:
type: bool
value: "false"
initial_ast: b4e5073c07791c4726b69f3e60ec66ccebefb7a3811f4a3576fc4042f8c80114
imports_resolved_ast: b4e5073c07791c4726b69f3e60ec66ccebefb7a3811f4a3576fc4042f8c80114
canonicalized_ast: 03a4e0ffc6deea9c6500a9d91eb683a780e8f5961801bea1aab26c14e4543325
type_inferenced_ast: abbbde55152e4dfe84e7c1f1a6cb82cbcf8b54d46efbcaa7b8c0854f6dee9e25
initial_ast: d53a0267c4afe271c6488aeda9910433e3a947d96530ea1286eba511e6e8f17e
imports_resolved_ast: d53a0267c4afe271c6488aeda9910433e3a947d96530ea1286eba511e6e8f17e
canonicalized_ast: 86bc6722c866a18e2b4d022e67c82dfa0f20f1b4d86d2869f6267010ef45c0c6
type_inferenced_ast: 0c7674288e3db92d39726e8d2964f7c03eeb8e27ec54d0cd558b20e976a48686

View File

@ -16,7 +16,7 @@ outputs:
r0:
type: bool
value: "true"
initial_ast: 7db61dab5c9e6647ad0649ba4fac74c7d5c7d6990f301db9f8da7c2deb2d0078
imports_resolved_ast: a1eeec54a46d6e9afba716fbc27cf5650875e01bb4f035d74f504934654761a6
canonicalized_ast: 12b30de036076b06f0409f38b0b84df3100cd8293eb8bf5def0f397d133f8ce1
type_inferenced_ast: 9db739a86d6e420f1d2a60078efc7a048a2985b264fb25ab218d962be573c20c
initial_ast: 44686de6ff7da19563c7435f977498fa070fe70394604f00891ac56919b49fc9
imports_resolved_ast: 04931e9a33306909e081ee99676f78fea07a00a88fddea1b41b7f49fe01b8b74
canonicalized_ast: 54f102c09881160287bb9ddd18a8b827b1fbd7a5e7f65a6bf930c2e1d289895a
type_inferenced_ast: 72cfbfa0e53d0f93ef984949371141b4ed9adb0b4663775a0a973cd04681a826

View File

@ -17,6 +17,6 @@ outputs:
type: bool
value: "true"
initial_ast: ae6826642faa492e34507695dbd11e5b44c319aecb0b1e78b29ce03ae446d907
imports_resolved_ast: e08b138c63ede9de6e090e6b7fbcfbbc27a1ae49b032a6cffcafaa8f76410839
canonicalized_ast: e08b138c63ede9de6e090e6b7fbcfbbc27a1ae49b032a6cffcafaa8f76410839
type_inferenced_ast: 71e74fbf0bd10a5f2069ebc887ae3e624bd1d4f8654878b54fb932cdbb067752
imports_resolved_ast: 20295c05b1768223eff4982abafe03e060196400ccf046df15a48a0a87c5fcdb
canonicalized_ast: 20295c05b1768223eff4982abafe03e060196400ccf046df15a48a0a87c5fcdb
type_inferenced_ast: edfcbd28230c0bae0b1e7fd32d8e72898368bc5ea7fe58cc285bb5c7e0588d24

View File

@ -17,6 +17,6 @@ outputs:
type: bool
value: "true"
initial_ast: bb86f336b58de89c79741628133e6aa997f3f49a6f066b8c054261e91e3f18a8
imports_resolved_ast: 1fe862bf85cf0c88ce3c52066118d544f367984dbe97665b2719281de15c449c
canonicalized_ast: 1fe862bf85cf0c88ce3c52066118d544f367984dbe97665b2719281de15c449c
type_inferenced_ast: d8f6f5bde53232553d1ff891e7f78823645d9a8984139d06409cb2ccde562e76
imports_resolved_ast: 7f53319b8eeb7fd2e7e76e7cbe6f130b3af9918060519cc111a45f9739cd8085
canonicalized_ast: 7f53319b8eeb7fd2e7e76e7cbe6f130b3af9918060519cc111a45f9739cd8085
type_inferenced_ast: 1fcfebcdbf04cba7f2878b8efe881f598407a0f15c5419bb7da7a8ea9ec37438

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Error [EASG0373016]: a variable named \"x\" already exists in this scope\n --> compiler-test:5:3\n |\n 5 | let x = true;\n | ^^^^^^^^^^^^"
- "Error [EASG0373050]: a variable cannot be named `x` as a function input or variable with that name already exists in this scope\n --> compiler-test:5:7\n |\n 5 | let x = true;\n | ^"

View File

@ -19,7 +19,7 @@ outputs:
c:
type: bool
value: "false"
initial_ast: 51cc6c9ff08fa4320783cf8b6683f784a6325a0e371c7d93049c30eb9d04cf72
imports_resolved_ast: 51cc6c9ff08fa4320783cf8b6683f784a6325a0e371c7d93049c30eb9d04cf72
canonicalized_ast: 51cc6c9ff08fa4320783cf8b6683f784a6325a0e371c7d93049c30eb9d04cf72
type_inferenced_ast: a1e55a4a926b0d9c8d0f611136c7f9ba8ed5c6156a85d1d04adc9faaadf1a611
initial_ast: 10550feaa2c5235500abf424e222f1f8383225ae3b6906c1cd76835e83286817
imports_resolved_ast: 10550feaa2c5235500abf424e222f1f8383225ae3b6906c1cd76835e83286817
canonicalized_ast: 10550feaa2c5235500abf424e222f1f8383225ae3b6906c1cd76835e83286817
type_inferenced_ast: db07b90097bb2605e23365d07d039b7845e9c7e7313a7ecaa01116dae93912ad

View File

@ -19,7 +19,7 @@ outputs:
c:
type: bool
value: "false"
initial_ast: 6692e9d94d784dd3cd11dbf48ac13b0b54f61d83ba0d85bf038e9bf84590851f
imports_resolved_ast: 6692e9d94d784dd3cd11dbf48ac13b0b54f61d83ba0d85bf038e9bf84590851f
canonicalized_ast: 6692e9d94d784dd3cd11dbf48ac13b0b54f61d83ba0d85bf038e9bf84590851f
type_inferenced_ast: 0d8c2b2b77762cfb957d5d6247366317b8fbe4ac7cb985df1b4d3511accf13b8
initial_ast: be3a0206397e9b0f95c696b4d7174ee81262e805fc787b3516b1b1a277892a4d
imports_resolved_ast: be3a0206397e9b0f95c696b4d7174ee81262e805fc787b3516b1b1a277892a4d
canonicalized_ast: be3a0206397e9b0f95c696b4d7174ee81262e805fc787b3516b1b1a277892a4d
type_inferenced_ast: 672df08a8f52ff75d5cdba1f4ebc070baba70a981351819d2205b3e8de76bfc7

View File

@ -19,7 +19,7 @@ outputs:
c:
type: bool
value: "true"
initial_ast: 531df9191a6ee867da7a9c5aa5120a9ab93eec5d4d29bdc78aa965fce0f52c8d
imports_resolved_ast: 531df9191a6ee867da7a9c5aa5120a9ab93eec5d4d29bdc78aa965fce0f52c8d
canonicalized_ast: 531df9191a6ee867da7a9c5aa5120a9ab93eec5d4d29bdc78aa965fce0f52c8d
type_inferenced_ast: b841d6651b93193e0bbd24df8b667bd16066ee77481dd3b8b0187c37968ca1c1
initial_ast: ea7f6cc8c9fe0deda02c3fde1f33dd71c33b6938c832af0f220fb681f56f9354
imports_resolved_ast: ea7f6cc8c9fe0deda02c3fde1f33dd71c33b6938c832af0f220fb681f56f9354
canonicalized_ast: ea7f6cc8c9fe0deda02c3fde1f33dd71c33b6938c832af0f220fb681f56f9354
type_inferenced_ast: 72d9dedc48ac69de544b2f35b1f0e675f4053f562fc708b30eebcfdc6ac59dc9