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