From 1ffb7920000ebd4ebed1968cd4e86c834de00208 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 7 Aug 2021 17:41:48 +0800 Subject: [PATCH] make tuple a ptr to a struct instead of a struct --- 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 ccba23c97..ac37dcdd5 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -95,7 +95,20 @@ impl<'ctx> CodeGenContext<'ctx> { SymbolValue::Double(v) => self.ctx.f64_type().const_float(*v).into(), SymbolValue::Tuple(ls) => { let vals = ls.iter().map(|v| self.gen_symbol_val(v)).collect_vec(); - self.ctx.const_struct(&vals, false).into() + let fields = vals.iter().map(|v| v.get_type()).collect_vec(); + let ty = self.ctx.struct_type(&fields, false); + let ptr = self.builder.build_alloca(ty, "tuple"); + let zero = self.ctx.i32_type().const_zero(); + unsafe { + for (i, val) in vals.into_iter().enumerate() { + let p = ptr.const_in_bounds_gep(&[ + zero, + self.ctx.i32_type().const_int(i as u64, false), + ]); + self.builder.build_store(p, val); + } + } + ptr.into() } } }