WIP on Str.split

This commit is contained in:
Chad Stearns 2020-10-18 21:12:08 -04:00
parent 7ecdf5ca35
commit bf81e67a89
2 changed files with 26 additions and 18 deletions

View file

@ -1393,17 +1393,12 @@ where
// This helper simulates a basic for loop, where // This helper simulates a basic for loop, where
// and index increments up from 0 to some end value // 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>, builder: &Builder<'ctx>,
ctx: &'ctx Context, ctx: &'ctx Context,
parent: FunctionValue<'ctx>, parent: FunctionValue<'ctx>,
end: IntValue<'ctx>, end: IntValue<'ctx>,
index_name: &str, 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, mut loop_fn: LoopFn,
) -> PointerValue<'ctx> ) -> PointerValue<'ctx>
where where

View file

@ -2,8 +2,8 @@ use crate::llvm::build::{
call_bitcode_fn, load_symbol, load_symbol_and_layout, ptr_from_symbol, Env, InPlace, Scope, call_bitcode_fn, load_symbol, load_symbol_and_layout, ptr_from_symbol, Env, InPlace, Scope,
}; };
use crate::llvm::build_list::{ use crate::llvm::build_list::{
allocate_list, build_basic_phi2, empty_list, incrementing_elem_loop, list_single, allocate_list, build_basic_phi2, empty_list, incrementing_elem_loop, incrementing_index_loop,
load_list_ptr, store_list, list_single, load_list_ptr, store_list,
}; };
use crate::llvm::convert::{collection, ptr_int}; use crate::llvm::convert::{collection, ptr_int};
use inkwell::builder::Builder; 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 str: BasicValueEnum<'ctx> = panic!("Get str basic value enum");
let delimiter: BasicValueEnum<'ctx> = panic!("Get delimiter 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( let delimiter_count =
env, 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, parent,
delimiter_is_longer_comparison, ret_list_len,
if_delimiter_is_longer, "str_split_ret_list_len_index",
if_delimiter_is_shorter, ret_list_loop,
str_wrapper_type, );
)
empty_list(env)
}, },
) )
}, },