make tuple a ptr to a struct instead of a struct

This commit is contained in:
pca006132 2021-08-07 17:41:48 +08:00
parent 057fcfe3df
commit 1ffb792000
1 changed files with 14 additions and 1 deletions

View File

@ -95,7 +95,20 @@ impl<'ctx> CodeGenContext<'ctx> {
SymbolValue::Double(v) => self.ctx.f64_type().const_float(*v).into(), SymbolValue::Double(v) => self.ctx.f64_type().const_float(*v).into(),
SymbolValue::Tuple(ls) => { SymbolValue::Tuple(ls) => {
let vals = ls.iter().map(|v| self.gen_symbol_val(v)).collect_vec(); 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()
} }
} }
} }