Tuple Fix (#246) #247
|
@ -808,42 +808,7 @@ impl InnerResolver {
|
|||
|
||||
Ok(Some(global.as_pointer_value().into()))
|
||||
} else if ty_id == self.primitive_ids.tuple {
|
||||
let id_str = id.to_string();
|
||||
|
||||
if let Some(global) = ctx.module.get_global(&id_str) {
|
||||
return Ok(Some(global.as_pointer_value().into()));
|
||||
}
|
||||
|
||||
let elements: &PyTuple = obj.cast_as()?;
|
||||
let types: Result<Result<Vec<_>, _>, _> = elements
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, elem)| {
|
||||
self.get_obj_type(
|
||||
py,
|
||||
elem,
|
||||
&mut ctx.unifier,
|
||||
&ctx.top_level.definitions.read(),
|
||||
&ctx.primitives,
|
||||
)
|
||||
.map_err(|e| super::CompileError::new_err(format!("Error getting element {}: {}", i, e)))
|
||||
.map(|ty| ty.map(|ty| ctx.get_llvm_type(generator, ty)))
|
||||
})
|
||||
.collect();
|
||||
let types = types?.unwrap();
|
||||
let ty = ctx.ctx.struct_type(&types, false);
|
||||
|
||||
{
|
||||
if self.global_value_ids.read().contains_key(&id) {
|
||||
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
|
||||
ctx.module.add_global(ty, Some(AddressSpace::Generic), &id_str)
|
||||
});
|
||||
return Ok(Some(global.as_pointer_value().into()));
|
||||
} else {
|
||||
self.global_value_ids.write().insert(id, obj.into());
|
||||
}
|
||||
}
|
||||
|
||||
let val: Result<Option<Vec<_>>, _> =
|
||||
elements.iter().enumerate().map(|(i, elem)| self.get_obj_value(py, elem, ctx, generator).map_err(|e|
|
||||
super::CompileError::new_err(format!("Error getting element {}: {}", i, e)))).collect();
|
||||
|
|
|
@ -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::<Result<Vec<_>, _>>()?;
|
||||
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
|
||||
|
|
|
@ -74,6 +74,11 @@ pub extern "C" fn __nac3_personality(_state: u32, _exception_object: u32, _conte
|
|||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn __nac3_raise(_state: u32, _exception_object: u32, _context: u32) -> u32 {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn run() -> i32;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
@extern
|
||||
def output_int32_list(x: list[int32]):
|
||||
...
|
||||
|
||||
@extern
|
||||
def output_int32(x: int32):
|
||||
...
|
||||
|
||||
class A:
|
||||
a: int32
|
||||
b: bool
|
||||
def __init__(self, a: int32, b: bool):
|
||||
self.a = a
|
||||
self.b = b
|
||||
|
||||
def run() -> int32:
|
||||
data = [0, 1, 2, 3]
|
||||
|
||||
t = [(d, d + d) for d in data]
|
||||
for i in t:
|
||||
tt = (Some(i[1]), i[0])
|
||||
tl = ([i[0], i[1] + i[0]], i[1])
|
||||
output_int32(tt[0].unwrap())
|
||||
output_int32(tt[1])
|
||||
output_int32(tl[0][0])
|
||||
output_int32(tl[0][1])
|
||||
output_int32(tl[1])
|
||||
|
||||
return 0
|
Loading…
Reference in New Issue