Compare commits

...

3 Commits

Author SHA1 Message Date
David Mak 45a549fb01 WIP - Fix string-like format 2024-08-12 17:02:26 +08:00
David Mak 2707735274 WIP - Fix bool format 2024-08-12 16:56:43 +08:00
David Mak 42f8dab980 WIP - Fix expected type of Tuple 2024-08-12 16:48:08 +08:00
1 changed files with 21 additions and 16 deletions

View File

@ -805,6 +805,8 @@ fn polymorphic_print<'ctx>(
match &*ctx.unifier.get_ty_immutable(ty) {
TypeEnum::TTuple { ty, is_vararg_ctx: false } => {
debug_assert_eq!(ty.len() as u32, value.into_struct_value().count_fields());
fmt.push('(');
flush(ctx, generator, &mut fmt, &mut args);
@ -814,11 +816,9 @@ fn polymorphic_print<'ctx>(
.map(|(i, ty)| {
(
*ty,
ValueEnum::from(ctx.build_in_bounds_gep_and_load(
value.into_pointer_value(),
&[llvm_i32.const_int(i as u64, false)],
None,
)),
unsafe {
ValueEnum::from(value.into_struct_value().get_field_at_index_unchecked(i as u32))
},
)
})
.collect_vec();
@ -841,18 +841,18 @@ fn polymorphic_print<'ctx>(
fmt.push_str("%.*s");
let true_str = ctx.gen_string(generator, "True");
let true_data = unsafe { true_str.get_field_at_index_unchecked(0) }.into_pointer_value();
let true_len = unsafe { true_str.get_field_at_index_unchecked(1) }.into_int_value();
let false_str = ctx.gen_string(generator, "False");
let false_data = unsafe { false_str.get_field_at_index_unchecked(0) }.into_pointer_value();
let false_len = unsafe { false_str.get_field_at_index_unchecked(1) }.into_int_value();
args.push(
ctx.builder
.build_select(
generator.bool_to_i1(ctx, value.into_int_value()),
true_str,
false_str,
"",
)
.unwrap(),
);
let bool_val = generator.bool_to_i1(ctx, value.into_int_value());
args.extend([
ctx.builder.build_select(bool_val, true_len, false_len, "").unwrap(),
ctx.builder.build_select(bool_val, true_data, false_data, "").unwrap(),
]);
}
TypeEnum::TObj { obj_id, .. }
@ -888,7 +888,12 @@ fn polymorphic_print<'ctx>(
} else {
fmt.push_str("%.*s");
}
args.push(value);
let str = value.into_struct_value();
let str_data = unsafe { str.get_field_at_index_unchecked(0) }.into_pointer_value();
let str_len = unsafe { str.get_field_at_index_unchecked(1) }.into_int_value();
args.extend(&[str_len.into(), str_data.into()]);
}
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PrimDef::List.id() => {