diff --git a/compiler/ast/src/passes/reconstructor/statement.rs b/compiler/ast/src/passes/reconstructor/statement.rs index 9ca1cb7157..bae5d40507 100644 --- a/compiler/ast/src/passes/reconstructor/statement.rs +++ b/compiler/ast/src/passes/reconstructor/statement.rs @@ -39,7 +39,17 @@ pub trait StatementReconstructor: ExpressionReconstructor + InstructionReconstru } fn reconstruct_assembly_block(&mut self, input: AssemblyBlock) -> (Statement, Self::AdditionalOutput) { - todo!() + ( + Statement::AssemblyBlock(AssemblyBlock { + instructions: input + .instructions + .into_iter() + .map(|inst| self.reconstruct_instruction(inst).0) + .collect(), + span: input.span, + }), + Default::default(), + ) } fn reconstruct_assert(&mut self, input: AssertStatement) -> (Statement, Self::AdditionalOutput) { diff --git a/compiler/parser/src/parser/instruction.rs b/compiler/parser/src/parser/instruction.rs index e1e574cc10..c1649a4a0e 100644 --- a/compiler/parser/src/parser/instruction.rs +++ b/compiler/parser/src/parser/instruction.rs @@ -51,7 +51,7 @@ impl ParserContext<'_> { | Expression::Access(AccessExpression::Member(_)) => {} // Valid _ => return Err(ParserError::invalid_instruction_operand(expression.span()).into()), } - operands.push(self.parse_expression()?); + operands.push(expression); } if self.check_identifier_with_name(sym::into) { // Parse the `into` keyword. diff --git a/compiler/passes/src/code_generation/mod.rs b/compiler/passes/src/code_generation/mod.rs index 1a441b0abe..c300d234d1 100644 --- a/compiler/passes/src/code_generation/mod.rs +++ b/compiler/passes/src/code_generation/mod.rs @@ -19,6 +19,8 @@ pub use generator::*; mod visit_expressions; +mod visit_instruction; + mod visit_program; mod visit_statements; diff --git a/compiler/passes/src/code_generation/visit_instruction.rs b/compiler/passes/src/code_generation/visit_instruction.rs new file mode 100644 index 0000000000..c771091822 --- /dev/null +++ b/compiler/passes/src/code_generation/visit_instruction.rs @@ -0,0 +1,48 @@ +// Copyright (C) 2019-2023 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 . + +use crate::CodeGenerator; + +use leo_ast::Instruction; + +use itertools::Itertools; + +impl<'a> CodeGenerator<'a> { + pub(crate) fn visit_instruction(&mut self, instruction: &'a Instruction) -> String { + // Visit the instruction operands. + // Note that parsing guarantees that the operands are either literals, identifiers, or member accesses. + let operands = instruction + .operands + .iter() + .map(|operand| self.visit_expression(operand).0) + .join(" "); + // Construct the new destination registers and add them to mapping. + let destinations = instruction + .destinations + .iter() + .map(|identifier| { + let destination_register = format!("r{}", self.next_register); + // Increment the register counter. + self.next_register += 1; + // Add the destination to the mapping. + self.variable_mapping + .insert(&identifier.name, destination_register.clone()); + destination_register + }) + .join(" "); + format!("{} {} into {};", instruction.opcode, operands, destinations) + } +} diff --git a/compiler/passes/src/code_generation/visit_statements.rs b/compiler/passes/src/code_generation/visit_statements.rs index 0eaba77d70..06baaa964d 100644 --- a/compiler/passes/src/code_generation/visit_statements.rs +++ b/compiler/passes/src/code_generation/visit_statements.rs @@ -44,11 +44,12 @@ impl<'a> CodeGenerator<'a> { } fn visit_assembly_block(&mut self, input: &'a AssemblyBlock) -> String { - let mut instructions = String::new(); - for instruction in &input.instructions { - instructions.push_str(&instruction.to_string()); - } - instructions + // For each instruction in the block, visit it and add it to the program. + input + .instructions + .iter() + .map(|inst| self.visit_instruction(inst)) + .join("") } fn visit_assert(&mut self, input: &'a AssertStatement) -> String { diff --git a/compiler/passes/src/dead_code_elimination/dead_code_eliminator.rs b/compiler/passes/src/dead_code_elimination/dead_code_eliminator.rs index 6d7c18c5eb..9544349ad8 100644 --- a/compiler/passes/src/dead_code_elimination/dead_code_eliminator.rs +++ b/compiler/passes/src/dead_code_elimination/dead_code_eliminator.rs @@ -17,6 +17,7 @@ use leo_span::Symbol; use indexmap::IndexSet; +use leo_ast::{Instruction, InstructionReconstructor}; #[derive(Default)] pub struct DeadCodeEliminator { @@ -35,3 +36,10 @@ impl DeadCodeEliminator { } } } + +impl InstructionReconstructor for DeadCodeEliminator { + /// Instructions in assembly blocks are not to be eliminated. + fn reconstruct_instruction(&mut self, input: Instruction) -> (Instruction, Self::AdditionalOutput) { + (input, Default::default()) + } +} diff --git a/compiler/passes/src/type_checking/check_expression.rs b/compiler/passes/src/type_checking/check_expression.rs index e2a1ed8a0c..989c0bd35e 100644 --- a/compiler/passes/src/type_checking/check_expression.rs +++ b/compiler/passes/src/type_checking/check_expression.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::TypeChecker; -use std::borrow::Borrow; use leo_ast::*; use leo_errors::emitter::Handler; diff --git a/compiler/passes/src/type_checking/check_instruction.rs b/compiler/passes/src/type_checking/check_instruction.rs index 62ea2969aa..bafec3bb05 100644 --- a/compiler/passes/src/type_checking/check_instruction.rs +++ b/compiler/passes/src/type_checking/check_instruction.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{TypeChecker, VariableSymbol, VariableType}; +use crate::{TypeChecker, VariableType}; -use leo_ast::{Expression, ExpressionVisitor, Instruction, InstructionVisitor, IntegerType, Node, Opcode, Type}; +use leo_ast::{ExpressionVisitor, Instruction, InstructionVisitor, IntegerType, Node, Opcode, Type}; use leo_errors::TypeCheckerError; use itertools::Itertools; @@ -26,21 +26,26 @@ impl<'a> TypeChecker<'a> { fn check_instruction_is_well_formed( &mut self, instruction: &'a Instruction, - ) { + ) -> bool { + // A flag to indicate if the instruction is well-formed. + let mut is_well_formed = true; // Check that the number of operands is NUM_OPERANDS. if instruction.operands.len() != NUM_OPERANDS { + is_well_formed = false; self.emit_err(TypeCheckerError::malformed_instruction( format!("Expected {NUM_OPERANDS} operands."), instruction.span, )); - } + }; // Check that the number of destinations is NUM_DESTINATIONS. if instruction.destinations.len() != NUM_DESTINATIONS { + is_well_formed = false; self.emit_err(TypeCheckerError::malformed_instruction( format!("Expected {NUM_DESTINATIONS} destination registers."), instruction.span, )); - } + }; + is_well_formed } // Helper to type check standard instructions. @@ -49,62 +54,71 @@ impl<'a> TypeChecker<'a> { instruction: &'a Instruction, expected_types: &[([Type; NUM_OPERANDS], [Type; NUM_DESTINATIONS])], ) { - // Check that the structure of the instruction is well-formed. - self.check_instruction_is_well_formed::(instruction); - // Get the types of the operands. - let operand_types = instruction - .operands - .iter() - .map(|operand| self.visit_expression(operand, &None)) - .collect_vec(); // Check that the types of the operands match one of the expected operand types. - let destination_types = expected_types - .iter() - .find(|(expected_operand_types, _)| { - operand_types - .iter() - .zip_eq(expected_operand_types.iter()) - .all(|(operand_type, expected_type)| match operand_type { - Some(operand_type) => operand_type.eq_flat(expected_type), - None => false, - }) - }) - .map(|(_, expected_destination_types)| expected_destination_types); - // If the destination types are found, add the destination registers to the symbol table. - // Otherwise, emit an error. - match destination_types { - Some(destination_types) => { - for (destination, destination_type) in instruction.destinations.iter().zip_eq(destination_types.iter()) - { - self.insert_variable( - destination.name, - destination_type.clone(), - destination.span, - VariableType::Mut, - ); + println!("NUM_OPERANDS: {}", NUM_OPERANDS); + println!("NUM_DESTINATIONS: {}", NUM_DESTINATIONS); + println!("instruction: {:?}", instruction); + // Check that the structure of the instruction is well-formed. + if self.check_instruction_is_well_formed::(instruction) { + // Get the types of the operands. + let operand_types = instruction + .operands + .iter() + .map(|operand| self.visit_expression(operand, &None)) + .collect_vec(); + + println!("operand_types: {:?}", operand_types); + + let destination_types = expected_types + .iter() + .find(|(expected_operand_types, _)| { + operand_types + .iter() + .zip_eq(expected_operand_types.iter()) + .all(|(operand_type, expected_type)| match operand_type { + Some(operand_type) => operand_type.eq_flat(expected_type), + None => false, + }) + }) + .map(|(_, expected_destination_types)| expected_destination_types); + // If the destination types are found, add the destination registers to the symbol table. + // Otherwise, emit an error. + match destination_types { + Some(destination_types) => { + for (destination, destination_type) in + instruction.destinations.iter().zip_eq(destination_types.iter()) + { + self.insert_variable( + destination.name, + destination_type.clone(), + destination.span, + VariableType::Mut, + ); + } } + None => self.emit_err(TypeCheckerError::invalid_instruction_operand_types( + &instruction.opcode, + expected_types + .iter() + .map(|(operand_types, _)| format!("({})", operand_types.iter().join(", "))) + .join(", "), + instruction.span, + )), } - None => self.emit_err(TypeCheckerError::invalid_instruction_operand_types( - &instruction.opcode, - expected_types - .iter() - .map(|(operand_types, _)| format!("({})", operand_types.iter().join(", "))) - .join(", "), - instruction.span, - )), } } // Helper to type check commit instructions. fn check_commit_instruction(&mut self, instruction: &'a Instruction, output_type: Type) { // Check that the structure of the instruction is well-formed. - self.check_instruction_is_well_formed::<2, 1>(instruction); - // Check that the second operand is a scalar. - let second_type = self.visit_expression(&instruction.operands[1], &None); - self.assert_type(&second_type, &Type::Scalar, instruction.operands[1].span()); - // Add the destination register to the symbol table. - let destination = &instruction.destinations[0]; - self.insert_variable(destination.name, output_type, destination.span, VariableType::Mut); + if self.check_instruction_is_well_formed::<2, 1>(instruction) { + // Check that the second operand is a scalar. + let second_type = self.visit_expression(&instruction.operands[1], &None); + self.assert_type(&second_type, &Type::Scalar, instruction.operands[1].span()); + // Add the destination register to the symbol table. + let destination = &instruction.destinations[0]; + self.insert_variable(destination.name, output_type, destination.span, VariableType::Mut); + } } } @@ -162,11 +176,12 @@ impl<'a> InstructionVisitor<'a> for TypeChecker<'a> { )), Opcode::AssertEq | Opcode::AssertNeq => { // Check that the instruction is well-formed. - self.check_instruction_is_well_formed::<2, 0>(instruction); - // Check that the operands are the same type. - let lhs = self.visit_expression(&instruction.operands[0], &None); - let rhs = self.visit_expression(&instruction.operands[1], &None); - self.check_eq_types(&lhs, &rhs, instruction.span); + if self.check_instruction_is_well_formed::<2, 0>(instruction) { + // Check that the operands are the same type. + let lhs = self.visit_expression(&instruction.operands[0], &None); + let rhs = self.visit_expression(&instruction.operands[1], &None); + self.check_eq_types(&lhs, &rhs, instruction.span); + } } Opcode::CommitBHP256 | Opcode::CommitBHP512 | Opcode::CommitBHP768 | Opcode::CommitBHP1024 => self.check_commit_instruction(instruction, Type::Field), Opcode::CommitPED64 | Opcode::CommitPED128 => self.check_commit_instruction(instruction, Type::Group), @@ -201,10 +216,11 @@ impl<'a> InstructionVisitor<'a> for TypeChecker<'a> { | Opcode::HashPSD4 | Opcode::HashPSD8 => { // Check that the instruction is well-formed. - self.check_instruction_is_well_formed::<1, 1>(instruction); - // Add the destination to the symbol table. - let destination = &instruction.destinations[0]; - self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut); + if self.check_instruction_is_well_formed::<1, 1>(instruction) { + // Add the destination to the symbol table. + let destination = &instruction.destinations[0]; + self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut); + } } Opcode::Inv | Opcode::Square @@ -213,14 +229,15 @@ impl<'a> InstructionVisitor<'a> for TypeChecker<'a> { )), Opcode::IsEq | Opcode::IsNeq => { // Check that the instruction is well formed. - self.check_instruction_is_well_formed::<2, 1>(instruction); - // Check that the operands are of the same type. - let lhs = self.visit_expression(&instruction.operands[0], &None); - let rhs = self.visit_expression(&instruction.operands[1], &None); - self.check_eq_types(&lhs, &rhs, instruction.span); - // Add the destination to the symbol table. - let destination = &instruction.destinations[0]; - self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut); + if self.check_instruction_is_well_formed::<2, 1>(instruction) { + // Check that the operands are of the same type. + let lhs = self.visit_expression(&instruction.operands[0], &None); + let rhs = self.visit_expression(&instruction.operands[1], &None); + self.check_eq_types(&lhs, &rhs, instruction.span); + // Add the destination to the symbol table. + let destination = &instruction.destinations[0]; + self.insert_variable(destination.name, Type::Boolean, destination.span, VariableType::Mut); + } } Opcode::Modulo => self.check_instruction(instruction, declare_types!( (Type::Integer(IntegerType::U8), Type::Integer(IntegerType::U8) => Type::Integer(IntegerType::U8)), diff --git a/compiler/passes/src/type_checking/check_statement.rs b/compiler/passes/src/type_checking/check_statement.rs index 92f778d836..1c9eead71b 100644 --- a/compiler/passes/src/type_checking/check_statement.rs +++ b/compiler/passes/src/type_checking/check_statement.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{TypeChecker, VariableSymbol, VariableType}; +use crate::{TypeChecker, VariableType}; use itertools::Itertools; use leo_ast::*; use leo_errors::TypeCheckerError; -use leo_span::{Span, Symbol}; impl<'a> StatementVisitor<'a> for TypeChecker<'a> { fn visit_statement(&mut self, input: &'a Statement) { diff --git a/tests/expectations/compiler/assembly/assembly.out b/tests/expectations/compiler/assembly/assembly.out new file mode 100644 index 0000000000..460cccb2ae --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly.out @@ -0,0 +1,11 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - initial_ast: d0725a7e0e729114b8cd54afc6b10412d84a15742ae6c12f60aba1676c4b7566 + unrolled_ast: d0725a7e0e729114b8cd54afc6b10412d84a15742ae6c12f60aba1676c4b7566 + ssa_ast: 22981ac2db8108536bd67526d33619a2441424115d8a1e4d2691d3e9248e4963 + flattened_ast: 02600d807e502eed2ef7c21fb0a73fb9beabf48b2f6fef022b71543e4636e6c5 + inlined_ast: 02600d807e502eed2ef7c21fb0a73fb9beabf48b2f6fef022b71543e4636e6c5 + dce_ast: 02600d807e502eed2ef7c21fb0a73fb9beabf48b2f6fef022b71543e4636e6c5 + bytecode: 897bea510b0004df84a28144ea171a0a68c5d351e6d3acd4f9aca376226f272e diff --git a/tests/expectations/compiler/assembly/assembly_in_conditional_fail.out b/tests/expectations/compiler/assembly/assembly_in_conditional_fail.out new file mode 100644 index 0000000000..3a6168b867 --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly_in_conditional_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected ; -- found 'return'\n --> compiler-test:10:13\n |\n 10 | return d;\n | ^^^^^^" diff --git a/tests/expectations/compiler/assembly/assembly_in_inline_fail.out b/tests/expectations/compiler/assembly/assembly_in_inline_fail.out new file mode 100644 index 0000000000..e8899cb288 --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly_in_inline_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected ; -- found 'return'\n --> compiler-test:8:9\n |\n 8 | return c;\n | ^^^^^^" diff --git a/tests/expectations/compiler/assembly/assembly_in_loop_fail.out b/tests/expectations/compiler/assembly/assembly_in_loop_fail.out new file mode 100644 index 0000000000..cbe8b825a8 --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly_in_loop_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected ; -- found 'y'\n --> compiler-test:11:13\n |\n 11 | y = z + z;\n | ^" diff --git a/tests/expectations/compiler/assembly/assembly_incorrect_number_of_operands_fail.out b/tests/expectations/compiler/assembly/assembly_incorrect_number_of_operands_fail.out new file mode 100644 index 0000000000..b1ccd6f840 --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly_incorrect_number_of_operands_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected ; -- found 'let'\n --> compiler-test:9:9\n |\n 9 | let f: u8 = d + 1u8;\n | ^^^" diff --git a/tests/expectations/compiler/assembly/assembly_incorrect_operand_types_fail.out b/tests/expectations/compiler/assembly/assembly_incorrect_operand_types_fail.out new file mode 100644 index 0000000000..6490b1ccd1 --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly_incorrect_operand_types_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected ; -- found 'let'\n --> compiler-test:11:9\n |\n 11 | let f: u8 = d + 1u8;\n | ^^^" diff --git a/tests/expectations/compiler/assembly/assembly_shadow_variable_fail.out b/tests/expectations/compiler/assembly/assembly_shadow_variable_fail.out new file mode 100644 index 0000000000..39b94ffaaf --- /dev/null +++ b/tests/expectations/compiler/assembly/assembly_shadow_variable_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected ; -- found 'return'\n --> compiler-test:8:9\n |\n 8 | return a;\n | ^^^^^^" diff --git a/tests/expectations/compiler/integers/i128/operator_methods.out b/tests/expectations/compiler/integers/i128/operator_methods.out index 6878048a6d..56f4d2517a 100644 --- a/tests/expectations/compiler/integers/i128/operator_methods.out +++ b/tests/expectations/compiler/integers/i128/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 450d11de6b2c3495ee84a45223a4d5bb59e4bee0de0953e356c2f441f87d9506 - unrolled_ast: 450d11de6b2c3495ee84a45223a4d5bb59e4bee0de0953e356c2f441f87d9506 - ssa_ast: 570e9b414628d3d469417a9177b1875bb00bfb7d6e207e84b76844acb4a0ca53 - flattened_ast: d2f200afaca7fc18edc44c42546a6aa41f5769b1f3040c7c624e58dddbe24445 - inlined_ast: d2f200afaca7fc18edc44c42546a6aa41f5769b1f3040c7c624e58dddbe24445 + - initial_ast: 56958cf9571d6dfabfaf4e18227ce54fd9b763a535d7aec725242cd9313a4bd7 + unrolled_ast: 56958cf9571d6dfabfaf4e18227ce54fd9b763a535d7aec725242cd9313a4bd7 + ssa_ast: 11dab7eb6db4b7bea80a9152dcc70a1297b81d54dd934b37dfab681960e61832 + flattened_ast: f44271dbd181bcaf30d0564fcd30e5d41510165ef0a00bb9d11c7110b4784c8a + inlined_ast: f44271dbd181bcaf30d0564fcd30e5d41510165ef0a00bb9d11c7110b4784c8a dce_ast: bf253b773de7fbefe2ca492f077f998365c30a2b2dab512cc3d13aaeb7f01bdf bytecode: 3ee7be6b9dbdaa4a046c5ca32ed10de40d57c80c13aba2fa5ee7fd80dd5c1ad3 diff --git a/tests/expectations/compiler/integers/i16/operator_methods.out b/tests/expectations/compiler/integers/i16/operator_methods.out index 4c1052db0e..1e717c6818 100644 --- a/tests/expectations/compiler/integers/i16/operator_methods.out +++ b/tests/expectations/compiler/integers/i16/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 7075037df0d5337fd40c7709ef7ad991e5aa2f8de347d5b5132b00f0dcd443c9 - unrolled_ast: 7075037df0d5337fd40c7709ef7ad991e5aa2f8de347d5b5132b00f0dcd443c9 - ssa_ast: 42ba7b6d8fc7b8bebf50232d4d8ca49769776637ea9aaaeaa1ac8c1b963c5239 - flattened_ast: 9005637746f0f1149b73dff4143b8597c2c8259c1e653c3d74fa6ed982c59904 - inlined_ast: 9005637746f0f1149b73dff4143b8597c2c8259c1e653c3d74fa6ed982c59904 + - initial_ast: 92447c89385d9a8a20fc08b0d2c01249266aeda2bd5928e5760df82e9e7b0bb4 + unrolled_ast: 92447c89385d9a8a20fc08b0d2c01249266aeda2bd5928e5760df82e9e7b0bb4 + ssa_ast: d89ccd15c83bcb68eca0533db460e0cb2a4c5d5d57a63ecd72dd70eaef976bc0 + flattened_ast: 107ce16937aade05a9b3cf6106b5ae4bee1c147432d6f8e5910b80cacdd3dc3f + inlined_ast: 107ce16937aade05a9b3cf6106b5ae4bee1c147432d6f8e5910b80cacdd3dc3f dce_ast: 088a2c4be3dc20eb2b3b7bc25874fa9547ed9cace1f95d15d846ef7f0612b962 bytecode: b36da573e89979cf5999abf1135a2443a42c08527c962edca14559769f7c3927 diff --git a/tests/expectations/compiler/integers/i32/operator_methods.out b/tests/expectations/compiler/integers/i32/operator_methods.out index e6817cd4fd..f5427387c5 100644 --- a/tests/expectations/compiler/integers/i32/operator_methods.out +++ b/tests/expectations/compiler/integers/i32/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 1fa056ac6bfafa193a25d19d92c44b5eb5f5b4aa50f5c910b08d6e1681a918c8 - unrolled_ast: 1fa056ac6bfafa193a25d19d92c44b5eb5f5b4aa50f5c910b08d6e1681a918c8 - ssa_ast: e5816bc6f7f6c533f6e19367575efef7f9d6696d7f5e60a1e01e619c47ae8821 - flattened_ast: 2157b9d9fb3208071b33add3201ff4cce1fe1c67bcce92ce0ec07461681d4851 - inlined_ast: 2157b9d9fb3208071b33add3201ff4cce1fe1c67bcce92ce0ec07461681d4851 + - initial_ast: 4811ff9f8f0c33486600cc2c9eae9977ec93ec03a0a191d7deb3ae587b817a04 + unrolled_ast: 4811ff9f8f0c33486600cc2c9eae9977ec93ec03a0a191d7deb3ae587b817a04 + ssa_ast: 062c86e9f94ca18e845285df1c4036fa2198083f8f9432a024ed9eb453de1732 + flattened_ast: d69caf4f05da1fca41c13d8e675925d301ca0be2705274f7bb44430575d05872 + inlined_ast: d69caf4f05da1fca41c13d8e675925d301ca0be2705274f7bb44430575d05872 dce_ast: 0875ca662c0e764c1e57247e9ce00fb984b437595276f30bb878dc77405f4f12 bytecode: 7ab3f946685bbd31ea648dcaf0dadbacbd6e50e63d1093f23f92f3387cab35f6 diff --git a/tests/expectations/compiler/integers/i64/operator_methods.out b/tests/expectations/compiler/integers/i64/operator_methods.out index 86bff209c6..aba2bc565c 100644 --- a/tests/expectations/compiler/integers/i64/operator_methods.out +++ b/tests/expectations/compiler/integers/i64/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: eff1e9e82caf84d6baa36c5a7eab33739a3bddc8744c50bacfa5f0f8cb0b8bf4 - unrolled_ast: eff1e9e82caf84d6baa36c5a7eab33739a3bddc8744c50bacfa5f0f8cb0b8bf4 - ssa_ast: 295f90c7b29c6f0c9179637bcae0dba07b9212feefe1b133ebd43eb785d847b8 - flattened_ast: 2a49c36ddb55e0b81b1692283c5f6de9cfe5036981b642105714b337ad87df7c - inlined_ast: 2a49c36ddb55e0b81b1692283c5f6de9cfe5036981b642105714b337ad87df7c + - initial_ast: b5d545b7b4a516e63d68211588a56f80490d21bfdfaa86001f5d44416e1366c0 + unrolled_ast: b5d545b7b4a516e63d68211588a56f80490d21bfdfaa86001f5d44416e1366c0 + ssa_ast: d4d72e8e3a0437309be4f675e5aaaa6ffc353034c4cd04c6377d04ee71deefeb + flattened_ast: 0bc0b6ec68ca50a95f29b252d31273b3eafe997afb14273895ef36d2118eab39 + inlined_ast: 0bc0b6ec68ca50a95f29b252d31273b3eafe997afb14273895ef36d2118eab39 dce_ast: df939888692cd36fa2095f9960448ca767efe6bb818dc151e982d05035dc4886 bytecode: 2bc4334f42205f2800b37e69fac6cacfdf6cac174d71034aaee478be2d1a2ef0 diff --git a/tests/expectations/compiler/integers/i8/operator_methods.out b/tests/expectations/compiler/integers/i8/operator_methods.out index 747a096ea9..0c74b3f336 100644 --- a/tests/expectations/compiler/integers/i8/operator_methods.out +++ b/tests/expectations/compiler/integers/i8/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 928201ba3086292b6434c839920a82a165b1b2d782da35d03bd78c1b399325f0 - unrolled_ast: 928201ba3086292b6434c839920a82a165b1b2d782da35d03bd78c1b399325f0 - ssa_ast: 3fd59a9e710784b69e95dca5ad4438ba4d4fa4fed189e7bfb6c0f30140190753 - flattened_ast: 0734a281c1bb57ff93023454c561d63ba6b8db3c2c34b9774e4a2e01d78f2f35 - inlined_ast: 0734a281c1bb57ff93023454c561d63ba6b8db3c2c34b9774e4a2e01d78f2f35 + - initial_ast: 60f44279e5cbe65f6fe0f05b83dad371b65863eb7f175b495535abf820cfe587 + unrolled_ast: 60f44279e5cbe65f6fe0f05b83dad371b65863eb7f175b495535abf820cfe587 + ssa_ast: e59cdbb726cb34d4765af299a3b6e51e14f93b16032e437a8c5f516eb66c6361 + flattened_ast: e51aa122bd6b2eae3b300972952cde859d3bcdd720c8db5d1d496ae1bea99ea1 + inlined_ast: e51aa122bd6b2eae3b300972952cde859d3bcdd720c8db5d1d496ae1bea99ea1 dce_ast: 3a0427fceb512fcd4d113149514140ea60114e1de8d994e631d26ee33bd857c8 bytecode: 6d23c0ce42f90915f6fe75dc44c729d183aef74ea294f3c5c966a069b1a33fdf diff --git a/tests/expectations/compiler/integers/u128/operator_methods.out b/tests/expectations/compiler/integers/u128/operator_methods.out index 474c286fcc..11e3ab0290 100644 --- a/tests/expectations/compiler/integers/u128/operator_methods.out +++ b/tests/expectations/compiler/integers/u128/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: f71270a459a000979dce1bf2f514778c8f9ea4e5cdaa834a5f0797e16fc6c09c - unrolled_ast: f71270a459a000979dce1bf2f514778c8f9ea4e5cdaa834a5f0797e16fc6c09c - ssa_ast: cb7aa960ed672414c1e7665a0b02bbb3926180e9f3a399bf526cbca7aa872c8c - flattened_ast: 8affd64c29c8aa7669652801bd58373f6e096d8c82af4e5f1340b552c3123ad9 - inlined_ast: 8affd64c29c8aa7669652801bd58373f6e096d8c82af4e5f1340b552c3123ad9 + - initial_ast: 7919cc18d1d700acfc094b1fcc2892e362d2eed3213f6bb5583011b65d04b6a2 + unrolled_ast: 7919cc18d1d700acfc094b1fcc2892e362d2eed3213f6bb5583011b65d04b6a2 + ssa_ast: ef61f8fdd1ebe27fa4aea9d93af5f6782025657492183c0e425cd421cae244f0 + flattened_ast: 6724eed786e387aa5be82c83f86c9d4673d07c470bb68458e03c0ce73f2538b0 + inlined_ast: 6724eed786e387aa5be82c83f86c9d4673d07c470bb68458e03c0ce73f2538b0 dce_ast: fab8ab63a79dc1b5b97b7ba1f1252f4779cdc324afd436b6dab44379af0c0c72 bytecode: 43507852e6ea9e5cf869a03c94302133470e5d32579620cf12e95614064223ea diff --git a/tests/expectations/compiler/integers/u16/operator_methods.out b/tests/expectations/compiler/integers/u16/operator_methods.out index 10a75475a8..a9fabbd01b 100644 --- a/tests/expectations/compiler/integers/u16/operator_methods.out +++ b/tests/expectations/compiler/integers/u16/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 673add2e4691004b32b69926b69fd8cd798c15a3d163d197edde976cd0373d6e - unrolled_ast: 673add2e4691004b32b69926b69fd8cd798c15a3d163d197edde976cd0373d6e - ssa_ast: 1aa40498ce952b263c37bf0d5877e071b2be8c2d40d433621256f03000bf1772 - flattened_ast: b69bc1f6e5076a264057b48afe3fb0e850df2143cba1fcaecd4c53e0c692e32b - inlined_ast: b69bc1f6e5076a264057b48afe3fb0e850df2143cba1fcaecd4c53e0c692e32b + - initial_ast: cbf499904045352a886262be52b3d9fd11d54d360f2c08b4d878e736f0b08ce8 + unrolled_ast: cbf499904045352a886262be52b3d9fd11d54d360f2c08b4d878e736f0b08ce8 + ssa_ast: 54defa106ce6b9b1f9413a8c9826d8e60a3038097bb92c5efd63f7795ba71dc3 + flattened_ast: 880fc6a9cdfdc2303f7e17080b1ae257272bac185bcd3c4e627f26c3864dd844 + inlined_ast: 880fc6a9cdfdc2303f7e17080b1ae257272bac185bcd3c4e627f26c3864dd844 dce_ast: 158e4da27be2d9a3ad884b59fc37eb639e4d3ea825d1aa4ef934848b5143c076 bytecode: 77797810cc7ce1ad77b02dc0da8aad7aa850efdee822ccd282305a30899c9dd3 diff --git a/tests/expectations/compiler/integers/u32/operator_methods.out b/tests/expectations/compiler/integers/u32/operator_methods.out index 45378c4131..231911bbc2 100644 --- a/tests/expectations/compiler/integers/u32/operator_methods.out +++ b/tests/expectations/compiler/integers/u32/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 8ec18c0e0cd34833461daf3634b6b9bea5509c830873305da03ff43810ca0a81 - unrolled_ast: 8ec18c0e0cd34833461daf3634b6b9bea5509c830873305da03ff43810ca0a81 - ssa_ast: 3c3bd8bdc9413f5bf10f21e0acf323b043148a56c5e02ad9f8f1a59dd79a286d - flattened_ast: 236bc3e88f512b6158d22daebebf5674e98e26887d6b25ce8e7ba1b1efff03e5 - inlined_ast: 236bc3e88f512b6158d22daebebf5674e98e26887d6b25ce8e7ba1b1efff03e5 + - initial_ast: 1a91672aee80afbe5c84fdcc4d355a63e8309da77531d436dcfc1443d1dc3e31 + unrolled_ast: 1a91672aee80afbe5c84fdcc4d355a63e8309da77531d436dcfc1443d1dc3e31 + ssa_ast: 84968cb36d83d06ee34d5f7331adfebd507e3bb1e86b038faec0bf11bc8f5bbc + flattened_ast: ac051743e4c719e4bb2c236385d3f8bbee056d23c6d74eeb5765f3f4e6f8e8a0 + inlined_ast: ac051743e4c719e4bb2c236385d3f8bbee056d23c6d74eeb5765f3f4e6f8e8a0 dce_ast: 0ec061faa5f9399193029b02f676d02cf6cfe73220c0f375f1a9354637b420f7 bytecode: 3a6e5f56da93ca64f10519ad72c0dfe039273274b0e88fecaec58c40d1717488 diff --git a/tests/expectations/compiler/integers/u64/operator_methods.out b/tests/expectations/compiler/integers/u64/operator_methods.out index 16e55e86ff..4bcbd874c6 100644 --- a/tests/expectations/compiler/integers/u64/operator_methods.out +++ b/tests/expectations/compiler/integers/u64/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: f58fdc2727e425eb2183879fb8e4d915ee076d5e54b88d80945423e990e0ea11 - unrolled_ast: f58fdc2727e425eb2183879fb8e4d915ee076d5e54b88d80945423e990e0ea11 - ssa_ast: 7812a0a147d79d53f32a905f1b44107075bc18ffbb07d350f26d74744623db62 - flattened_ast: f144f6abd33191415592fc866fa5a1374383f14cb3d847a2a9571ccedd910399 - inlined_ast: f144f6abd33191415592fc866fa5a1374383f14cb3d847a2a9571ccedd910399 + - initial_ast: ab8d13323e95a8c8e149e7b8d4cce778a0e8d87d236a1de5f003a5152e109392 + unrolled_ast: ab8d13323e95a8c8e149e7b8d4cce778a0e8d87d236a1de5f003a5152e109392 + ssa_ast: 14cbdb377aee3ff9070429b690adf54e9d44752394a4be47765f88b2b4e22cc5 + flattened_ast: fb16ca7aa74e84ca91b5ac3eed7fa2d06060b132692e7a28ab4d59aa7c19a20e + inlined_ast: fb16ca7aa74e84ca91b5ac3eed7fa2d06060b132692e7a28ab4d59aa7c19a20e dce_ast: 99d13e0f22f1cbd7d9e6a021f3d1c884cce23900eef9d92069629855be3a8d4b bytecode: 6df1568996922ad2b9ebab5d7d0b01d5fcd2b723c2a79b7ccb6a9a8c6da706ab diff --git a/tests/expectations/compiler/integers/u8/operator_methods.out b/tests/expectations/compiler/integers/u8/operator_methods.out index 2b6944131e..bd519136a3 100644 --- a/tests/expectations/compiler/integers/u8/operator_methods.out +++ b/tests/expectations/compiler/integers/u8/operator_methods.out @@ -2,10 +2,10 @@ namespace: Compile expectation: Pass outputs: - - initial_ast: 49eceb52e53590ba231a2ca416034c6f3718b1bfe3f67ca41b973e7323efaf02 - unrolled_ast: 49eceb52e53590ba231a2ca416034c6f3718b1bfe3f67ca41b973e7323efaf02 - ssa_ast: e52370740422e008eec0e2630211063995fa07851929a81afe3e68de6c8052de - flattened_ast: 67c260a2ee07c5087249d064140ed1b0bcadee108e8165795d119431a52c601f - inlined_ast: 67c260a2ee07c5087249d064140ed1b0bcadee108e8165795d119431a52c601f + - initial_ast: 2bb0ee8a11f2883241c5ecd1fe800ed428f6c7760a7928f161133ba8870d043f + unrolled_ast: 2bb0ee8a11f2883241c5ecd1fe800ed428f6c7760a7928f161133ba8870d043f + ssa_ast: b737349409c53b451cf8b881e9bce93ca32935bb3982479aefc26d410aca4d73 + flattened_ast: 3387bcf3c9c604cfe8c98946993e839501c4629b4eaa1ee12d47603b398ea4e0 + inlined_ast: 3387bcf3c9c604cfe8c98946993e839501c4629b4eaa1ee12d47603b398ea4e0 dce_ast: c0095a84d960acb0bd845de7e20902fc26f7b203e91b109e61cd0405cd26a0cc bytecode: bc96cd7d2338fc235857e720f458edaf870603cb91f763e2e82cff2be42df25c diff --git a/tests/expectations/parser/instruction/call_fail.out b/tests/expectations/parser/instruction/call_fail.out index b5085f6c49..c85937f874 100644 --- a/tests/expectations/parser/instruction/call_fail.out +++ b/tests/expectations/parser/instruction/call_fail.out @@ -2,4 +2,5 @@ namespace: ParseInstruction expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'expression', found '.'\n --> test:1:9\n |\n 1 | call foo.aleo r0 r1 into r2;\n | ^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | call foo bar baz into bax;\n | ^^^^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | call foo.aleo r0 r1 into r2;\n | ^^^^" diff --git a/tests/expectations/parser/instruction/cast_fail.out b/tests/expectations/parser/instruction/cast_fail.out index ab6de39da5..c8b28795e8 100644 --- a/tests/expectations/parser/instruction/cast_fail.out +++ b/tests/expectations/parser/instruction/cast_fail.out @@ -2,4 +2,5 @@ namespace: ParseInstruction expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'identifier', found ';'\n --> test:1:22\n |\n 1 | cast foo bar into baz;\n | ^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | cast foo bar baz bax.soup into fleeces as sheep;\n | ^^^^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | cast foo bar into baz;\n | ^^^^" diff --git a/tests/expectations/parser/instruction/decrement_fail.out b/tests/expectations/parser/instruction/decrement_fail.out index 2f11141eb8..58fdd5bbda 100644 --- a/tests/expectations/parser/instruction/decrement_fail.out +++ b/tests/expectations/parser/instruction/decrement_fail.out @@ -2,4 +2,5 @@ namespace: ParseInstruction expectation: Fail outputs: - - "Error [EPAR0370005]: expected [ -- found 'sender'\n --> test:1:20\n |\n 1 | decrement balances sender by 1u8;\n | ^^^^^^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | decrement balances[sender] by 1u8;\n | ^^^^^^^^^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | decrement balances sender by 1u8;\n | ^^^^^^^^^" diff --git a/tests/expectations/parser/instruction/increment_fail.out b/tests/expectations/parser/instruction/increment_fail.out index 0641bdff1e..0a707ba9d2 100644 --- a/tests/expectations/parser/instruction/increment_fail.out +++ b/tests/expectations/parser/instruction/increment_fail.out @@ -2,4 +2,5 @@ namespace: ParseInstruction expectation: Fail outputs: - - "Error [EPAR0370005]: expected [ -- found 'user'\n --> test:1:20\n |\n 1 | increment balances user by 1u8;\n | ^^^^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | increment balances[user] by 1u8;\n | ^^^^^^^^^" + - "Error [EPAR0370034]: Expected a valid opcode.\n --> test:1:1\n |\n 1 | increment balances user by 1u8;\n | ^^^^^^^^^" diff --git a/tests/expectations/parser/instruction/instruction.out b/tests/expectations/parser/instruction/instruction.out new file mode 100644 index 0000000000..138111b158 --- /dev/null +++ b/tests/expectations/parser/instruction/instruction.out @@ -0,0 +1,59 @@ +--- +namespace: ParseInstruction +expectation: Pass +outputs: + - opcode: Add + operands: + - Identifier: "{\"name\":\"r0\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":6}\"}" + - Identifier: "{\"name\":\"tree\",\"span\":\"{\\\"lo\\\":7,\\\"hi\\\":11}\"}" + destinations: + - "{\"name\":\"result\",\"span\":\"{\\\"lo\\\":17,\\\"hi\\\":23}\"}" + span: + lo: 0 + hi: 24 + - opcode: Add + operands: + - Identifier: "{\"name\":\"r0\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":6}\"}" + - Identifier: "{\"name\":\"r1\",\"span\":\"{\\\"lo\\\":7,\\\"hi\\\":9}\"}" + - Identifier: "{\"name\":\"r4\",\"span\":\"{\\\"lo\\\":10,\\\"hi\\\":12}\"}" + destinations: + - "{\"name\":\"r2\",\"span\":\"{\\\"lo\\\":18,\\\"hi\\\":20}\"}" + span: + lo: 0 + hi: 21 + - opcode: Ternary + operands: + - Identifier: "{\"name\":\"floo\",\"span\":\"{\\\"lo\\\":8,\\\"hi\\\":12}\"}" + - Identifier: "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":13,\\\"hi\\\":16}\"}" + - Identifier: "{\"name\":\"baz\",\"span\":\"{\\\"lo\\\":17,\\\"hi\\\":20}\"}" + destinations: + - "{\"name\":\"fax\",\"span\":\"{\\\"lo\\\":26,\\\"hi\\\":29}\"}" + span: + lo: 0 + hi: 30 + - opcode: Ternary + operands: + - Identifier: "{\"name\":\"r0\",\"span\":\"{\\\"lo\\\":8,\\\"hi\\\":10}\"}" + - Identifier: "{\"name\":\"r1\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":13}\"}" + destinations: + - "{\"name\":\"r2\",\"span\":\"{\\\"lo\\\":19,\\\"hi\\\":21}\"}" + span: + lo: 0 + hi: 22 + - opcode: Abs + operands: + - Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":7}\"}" + destinations: + - "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":13,\\\"hi\\\":16}\"}" + span: + lo: 0 + hi: 17 + - opcode: Abs + operands: + - Identifier: "{\"name\":\"foo\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":7}\"}" + - Identifier: "{\"name\":\"bax\",\"span\":\"{\\\"lo\\\":8,\\\"hi\\\":11}\"}" + destinations: + - "{\"name\":\"bar\",\"span\":\"{\\\"lo\\\":17,\\\"hi\\\":20}\"}" + span: + lo: 0 + hi: 21 diff --git a/tests/expectations/parser/unreachable/define.out b/tests/expectations/parser/unreachable/define.out index c9db5def6b..b4ffe3f7e0 100644 --- a/tests/expectations/parser/unreachable/define.out +++ b/tests/expectations/parser/unreachable/define.out @@ -25,7 +25,7 @@ outputs: - "Error [EPAR0370009]: unexpected string: expected 'expression', found '<='\n --> test:1:1\n |\n 1 | <= x = 10u8;\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'expression', found '>'\n --> test:1:1\n |\n 1 | > x = 10u8;\n | ^" - "Error [EPAR0370009]: unexpected string: expected 'expression', found '..'\n --> test:1:1\n |\n 1 | .. x = 10u8;\n | ^^" - - "Error [EPAR0370005]: expected ; -- found 'x'\n --> test:1:4\n |\n 1 | as x = 10u8;\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found 'as'\n --> test:1:1\n |\n 1 | as x = 10u8;\n | ^^" - "Error [EPAR0370032]: `console` statements are not yet supported.\n --> test:1:1\n |\n 1 | console x = 10u8;\n | ^^^^^^^\n |\n = Consider using `assert`, `assert_eq`, or `assert_neq` instead." - "Error [EPAR0370005]: expected : -- found '='\n --> test:1:7\n |\n 1 | for x = 10u8;\n | ^" - "Error [EPAR0370005]: expected { -- found '='\n --> test:1:6\n |\n 1 | if x = 10u8;\n | ^" diff --git a/tests/expectations/parser/unreachable/expect_ident.out b/tests/expectations/parser/unreachable/expect_ident.out index f14f2acbe1..0a5266ff93 100644 --- a/tests/expectations/parser/unreachable/expect_ident.out +++ b/tests/expectations/parser/unreachable/expect_ident.out @@ -30,7 +30,7 @@ outputs: - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '<='\n --> test:1:4\n |\n 1 | x::<=\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '>'\n --> test:1:4\n |\n 1 | x::>\n | ^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '..'\n --> test:1:4\n |\n 1 | x::..\n | ^^" - - "Error [EPAR0370005]: expected ; -- found ''\n --> test:1:4\n |\n 1 | x::as\n | ^^" + - "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'as'\n --> test:1:4\n |\n 1 | x::as\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'console'\n --> test:1:4\n |\n 1 | x::console\n | ^^^^^^^" - "Error [EPAR0370005]: expected ; -- found ''\n --> test:1:4\n |\n 1 | x::const\n | ^^^^^" - "Error [EPAR0370009]: unexpected string: expected 'identifier', found 'let'\n --> test:1:4\n |\n 1 | x::let\n | ^^^" diff --git a/tests/tests/compiler/assembly/assembly.leo b/tests/tests/compiler/assembly/assembly.leo new file mode 100644 index 0000000000..40a4443b60 --- /dev/null +++ b/tests/tests/compiler/assembly/assembly.leo @@ -0,0 +1,15 @@ +/* +namespace: Compile +expectation: Pass +*/ + +program test.aleo { + transition hello(a: u8, b: u8) -> u8 { + asm { + add a b into c; + add.w c c into d; + }; + let f: u8 = d + 1u8; + return f; + } +} \ No newline at end of file diff --git a/tests/tests/compiler/assembly/assembly_in_conditional_fail.leo b/tests/tests/compiler/assembly/assembly_in_conditional_fail.leo new file mode 100644 index 0000000000..dd3a2d20db --- /dev/null +++ b/tests/tests/compiler/assembly/assembly_in_conditional_fail.leo @@ -0,0 +1,18 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + transition hello(a: u8, b: u8) -> u8 { + if a == b { + asm { + add a b into c; + add.w c c into d; + } + return d; + } else { + return a + a; + } + } +} \ No newline at end of file diff --git a/tests/tests/compiler/assembly/assembly_in_inline_fail.leo b/tests/tests/compiler/assembly/assembly_in_inline_fail.leo new file mode 100644 index 0000000000..a90da5f5d5 --- /dev/null +++ b/tests/tests/compiler/assembly/assembly_in_inline_fail.leo @@ -0,0 +1,17 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + inline adder(a: u8, b: u8) -> u8 { + asm { + add a b into c; + } + return c; + } + + transition hello(a: u8, b: u8) -> u8 { + return adder(a, b); + } +} \ No newline at end of file diff --git a/tests/tests/compiler/assembly/assembly_in_loop_fail.leo b/tests/tests/compiler/assembly/assembly_in_loop_fail.leo new file mode 100644 index 0000000000..5a0eacd52f --- /dev/null +++ b/tests/tests/compiler/assembly/assembly_in_loop_fail.leo @@ -0,0 +1,18 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + transition main(x: u32) -> bool { + let y: u32 = x; + + for i: u32 in 0u32..3u32 { + asm { + sub y 1u32 into z; + } + y = z + z; + } + return y == 0u32; + } +} diff --git a/tests/tests/compiler/assembly/assembly_incorrect_number_of_operands_fail.leo b/tests/tests/compiler/assembly/assembly_incorrect_number_of_operands_fail.leo new file mode 100644 index 0000000000..21ffdda765 --- /dev/null +++ b/tests/tests/compiler/assembly/assembly_incorrect_number_of_operands_fail.leo @@ -0,0 +1,15 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + transition hello(a: u8, b: u8) -> u8 { + asm { + add a b a into c; + add.w c into d; + } + let f: u8 = d + 1u8; + return f; + } +} \ No newline at end of file diff --git a/tests/tests/compiler/assembly/assembly_incorrect_operand_types_fail.leo b/tests/tests/compiler/assembly/assembly_incorrect_operand_types_fail.leo new file mode 100644 index 0000000000..7e1b26b1a8 --- /dev/null +++ b/tests/tests/compiler/assembly/assembly_incorrect_operand_types_fail.leo @@ -0,0 +1,17 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + transition hello(a: u8, b: u8) -> u8 { + let foo: field = 1field; + let bar: u16 = 4u16; + asm { + add a foo into c; + add.w c bar into d; + } + let f: u8 = d + 1u8; + return f; + } +} \ No newline at end of file diff --git a/tests/tests/compiler/assembly/assembly_shadow_variable_fail.leo b/tests/tests/compiler/assembly/assembly_shadow_variable_fail.leo new file mode 100644 index 0000000000..606f19f3ee --- /dev/null +++ b/tests/tests/compiler/assembly/assembly_shadow_variable_fail.leo @@ -0,0 +1,13 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + transition hello(a: u8, b: u8) -> u8 { + asm { + add a b into a; + } + return a; + } +} \ No newline at end of file diff --git a/tests/tests/compiler/integers/i128/operator_methods.leo b/tests/tests/compiler/integers/i128/operator_methods.leo index 0753d34dde..5cb659ce3c 100644 --- a/tests/tests/compiler/integers/i128/operator_methods.leo +++ b/tests/tests/compiler/integers/i128/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i128 = a.shr_wrapped(2u16); let aq: i128 = a.shr_wrapped(2u32); let ar: i128 = a.xor(b); - let as: i128 = a.rem(b); - let at: i128 = a.rem_wrapped(b); + let at: i128 = a.rem(b); + let au: i128 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i16/operator_methods.leo b/tests/tests/compiler/integers/i16/operator_methods.leo index 21f9d09c93..99048b5da7 100644 --- a/tests/tests/compiler/integers/i16/operator_methods.leo +++ b/tests/tests/compiler/integers/i16/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i16 = a.shr_wrapped(2u16); let aq: i16 = a.shr_wrapped(2u32); let ar: i16 = a.xor(b); - let as: i16 = a.rem(b); - let at: i16 = a.rem_wrapped(b); + let at: i16 = a.rem(b); + let au: i16 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i32/operator_methods.leo b/tests/tests/compiler/integers/i32/operator_methods.leo index e9a81e2118..61a4bb456c 100644 --- a/tests/tests/compiler/integers/i32/operator_methods.leo +++ b/tests/tests/compiler/integers/i32/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i32 = a.shr_wrapped(2u16); let aq: i32 = a.shr_wrapped(2u32); let ar: i32 = a.xor(b); - let as: i32 = a.rem(b); - let at: i32 = a.rem_wrapped(b); + let at: i32 = a.rem(b); + let au: i32 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i64/operator_methods.leo b/tests/tests/compiler/integers/i64/operator_methods.leo index f7ee0f1419..342a00805d 100644 --- a/tests/tests/compiler/integers/i64/operator_methods.leo +++ b/tests/tests/compiler/integers/i64/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i64 = a.shr_wrapped(2u16); let aq: i64 = a.shr_wrapped(2u32); let ar: i64 = a.xor(b); - let as: i64 = a.rem(b); - let at: i64 = a.rem_wrapped(b); + let at: i64 = a.rem(b); + let au: i64 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/i8/operator_methods.leo b/tests/tests/compiler/integers/i8/operator_methods.leo index 37ec2f0ed5..5f35349478 100644 --- a/tests/tests/compiler/integers/i8/operator_methods.leo +++ b/tests/tests/compiler/integers/i8/operator_methods.leo @@ -45,8 +45,8 @@ program test.aleo { let ap: i8 = a.shr_wrapped(2u16); let aq: i8 = a.shr_wrapped(2u32); let ar: i8 = a.xor(b); - let as: i8 = a.rem(b); - let at: i8 = a.rem_wrapped(b); + let at: i8 = a.rem(b); + let au: i8 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u128/operator_methods.leo b/tests/tests/compiler/integers/u128/operator_methods.leo index cad091b769..eb703c47a3 100644 --- a/tests/tests/compiler/integers/u128/operator_methods.leo +++ b/tests/tests/compiler/integers/u128/operator_methods.leo @@ -42,9 +42,9 @@ program test.aleo { let ap: u128 = a.shr_wrapped(2u16); let aq: u128 = a.shr_wrapped(2u32); let ar: u128 = a.xor(b); - let as: u128 = a.mod(b); - let at: u128 = a.rem(b); - let au: u128 = a.rem_wrapped(b); + let at: u128 = a.mod(b); + let au: u128 = a.rem(b); + let av: u128 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u16/operator_methods.leo b/tests/tests/compiler/integers/u16/operator_methods.leo index d02892108c..796ca1edc5 100644 --- a/tests/tests/compiler/integers/u16/operator_methods.leo +++ b/tests/tests/compiler/integers/u16/operator_methods.leo @@ -43,9 +43,9 @@ program test.aleo { let ap: u16 = a.shr_wrapped(b); let aq: u16 = a.shr_wrapped(2u32); let ar: u16 = a.xor(b); - let as: u16 = a.mod(b); - let at: u16 = a.rem(b); - let au: u16 = a.rem_wrapped(b); + let at: u16 = a.mod(b); + let au: u16 = a.rem(b); + let av: u16 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u32/operator_methods.leo b/tests/tests/compiler/integers/u32/operator_methods.leo index 28144b7af9..a290585b69 100644 --- a/tests/tests/compiler/integers/u32/operator_methods.leo +++ b/tests/tests/compiler/integers/u32/operator_methods.leo @@ -43,9 +43,9 @@ program test.aleo { let ap: u32 = a.shr_wrapped(2u16); let aq: u32 = a.shr_wrapped(b); let ar: u32 = a.xor(b); - let as: u32 = a.mod(b); - let at: u32 = a.rem(b); - let au: u32 = a.rem_wrapped(b); + let at: u32 = a.mod(b); + let au: u32 = a.rem(b); + let av: u32 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u64/operator_methods.leo b/tests/tests/compiler/integers/u64/operator_methods.leo index cd2afcf66f..5915d5aac5 100644 --- a/tests/tests/compiler/integers/u64/operator_methods.leo +++ b/tests/tests/compiler/integers/u64/operator_methods.leo @@ -42,9 +42,9 @@ program test.aleo { let ap: u64 = a.shr_wrapped(2u16); let aq: u64 = a.shr_wrapped(2u32); let ar: u64 = a.xor(b); - let as: u64 = a.mod(b); - let at: u64 = a.rem(b); - let au: u64 = a.rem_wrapped(b); + let at: u64 = a.mod(b); + let au: u64 = a.rem(b); + let av: u64 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/compiler/integers/u8/operator_methods.leo b/tests/tests/compiler/integers/u8/operator_methods.leo index 84bf767816..a067b6487a 100644 --- a/tests/tests/compiler/integers/u8/operator_methods.leo +++ b/tests/tests/compiler/integers/u8/operator_methods.leo @@ -42,9 +42,9 @@ program test.aleo { let ap: u8 = a.shr_wrapped(2u16); let aq: u8 = a.shr_wrapped(2u32); let ar: u8 = a.xor(b); - let as: u8 = a.mod(b); - let at: u8 = a.rem(b); - let au: u8 = a.rem_wrapped(b); + let at: u8 = a.mod(b); + let au: u8 = a.rem(b); + let av: u8 = a.rem_wrapped(b); return a == b; }} diff --git a/tests/tests/parser/instruction/assembly_in_program_scope_fail.leo b/tests/tests/parser/instruction/assembly_in_program_scope_fail.leo new file mode 100644 index 0000000000..9d2c185c15 --- /dev/null +++ b/tests/tests/parser/instruction/assembly_in_program_scope_fail.leo @@ -0,0 +1,15 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + asm {} + + transition hello(a: u8, b: u8) -> u8 { + + let f: u8 = d + 1u8; + return f; + } + +} \ No newline at end of file diff --git a/tests/tests/parser/instruction/binary.leo b/tests/tests/parser/instruction/binary.leo deleted file mode 100644 index 14c444b6b5..0000000000 --- a/tests/tests/parser/instruction/binary.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -add r0 tree into result; \ No newline at end of file diff --git a/tests/tests/parser/instruction/binary_fail.leo b/tests/tests/parser/instruction/binary_fail.leo deleted file mode 100644 index 9a837b3eb0..0000000000 --- a/tests/tests/parser/instruction/binary_fail.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Fail -*/ - -add r0 r1 r4 into r2; \ No newline at end of file diff --git a/tests/tests/parser/instruction/call.leo b/tests/tests/parser/instruction/call.leo deleted file mode 100644 index 57a8699c8f..0000000000 --- a/tests/tests/parser/instruction/call.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -call foo bar baz into bax; \ No newline at end of file diff --git a/tests/tests/parser/instruction/call_fail.leo b/tests/tests/parser/instruction/call_fail.leo index 61bd68ab53..7f302a5ff7 100644 --- a/tests/tests/parser/instruction/call_fail.leo +++ b/tests/tests/parser/instruction/call_fail.leo @@ -3,4 +3,5 @@ namespace: ParseInstruction expectation: Fail */ +call foo bar baz into bax; call foo.aleo r0 r1 into r2; \ No newline at end of file diff --git a/tests/tests/parser/instruction/cast.leo b/tests/tests/parser/instruction/cast.leo deleted file mode 100644 index 4142950f97..0000000000 --- a/tests/tests/parser/instruction/cast.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -cast foo bar baz bax.soup into fleeces as sheep; \ No newline at end of file diff --git a/tests/tests/parser/instruction/cast_fail.leo b/tests/tests/parser/instruction/cast_fail.leo index b139549524..1efd4eb245 100644 --- a/tests/tests/parser/instruction/cast_fail.leo +++ b/tests/tests/parser/instruction/cast_fail.leo @@ -3,4 +3,5 @@ namespace: ParseInstruction expectation: Fail */ +cast foo bar baz bax.soup into fleeces as sheep; cast foo bar into baz; \ No newline at end of file diff --git a/tests/tests/parser/instruction/decrement.leo b/tests/tests/parser/instruction/decrement.leo deleted file mode 100644 index ae094e0c19..0000000000 --- a/tests/tests/parser/instruction/decrement.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -decrement balances[sender] by 1u8; \ No newline at end of file diff --git a/tests/tests/parser/instruction/decrement_fail.leo b/tests/tests/parser/instruction/decrement_fail.leo index 26e29deeb3..c663ae4915 100644 --- a/tests/tests/parser/instruction/decrement_fail.leo +++ b/tests/tests/parser/instruction/decrement_fail.leo @@ -3,4 +3,5 @@ namespace: ParseInstruction expectation: Fail */ +decrement balances[sender] by 1u8; decrement balances sender by 1u8; \ No newline at end of file diff --git a/tests/tests/parser/instruction/increment.leo b/tests/tests/parser/instruction/increment.leo deleted file mode 100644 index db78a2cfd8..0000000000 --- a/tests/tests/parser/instruction/increment.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -increment balances[user] by 1u8; \ No newline at end of file diff --git a/tests/tests/parser/instruction/increment_fail.leo b/tests/tests/parser/instruction/increment_fail.leo index 81eb96056b..e58732ef7c 100644 --- a/tests/tests/parser/instruction/increment_fail.leo +++ b/tests/tests/parser/instruction/increment_fail.leo @@ -3,4 +3,5 @@ namespace: ParseInstruction expectation: Fail */ +increment balances[user] by 1u8; increment balances user by 1u8; \ No newline at end of file diff --git a/tests/tests/parser/instruction/instruction.leo b/tests/tests/parser/instruction/instruction.leo new file mode 100644 index 0000000000..5ed7be2dd1 --- /dev/null +++ b/tests/tests/parser/instruction/instruction.leo @@ -0,0 +1,11 @@ +/* +namespace: ParseInstruction +expectation: Pass +*/ + +add r0 tree into result; +add r0 r1 r4 into r2; +ternary floo bar baz into fax; +ternary r0 r1 into r2; +abs foo into bar; +abs foo bax into bar; diff --git a/tests/tests/parser/instruction/ternary.leo b/tests/tests/parser/instruction/ternary.leo deleted file mode 100644 index 014c7da746..0000000000 --- a/tests/tests/parser/instruction/ternary.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -ternary floo bar baz into fax; \ No newline at end of file diff --git a/tests/tests/parser/instruction/ternary_fail.leo b/tests/tests/parser/instruction/ternary_fail.leo deleted file mode 100644 index c3e3f6a122..0000000000 --- a/tests/tests/parser/instruction/ternary_fail.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Fail -*/ - -ternary r0 r1 into r2; \ No newline at end of file diff --git a/tests/tests/parser/instruction/unary.leo b/tests/tests/parser/instruction/unary.leo deleted file mode 100644 index 67c8bfeeb4..0000000000 --- a/tests/tests/parser/instruction/unary.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Pass -*/ - -abs foo into bar; diff --git a/tests/tests/parser/instruction/unary_fail.leo b/tests/tests/parser/instruction/unary_fail.leo deleted file mode 100644 index ca96edc82a..0000000000 --- a/tests/tests/parser/instruction/unary_fail.leo +++ /dev/null @@ -1,6 +0,0 @@ -/* -namespace: ParseInstruction -expectation: Fail -*/ - -abs foo bax into bar; \ No newline at end of file