use zig list/str type

This commit is contained in:
Folkert 2021-04-23 16:24:36 +02:00
parent 41c1878d8d
commit 2319b33794
5 changed files with 74 additions and 113 deletions

View file

@ -6,7 +6,7 @@ use crate::llvm::bitcode::{
use crate::llvm::build::{
allocate_with_refcount_help, cast_basic_basic, complex_bitcast, Env, InPlace,
};
use crate::llvm::convert::{basic_type_from_layout, collection, get_ptr_type};
use crate::llvm::convert::{basic_type_from_layout, get_ptr_type};
use crate::llvm::refcounting::{
increment_refcount_layout, refcount_is_one_comparison, PointerToRefcount,
};
@ -88,7 +88,7 @@ pub fn list_repeat<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -317,7 +317,7 @@ pub fn list_join<'a, 'ctx, 'env>(
let build_else = || empty_list(env);
let struct_type = collection(ctx, env.ptr_bytes);
let struct_type = super::convert::zig_list_type(env);
build_basic_phi2(
env,
@ -377,7 +377,7 @@ pub fn list_reverse<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -464,7 +464,7 @@ pub fn list_append<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -790,7 +790,7 @@ pub fn list_range<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -881,7 +881,7 @@ pub fn list_keep_if<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -998,7 +998,7 @@ pub fn list_keep_result<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -1044,7 +1044,7 @@ pub fn list_sort_with<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -1149,7 +1149,7 @@ fn list_map_generic<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -1236,7 +1236,7 @@ pub fn list_map2<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -1340,7 +1340,7 @@ pub fn list_map3<'a, 'ctx, 'env>(
complex_bitcast(
env.builder,
output,
collection(env.context, env.ptr_bytes).into(),
super::convert::zig_list_type(env).into(),
"from_i128",
)
}
@ -1405,7 +1405,7 @@ pub fn list_concat<'a, 'ctx, 'env>(
second_list_length_comparison,
build_second_list_then,
build_second_list_else,
BasicTypeEnum::StructType(collection(ctx, env.ptr_bytes)),
BasicTypeEnum::StructType(super::convert::zig_list_type(env)),
)
};
@ -1520,7 +1520,7 @@ pub fn list_concat<'a, 'ctx, 'env>(
second_list_length_comparison,
if_second_list_is_not_empty,
if_second_list_is_empty,
BasicTypeEnum::StructType(collection(ctx, env.ptr_bytes)),
BasicTypeEnum::StructType(super::convert::zig_list_type(env)),
)
};
@ -1530,7 +1530,7 @@ pub fn list_concat<'a, 'ctx, 'env>(
first_list_length_comparison,
if_first_list_is_not_empty,
if_first_list_is_empty,
BasicTypeEnum::StructType(collection(ctx, env.ptr_bytes)),
BasicTypeEnum::StructType(super::convert::zig_list_type(env)),
)
}
_ => {
@ -1732,9 +1732,7 @@ where
}
pub fn empty_polymorphic_list<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValueEnum<'ctx> {
let ctx = env.context;
let struct_type = collection(ctx, env.ptr_bytes);
let struct_type = super::convert::zig_list_type(env);
// The pointer should be null (aka zero) and the length should be zero,
// so the whole struct should be a const_zero
@ -1743,9 +1741,7 @@ pub fn empty_polymorphic_list<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> Basi
// TODO investigate: does this cause problems when the layout is known? this value is now not refcounted!
pub fn empty_list<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValueEnum<'ctx> {
let ctx = env.context;
let struct_type = collection(ctx, env.ptr_bytes);
let struct_type = super::convert::zig_list_type(env);
// The pointer should be null (aka zero) and the length should be zero,
// so the whole struct should be a const_zero
@ -1832,7 +1828,7 @@ pub fn clone_nonempty_list<'a, 'ctx, 'env>(
let u8_ptr_type = ctx.i8_type().ptr_type(AddressSpace::Generic);
let generic_ptr = cast_basic_basic(builder, clone_ptr.into(), u8_ptr_type.into());
let struct_type = collection(ctx, env.ptr_bytes);
let struct_type = super::convert::zig_list_type(env);
let mut struct_val;
// Store the pointer
@ -1853,7 +1849,7 @@ pub fn clone_nonempty_list<'a, 'ctx, 'env>(
let answer = builder
.build_bitcast(
struct_val.into_struct_value(),
collection(ctx, ptr_bytes),
super::convert::zig_list_type(env),
"cast_collection",
)
.into_struct_value();
@ -1924,8 +1920,7 @@ pub fn store_list<'a, 'ctx, 'env>(
let ctx = env.context;
let builder = env.builder;
let ptr_bytes = env.ptr_bytes;
let struct_type = collection(ctx, ptr_bytes);
let struct_type = super::convert::zig_list_type(env);
let u8_ptr_type = ctx.i8_type().ptr_type(AddressSpace::Generic);
let generic_ptr =
@ -1950,7 +1945,7 @@ pub fn store_list<'a, 'ctx, 'env>(
builder.build_bitcast(
struct_val.into_struct_value(),
collection(ctx, ptr_bytes),
super::convert::zig_list_type(env),
"cast_collection",
)
}