mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
List.mapWithIndex
This commit is contained in:
parent
7bd228ca9b
commit
65ab08728a
11 changed files with 117 additions and 5 deletions
|
@ -1169,6 +1169,49 @@ pub fn list_map<'a, 'ctx, 'env>(
|
|||
transform_layout: &Layout<'a>,
|
||||
list: BasicValueEnum<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
list_map_generic(
|
||||
env,
|
||||
layout_ids,
|
||||
transform,
|
||||
transform_layout,
|
||||
list,
|
||||
element_layout,
|
||||
bitcode::LIST_MAP,
|
||||
&[element_layout.clone()],
|
||||
)
|
||||
}
|
||||
|
||||
/// List.mapWithIndex : List before, (Nat, before -> after) -> List after
|
||||
pub fn list_map_with_index<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
transform: BasicValueEnum<'ctx>,
|
||||
transform_layout: &Layout<'a>,
|
||||
list: BasicValueEnum<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
list_map_generic(
|
||||
env,
|
||||
layout_ids,
|
||||
transform,
|
||||
transform_layout,
|
||||
list,
|
||||
element_layout,
|
||||
bitcode::LIST_MAP_WITH_INDEX,
|
||||
&[Layout::Builtin(Builtin::Usize), element_layout.clone()],
|
||||
)
|
||||
}
|
||||
|
||||
fn list_map_generic<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
transform: BasicValueEnum<'ctx>,
|
||||
transform_layout: &Layout<'a>,
|
||||
list: BasicValueEnum<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
op: &str,
|
||||
argument_layouts: &[Layout<'a>],
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let builder = env.builder;
|
||||
|
||||
|
@ -1186,7 +1229,7 @@ pub fn list_map<'a, 'ctx, 'env>(
|
|||
env.builder.build_store(transform_ptr, transform);
|
||||
|
||||
let stepper_caller =
|
||||
build_transform_caller(env, layout_ids, transform_layout, &[element_layout.clone()])
|
||||
build_transform_caller(env, layout_ids, transform_layout, argument_layouts)
|
||||
.as_global_value()
|
||||
.as_pointer_value();
|
||||
|
||||
|
@ -1212,7 +1255,7 @@ pub fn list_map<'a, 'ctx, 'env>(
|
|||
old_element_width.into(),
|
||||
new_element_width.into(),
|
||||
],
|
||||
&bitcode::LIST_MAP,
|
||||
op,
|
||||
);
|
||||
|
||||
complex_bitcast(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue