From 8d7e300a4a1c03d243038a2ec78cac2ce794e2aa Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sun, 27 Mar 2022 10:13:17 +0800 Subject: [PATCH] nac3core: do not use const struct for tuple --- nac3core/src/codegen/expr.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 9657dad0..78985301 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -1020,7 +1020,20 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>( .map_or_else(Err, |v| v.unwrap().to_basic_value_enum(ctx, generator)) }) .collect::, _>>()?; - ctx.ctx.const_struct(&element_val, false).into() + let element_ty = element_val.iter().map(BasicValueEnum::get_type).collect_vec(); + let tuple_ty = ctx.ctx.struct_type(&element_ty, false); + let tuple_ptr = ctx.builder.build_alloca(tuple_ty, "tuple"); + for (i, v) in element_val.into_iter().enumerate() { + unsafe { + let ptr = ctx.builder.build_in_bounds_gep( + tuple_ptr, + &[zero, int32.const_int(i as u64, false)], + "ptr", + ); + ctx.builder.build_store(ptr, v); + } + } + ctx.builder.build_load(tuple_ptr, "tup_val").into() } ExprKind::Attribute { value, attr, .. } => { // note that we would handle class methods directly in calls