mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Set up many basic details for Str.split- no implementation yet
This commit is contained in:
parent
7aada6c485
commit
943925e4de
5 changed files with 47 additions and 2 deletions
|
@ -4,7 +4,7 @@ use crate::llvm::build_list::{
|
||||||
list_join, list_keep_if, list_len, list_map, list_prepend, list_repeat, list_reverse, list_set,
|
list_join, list_keep_if, list_len, list_map, list_prepend, list_repeat, list_reverse, list_set,
|
||||||
list_single, list_walk_right,
|
list_single, list_walk_right,
|
||||||
};
|
};
|
||||||
use crate::llvm::build_str::{str_concat, str_len, CHAR_LAYOUT};
|
use crate::llvm::build_str::{str_concat, str_len, str_split, CHAR_LAYOUT};
|
||||||
use crate::llvm::compare::{build_eq, build_neq};
|
use crate::llvm::compare::{build_eq, build_neq};
|
||||||
use crate::llvm::convert::{
|
use crate::llvm::convert::{
|
||||||
basic_type_from_layout, block_of_memory, collection, get_fn_type, get_ptr_type, ptr_int,
|
basic_type_from_layout, block_of_memory, collection, get_fn_type, get_ptr_type, ptr_int,
|
||||||
|
@ -1809,6 +1809,12 @@ fn run_low_level<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
str_concat(env, inplace, scope, parent, args[0], args[1])
|
str_concat(env, inplace, scope, parent, args[0], args[1])
|
||||||
}
|
}
|
||||||
|
StrSplit => {
|
||||||
|
// Str.split : Str, Str -> List Str
|
||||||
|
debug_assert_eq!(args.len(), 2);
|
||||||
|
|
||||||
|
str_split(env, scope, parent, args[0], args[1])
|
||||||
|
}
|
||||||
StrIsEmpty => {
|
StrIsEmpty => {
|
||||||
// Str.isEmpty : Str -> Str
|
// Str.isEmpty : Str -> Str
|
||||||
debug_assert_eq!(args.len(), 1);
|
debug_assert_eq!(args.len(), 1);
|
||||||
|
|
|
@ -12,6 +12,43 @@ use roc_mono::layout::{Builtin, Layout};
|
||||||
|
|
||||||
pub static CHAR_LAYOUT: Layout = Layout::Builtin(Builtin::Int8);
|
pub static CHAR_LAYOUT: Layout = Layout::Builtin(Builtin::Int8);
|
||||||
|
|
||||||
|
/// Str.split : Str, Str -> List Str
|
||||||
|
pub fn str_split<'a, 'ctx, 'env>(
|
||||||
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
|
scope: &Scope<'a, 'ctx>,
|
||||||
|
parent: FunctionValue<'ctx>,
|
||||||
|
str_symbol: Symbol,
|
||||||
|
delimiter_symbol: Symbol,
|
||||||
|
) -> BasicValueEnum<'ctx> {
|
||||||
|
let builder = env.builder;
|
||||||
|
let ctx = env.context;
|
||||||
|
|
||||||
|
let str_ptr = ptr_from_symbol(scope, str_symbol);
|
||||||
|
let delimiter_ptr = ptr_from_symbol(scope, delimiter_symbol);
|
||||||
|
|
||||||
|
let str_wrapper_type = BasicTypeEnum::StructType(collection(ctx, env.ptr_bytes));
|
||||||
|
|
||||||
|
load_str(
|
||||||
|
env,
|
||||||
|
parent,
|
||||||
|
*str_ptr,
|
||||||
|
str_wrapper_type,
|
||||||
|
|_, str_len, str_smallness| {
|
||||||
|
load_str(
|
||||||
|
env,
|
||||||
|
parent,
|
||||||
|
*delimiter_ptr,
|
||||||
|
|_, delimiter_len, delimiter_smallness| {
|
||||||
|
let ret_list_len_alloca =
|
||||||
|
builder.build_alloca(ctx.i64_type(), "ret_list_len_alloca");
|
||||||
|
|
||||||
|
builder.build_store(ret_list_len_alloca, ctx.i64_type().const_zero());
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Str.concat : Str, Str -> Str
|
/// Str.concat : Str, Str -> Str
|
||||||
pub fn str_concat<'a, 'ctx, 'env>(
|
pub fn str_concat<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
pub enum LowLevel {
|
pub enum LowLevel {
|
||||||
StrConcat,
|
StrConcat,
|
||||||
StrIsEmpty,
|
StrIsEmpty,
|
||||||
|
StrSplit,
|
||||||
ListLen,
|
ListLen,
|
||||||
ListGetUnsafe,
|
ListGetUnsafe,
|
||||||
ListSet,
|
ListSet,
|
||||||
|
|
|
@ -660,6 +660,7 @@ define_builtins! {
|
||||||
2 STR_IS_EMPTY: "isEmpty"
|
2 STR_IS_EMPTY: "isEmpty"
|
||||||
3 STR_APPEND: "append"
|
3 STR_APPEND: "append"
|
||||||
4 STR_CONCAT: "concat"
|
4 STR_CONCAT: "concat"
|
||||||
|
5 STR_SPLIT: "split"
|
||||||
}
|
}
|
||||||
4 LIST: "List" => {
|
4 LIST: "List" => {
|
||||||
0 LIST_LIST: "List" imported // the List.List type alias
|
0 LIST_LIST: "List" imported // the List.List type alias
|
||||||
|
|
|
@ -510,7 +510,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
||||||
ListSetInPlace => arena.alloc_slice_copy(&[owned, irrelevant, irrelevant]),
|
ListSetInPlace => arena.alloc_slice_copy(&[owned, irrelevant, irrelevant]),
|
||||||
ListGetUnsafe => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
ListGetUnsafe => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
||||||
ListConcat | StrConcat => arena.alloc_slice_copy(&[owned, borrowed]),
|
ListConcat | StrConcat => arena.alloc_slice_copy(&[owned, borrowed]),
|
||||||
|
StrSplit => arena.alloc_slice_copy(&[borrowed, borrowed]),
|
||||||
ListSingle => arena.alloc_slice_copy(&[irrelevant]),
|
ListSingle => arena.alloc_slice_copy(&[irrelevant]),
|
||||||
ListRepeat => arena.alloc_slice_copy(&[irrelevant, irrelevant]),
|
ListRepeat => arena.alloc_slice_copy(&[irrelevant, irrelevant]),
|
||||||
ListReverse => arena.alloc_slice_copy(&[owned]),
|
ListReverse => arena.alloc_slice_copy(&[owned]),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue