neo_solidity/ir/expressions/dispatch/
tuple.rs1fn try_lower_expression_tuple(
2 expr: &Expression,
3 ctx: &mut LoweringContext,
4 instructions: &mut Vec<Instruction>,
5) -> Option<bool> {
6 match expr {
7 Expression::List(_, params) => {
8 let element_count = params.len();
10 let element_type = ValueType::Any;
11
12 let array_local = ctx.allocate_local(
13 "__tuple_literal".to_string(),
14 Some(ValueType::Array(Box::new(element_type.clone()))),
15 );
16
17 instructions.push(Instruction::PushLiteral(LiteralValue::Integer(
18 BigInt::from(element_count),
19 )));
20 instructions.push(Instruction::NewArray { element_type });
21 instructions.push(Instruction::StoreLocal(array_local));
22
23 for (index, (_, param)) in params.iter().enumerate() {
24 instructions.push(Instruction::LoadLocal(array_local));
25 instructions.push(Instruction::PushLiteral(LiteralValue::Integer(
26 BigInt::from(index as u64),
27 )));
28
29 if let Some(parameter) = param {
30 if !lower_expression(¶meter.ty, ctx, instructions) {
31 instructions.push(Instruction::PushLiteral(LiteralValue::Integer(
32 BigInt::zero(),
33 )));
34 }
35 } else {
36 instructions.push(Instruction::PushLiteral(LiteralValue::Integer(
37 BigInt::zero(),
38 )));
39 }
40
41 instructions.push(Instruction::ArraySet);
42 }
43
44 instructions.push(Instruction::LoadLocal(array_local));
45 Some(true)
46 }
47 _ => None,
48 }
49}