This commit is contained in:
pca006132 2021-09-21 11:29:51 +08:00
parent 20905a9b67
commit df6c9c8a35
1 changed files with 6 additions and 5 deletions

View File

@ -126,14 +126,15 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
fun_id = Some(*id); fun_id = Some(*id);
} }
} }
let fun_id = fun_id.unwrap();
let ty = self.get_llvm_type(fun.0.ret).into_pointer_type(); let ty = self.get_llvm_type(fun.0.ret).into_pointer_type();
let zelf_ty: BasicTypeEnum = ty.get_element_type().try_into().unwrap(); let zelf_ty: BasicTypeEnum = ty.get_element_type().try_into().unwrap();
let zelf = self.builder.build_alloca(zelf_ty, "alloca").into(); let zelf = self.builder.build_alloca(zelf_ty, "alloca").into();
// call `__init__` if there is one
if let Some(fun_id) = fun_id {
let mut sign = fun.0.clone(); let mut sign = fun.0.clone();
sign.ret = self.primitives.none; sign.ret = self.primitives.none;
self.gen_call(Some((fun.0.ret, zelf)), (&sign, fun_id), params); self.gen_call(Some((fun.0.ret, zelf)), (&sign, fun_id), params);
}
return Some(zelf); return Some(zelf);
} }
} }