mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
WIP on Str.split
This commit is contained in:
parent
7ecdf5ca35
commit
bf81e67a89
2 changed files with 26 additions and 18 deletions
|
@ -1393,17 +1393,12 @@ where
|
|||
|
||||
// This helper simulates a basic for loop, where
|
||||
// and index increments up from 0 to some end value
|
||||
fn incrementing_index_loop<'ctx, LoopFn>(
|
||||
pub fn incrementing_index_loop<'ctx, LoopFn>(
|
||||
builder: &Builder<'ctx>,
|
||||
ctx: &'ctx Context,
|
||||
parent: FunctionValue<'ctx>,
|
||||
end: IntValue<'ctx>,
|
||||
index_name: &str,
|
||||
// allocating memory for an index is costly, so sometimes
|
||||
// we want to reuse an index if multiple loops happen in a
|
||||
// series, such as the case in List.concat. A memory
|
||||
// allocation cab be passed in to be used, and the memory
|
||||
// allocation that _is_ used is the return value.
|
||||
mut loop_fn: LoopFn,
|
||||
) -> PointerValue<'ctx>
|
||||
where
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::llvm::build::{
|
|||
call_bitcode_fn, load_symbol, load_symbol_and_layout, ptr_from_symbol, Env, InPlace, Scope,
|
||||
};
|
||||
use crate::llvm::build_list::{
|
||||
allocate_list, build_basic_phi2, empty_list, incrementing_elem_loop, list_single,
|
||||
load_list_ptr, store_list,
|
||||
allocate_list, build_basic_phi2, empty_list, incrementing_elem_loop, incrementing_index_loop,
|
||||
list_single, load_list_ptr, store_list,
|
||||
};
|
||||
use crate::llvm::convert::{collection, ptr_int};
|
||||
use inkwell::builder::Builder;
|
||||
|
@ -51,18 +51,31 @@ pub fn str_split<'a, 'ctx, 'env>(
|
|||
|
||||
let str: BasicValueEnum<'ctx> = panic!("Get str basic value enum");
|
||||
let delimiter: BasicValueEnum<'ctx> = panic!("Get delimiter basic value enum");
|
||||
git
|
||||
let delimiter_count =
|
||||
call_bitcode_fn(env, &[str, delimiter], "count_delimiters_");
|
||||
|
||||
build_basic_phi2(
|
||||
env,
|
||||
let delimiter_count =
|
||||
call_bitcode_fn(env, &[str, delimiter], "count_delimiters_")
|
||||
.into_int_value();
|
||||
|
||||
let ret_list_len = builder.build_int_add(
|
||||
delimiter_count,
|
||||
ctx.i64_type().const_int(1, false),
|
||||
"ret_str_split_list_Len",
|
||||
);
|
||||
|
||||
let ret_list_ptr = allocate_list(env, inplace, &CHAR_LAYOUT, ret_list_len);
|
||||
|
||||
let ret_list_loop = |index| {};
|
||||
|
||||
incrementing_index_loop(
|
||||
builder,
|
||||
ctx,
|
||||
parent,
|
||||
delimiter_is_longer_comparison,
|
||||
if_delimiter_is_longer,
|
||||
if_delimiter_is_shorter,
|
||||
str_wrapper_type,
|
||||
)
|
||||
ret_list_len,
|
||||
"str_split_ret_list_len_index",
|
||||
ret_list_loop,
|
||||
);
|
||||
|
||||
empty_list(env)
|
||||
},
|
||||
)
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue