mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-13 08:47:17 +03:00
wip tuples
This commit is contained in:
parent
4963a11ee7
commit
c651da0581
@ -198,11 +198,17 @@ fn compile_and_process<'a>(parsed: &'a mut Compiler<'a>, handler: &Handler) -> R
|
||||
let st = parsed.loop_unrolling_pass(st)?;
|
||||
let assigner = parsed.static_single_assignment_pass(&st)?;
|
||||
|
||||
println!("Before ssa:\n{:?}", parsed.ast);
|
||||
|
||||
parsed.flattening_pass(&st, assigner)?;
|
||||
|
||||
println!("Before codegen:\n{:?}", parsed.ast);
|
||||
|
||||
// Compile Leo program to bytecode.
|
||||
let bytecode = CodeGenerator::do_pass((&parsed.ast, handler))?;
|
||||
|
||||
println!("After codegen:\n{:?}", bytecode);
|
||||
|
||||
Ok(bytecode)
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,12 @@ impl ParserContext<'_> {
|
||||
Ok((Type::Identifier(ident), ident.span))
|
||||
} else if self.token.token == Token::LeftParen {
|
||||
let (types, _, span) = self.parse_paren_comma_list(|p| p.parse_type().map(Some))?;
|
||||
|
||||
Ok((Type::Tuple(Tuple(types.into_iter().map(|t| t.0).collect())), span))
|
||||
match types.len() {
|
||||
// If the parenthetical block is empty, e.g. `()` or `( )`, it should be parsed into `Unit` types.
|
||||
0 => Ok((Type::Unit, span)),
|
||||
// Otherwise, parse it into a `Tuple` type.
|
||||
_ => Ok((Type::Tuple(Tuple(types.into_iter().map(|t| t.0).collect())), span)),
|
||||
}
|
||||
} else {
|
||||
self.parse_primitive_type()
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ impl<'a> CodeGenerator<'a> {
|
||||
}
|
||||
|
||||
fn visit_identifier(&mut self, input: &'a Identifier) -> (String, String) {
|
||||
println!("Codegen|visit_identifier|input: {:?}", input);
|
||||
(self.variable_mapping.get(&input.name).unwrap().clone(), String::new())
|
||||
}
|
||||
|
||||
|
@ -380,11 +380,13 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
|
||||
self.has_return = true;
|
||||
|
||||
// Check that the return expression is not a tuple.
|
||||
if matches!(&input.expression, Expression::Tuple(_)) {
|
||||
self.emit_err(TypeCheckerError::finalize_statement_cannot_contain_tuples(
|
||||
input.expression.span(),
|
||||
))
|
||||
// Check that the return expression is not a nested tuple.
|
||||
if let Expression::Tuple(TupleExpression { elements, .. }) = &input.expression {
|
||||
for element in elements {
|
||||
if matches!(element, Expression::Tuple(_)) {
|
||||
self.emit_err(TypeCheckerError::nested_tuple_expression(element.span()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.visit_expression(&input.expression, return_type);
|
||||
|
@ -1,10 +0,0 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
@program
|
||||
function baz(a: (u8, u16)) -> u8 {
|
||||
a = (3u8, 4u16);
|
||||
return 1u8 + 1u8;
|
||||
}
|
12
tests/compiler/tuple/tuple_in_assignment_fail.leo
Normal file
12
tests/compiler/tuple/tuple_in_assignment_fail.leo
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
transition baz(a: (u8, u16)) -> u8 {
|
||||
a = (3u8, 4u16);
|
||||
return 1u8 + 1u8;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
circuit A {
|
||||
mem: (u8, u16)
|
||||
}
|
||||
|
||||
circuit B {
|
||||
mems: (A, A)
|
||||
}
|
||||
|
||||
circuit Token {
|
||||
owner: address,
|
||||
gates: u64,
|
||||
amounts: (u64, u64),
|
||||
}
|
21
tests/compiler/tuple/tuple_in_struct.leo
Normal file
21
tests/compiler/tuple/tuple_in_struct.leo
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
circuit A {
|
||||
mem: (u8, u16)
|
||||
}
|
||||
|
||||
circuit B {
|
||||
mems: (A, A)
|
||||
}
|
||||
|
||||
circuit Token {
|
||||
owner: address,
|
||||
gates: u64,
|
||||
amounts: (u64, u64),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user