mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
change representation of list/str
This commit is contained in:
parent
52772df2c3
commit
8013af7e97
6 changed files with 45 additions and 65 deletions
|
@ -60,17 +60,20 @@ pub fn str_split<'a, 'ctx, 'env>(
|
|||
let ret_list_ptr =
|
||||
allocate_list(env, inplace, &Layout::Builtin(Builtin::Str), segment_count);
|
||||
|
||||
// convert `*mut RocStr` to `*mut i128`
|
||||
let ret_list_ptr_u128s = builder.build_bitcast(
|
||||
// get the RocStr type defined by zig
|
||||
let roc_str_type = env.module.get_struct_type("str.RocStr").unwrap();
|
||||
|
||||
// convert `*mut { *mut u8, i64 }` to `*mut RocStr`
|
||||
let ret_list_ptr_zig_rocstr = builder.build_bitcast(
|
||||
ret_list_ptr,
|
||||
ctx.i128_type().ptr_type(AddressSpace::Generic),
|
||||
"ret_u128_list",
|
||||
roc_str_type.ptr_type(AddressSpace::Generic),
|
||||
"convert_to_zig_rocstr",
|
||||
);
|
||||
|
||||
call_void_bitcode_fn(
|
||||
env,
|
||||
&[
|
||||
ret_list_ptr_u128s,
|
||||
ret_list_ptr_zig_rocstr,
|
||||
BasicValueEnum::IntValue(segment_count),
|
||||
BasicValueEnum::PointerValue(str_bytes_ptr),
|
||||
BasicValueEnum::IntValue(str_len),
|
||||
|
@ -533,7 +536,6 @@ fn clone_nonempty_str<'a, 'ctx, 'env>(
|
|||
Smallness::Big => {
|
||||
let clone_ptr = allocate_list(env, inplace, &CHAR_LAYOUT, len);
|
||||
let int_type = ptr_int(ctx, ptr_bytes);
|
||||
let ptr_as_int = builder.build_ptr_to_int(clone_ptr, int_type, "list_cast_ptr");
|
||||
|
||||
// TODO check if malloc returned null; if so, runtime error for OOM!
|
||||
|
||||
|
@ -551,7 +553,7 @@ fn clone_nonempty_str<'a, 'ctx, 'env>(
|
|||
struct_val = builder
|
||||
.build_insert_value(
|
||||
struct_type.get_undef(),
|
||||
ptr_as_int,
|
||||
clone_ptr,
|
||||
Builtin::WRAPPER_PTR,
|
||||
"insert_ptr",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue