mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Use struct parameter
This commit is contained in:
parent
379235fd7e
commit
08dba946e6
2 changed files with 44 additions and 22 deletions
|
@ -3,7 +3,7 @@ use crate::llvm::build_list::{
|
||||||
allocate_list, build_basic_phi2, clone_nonempty_list, empty_list, empty_polymorphic_list,
|
allocate_list, build_basic_phi2, clone_nonempty_list, empty_list, empty_polymorphic_list,
|
||||||
incrementing_elem_loop, list_append, list_concat, list_get_unsafe, list_is_not_empty,
|
incrementing_elem_loop, list_append, list_concat, list_get_unsafe, list_is_not_empty,
|
||||||
list_join, list_len, list_map, list_prepend, list_repeat, list_reverse, list_set, list_single,
|
list_join, list_len, list_map, list_prepend, list_repeat, list_reverse, list_set, list_single,
|
||||||
load_list_ptr, store_list,
|
load_list_ptr, store_list, LoopListArg,
|
||||||
};
|
};
|
||||||
use crate::llvm::compare::{build_eq, build_neq};
|
use crate::llvm::compare::{build_eq, build_neq};
|
||||||
use crate::llvm::convert::{
|
use crate::llvm::convert::{
|
||||||
|
@ -2021,8 +2021,10 @@ fn str_concat<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
first_str_ptr,
|
LoopListArg {
|
||||||
first_str_len,
|
ptr: first_str_ptr,
|
||||||
|
len: first_str_len,
|
||||||
|
},
|
||||||
index_name,
|
index_name,
|
||||||
None,
|
None,
|
||||||
first_loop,
|
first_loop,
|
||||||
|
@ -2061,8 +2063,10 @@ fn str_concat<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
second_str_ptr,
|
LoopListArg {
|
||||||
second_str_len,
|
ptr: second_str_ptr,
|
||||||
|
len: second_str_len,
|
||||||
|
},
|
||||||
index_name,
|
index_name,
|
||||||
Some(index_alloca),
|
Some(index_alloca),
|
||||||
second_loop,
|
second_loop,
|
||||||
|
|
|
@ -258,8 +258,10 @@ pub fn list_join<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
outer_list_ptr,
|
LoopListArg {
|
||||||
outer_list_len,
|
ptr: outer_list_ptr,
|
||||||
|
len: outer_list_len,
|
||||||
|
},
|
||||||
"#sum_index",
|
"#sum_index",
|
||||||
None,
|
None,
|
||||||
sum_loop,
|
sum_loop,
|
||||||
|
@ -322,8 +324,10 @@ pub fn list_join<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
inner_list_ptr,
|
LoopListArg {
|
||||||
inner_list_len,
|
ptr: inner_list_ptr,
|
||||||
|
len: inner_list_len,
|
||||||
|
},
|
||||||
"#inner_index",
|
"#inner_index",
|
||||||
None,
|
None,
|
||||||
inner_elem_loop,
|
inner_elem_loop,
|
||||||
|
@ -337,8 +341,10 @@ pub fn list_join<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
outer_list_ptr,
|
LoopListArg {
|
||||||
outer_list_len,
|
ptr: outer_list_ptr,
|
||||||
|
len: outer_list_len,
|
||||||
|
},
|
||||||
"#inner_list_index",
|
"#inner_list_index",
|
||||||
None,
|
None,
|
||||||
inner_list_loop,
|
inner_list_loop,
|
||||||
|
@ -682,7 +688,13 @@ pub fn list_map<'a, 'ctx, 'env>(
|
||||||
};
|
};
|
||||||
|
|
||||||
incrementing_elem_loop(
|
incrementing_elem_loop(
|
||||||
builder, parent, ctx, list_ptr, len, "#index", None, list_loop,
|
builder,
|
||||||
|
parent,
|
||||||
|
ctx,
|
||||||
|
LoopListArg { ptr: list_ptr, len },
|
||||||
|
"#index",
|
||||||
|
None,
|
||||||
|
list_loop,
|
||||||
);
|
);
|
||||||
|
|
||||||
store_list(env, ret_list_ptr, len)
|
store_list(env, ret_list_ptr, len)
|
||||||
|
@ -813,8 +825,10 @@ pub fn list_concat<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
first_list_ptr,
|
LoopListArg {
|
||||||
first_list_len,
|
ptr: first_list_ptr,
|
||||||
|
len: first_list_len,
|
||||||
|
},
|
||||||
index_name,
|
index_name,
|
||||||
None,
|
None,
|
||||||
first_loop,
|
first_loop,
|
||||||
|
@ -857,8 +871,10 @@ pub fn list_concat<'a, 'ctx, 'env>(
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
second_list_ptr,
|
LoopListArg {
|
||||||
second_list_len,
|
ptr: second_list_ptr,
|
||||||
|
len: second_list_len,
|
||||||
|
},
|
||||||
index_name,
|
index_name,
|
||||||
Some(index_alloca),
|
Some(index_alloca),
|
||||||
second_loop,
|
second_loop,
|
||||||
|
@ -895,14 +911,16 @@ pub fn list_concat<'a, 'ctx, 'env>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This helper simulates a basic for loop, where
|
pub struct LoopListArg<'ctx> {
|
||||||
// and index increments up from 0 to some end value
|
pub ptr: PointerValue<'ctx>,
|
||||||
|
pub len: IntValue<'ctx>,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn incrementing_elem_loop<'ctx, LoopFn>(
|
pub fn incrementing_elem_loop<'ctx, LoopFn>(
|
||||||
builder: &Builder<'ctx>,
|
builder: &Builder<'ctx>,
|
||||||
parent: FunctionValue<'ctx>,
|
parent: FunctionValue<'ctx>,
|
||||||
ctx: &'ctx Context,
|
ctx: &'ctx Context,
|
||||||
list_ptr: PointerValue<'ctx>,
|
list: LoopListArg<'ctx>,
|
||||||
end: IntValue<'ctx>,
|
|
||||||
index_name: &str,
|
index_name: &str,
|
||||||
maybe_alloca: Option<PointerValue<'ctx>>,
|
maybe_alloca: Option<PointerValue<'ctx>>,
|
||||||
mut loop_fn: LoopFn,
|
mut loop_fn: LoopFn,
|
||||||
|
@ -914,12 +932,12 @@ where
|
||||||
builder,
|
builder,
|
||||||
parent,
|
parent,
|
||||||
ctx,
|
ctx,
|
||||||
end,
|
list.len,
|
||||||
index_name,
|
index_name,
|
||||||
maybe_alloca,
|
maybe_alloca,
|
||||||
|index| {
|
|index| {
|
||||||
// The pointer to the element in the list
|
// The pointer to the element in the list
|
||||||
let elem_ptr = unsafe { builder.build_in_bounds_gep(list_ptr, &[index], "load_index") };
|
let elem_ptr = unsafe { builder.build_in_bounds_gep(list.ptr, &[index], "load_index") };
|
||||||
|
|
||||||
let elem = builder.build_load(elem_ptr, "get_elem");
|
let elem = builder.build_load(elem_ptr, "get_elem");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue