make things compile

This commit is contained in:
Folkert 2021-06-24 20:31:14 +02:00
parent 2355bbf815
commit a05d8b52c0
3 changed files with 42 additions and 34 deletions

View file

@ -134,30 +134,18 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
) )
.into_pointer_value(); .into_pointer_value();
let input = env.builder.build_load(argument_cast, "get_value"); let tag_value = env.builder.build_load(argument_cast, "get_value");
let tag_value = crate::llvm::build::extract_tag_discriminant( let actual_tag_id = {
let tag_id_i64 = crate::llvm::build::extract_tag_discriminant(
env, env,
function_value, function_value,
union_layout, union_layout,
input, tag_value,
); );
let actual_tag_id =
env.builder env.builder
.build_int_cast(tag_value, env.context.i16_type(), "to_i16"); .build_int_cast(tag_id_i64, env.context.i16_type(), "to_i16")
let data_ptr = {
let index = env
.context
.i64_type()
.const_int(TAG_DATA_INDEX as u64, false);
let ptr = unsafe {
env.builder
.build_in_bounds_gep(argument_cast, &[index], "get_tag_id")
};
env.builder.build_bitcast(ptr, i8_ptr_type, "to_opaque")
}; };
let answer = env.builder.build_int_compare( let answer = env.builder.build_int_compare(
@ -167,7 +155,7 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
"compare", "compare",
); );
let field_vals = [(0, answer.into()), (1, data_ptr)]; let field_vals = [(0, answer.into()), (1, *tag_value_ptr)];
let output = struct_from_fields(env, output_type, field_vals.iter().copied()); let output = struct_from_fields(env, output_type, field_vals.iter().copied());

View file

@ -996,19 +996,10 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
// Create the struct_type // Create the struct_type
let struct_type = ctx.struct_type(field_types.into_bump_slice(), false); let struct_type = ctx.struct_type(field_types.into_bump_slice(), false);
let mut struct_val = struct_type.const_zero().into();
// Insert field exprs into struct_val // Insert field exprs into struct_val
for (index, field_val) in field_vals.into_iter().enumerate() { let struct_val =
struct_val = builder struct_from_fields(env, struct_type, field_vals.into_iter().enumerate());
.build_insert_value(
struct_val,
field_val,
index as u32,
"insert_multi_tag_field",
)
.unwrap();
}
// How we create tag values // How we create tag values
// //
@ -1036,7 +1027,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
let internal_type = basic_type_from_layout(env, &tag_layout); let internal_type = basic_type_from_layout(env, &tag_layout);
cast_tag_to_block_of_memory(builder, struct_val.into_struct_value(), internal_type) cast_tag_to_block_of_memory(builder, struct_val, internal_type)
} }
Tag { Tag {
arguments, arguments,
@ -1575,6 +1566,29 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
} }
} }
pub fn struct_from_fields<'a, 'ctx, 'env, I>(
env: &Env<'a, 'ctx, 'env>,
struct_type: StructType<'ctx>,
values: I,
) -> StructValue<'ctx>
where
I: Iterator<Item = (usize, BasicValueEnum<'ctx>)>,
{
let mut struct_value = struct_type.const_zero().into();
// Insert field exprs into struct_val
for (index, field_val) in values {
let index: u32 = index as u32;
struct_value = env
.builder
.build_insert_value(struct_value, field_val, index, "insert_record_field")
.unwrap();
}
struct_value.into_struct_value()
}
fn lookup_at_index_ptr<'a, 'ctx, 'env>( fn lookup_at_index_ptr<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
field_layouts: &[Layout<'_>], field_layouts: &[Layout<'_>],

View file

@ -180,3 +180,9 @@ pub fn zig_str_type<'a, 'ctx, 'env>(
) -> StructType<'ctx> { ) -> StructType<'ctx> {
env.module.get_struct_type("str.RocStr").unwrap() env.module.get_struct_type("str.RocStr").unwrap()
} }
pub fn zig_has_tag_id_type<'a, 'ctx, 'env>(
env: &crate::llvm::build::Env<'a, 'ctx, 'env>,
) -> StructType<'ctx> {
env.module.get_struct_type("list.HasTagId").unwrap()
}