List.mapWithIndex

This commit is contained in:
Folkert 2021-02-17 22:29:15 +01:00
parent 7bd228ca9b
commit 65ab08728a
11 changed files with 117 additions and 5 deletions

View file

@ -7,8 +7,8 @@ use crate::llvm::build_hash::generic_hash;
use crate::llvm::build_list::{
allocate_list, empty_list, empty_polymorphic_list, list_append, list_concat, list_contains,
list_get_unsafe, list_join, list_keep_errs, list_keep_if, list_keep_oks, list_len, list_map,
list_prepend, list_repeat, list_reverse, list_set, list_single, list_sum, list_walk,
list_walk_backwards,
list_map_with_index, list_prepend, list_repeat, list_reverse, list_set, list_single, list_sum,
list_walk, list_walk_backwards,
};
use crate::llvm::build_str::{
str_concat, str_count_graphemes, str_ends_with, str_from_float, str_from_int, str_join_with,
@ -3642,6 +3642,24 @@ fn run_low_level<'a, 'ctx, 'env>(
_ => unreachable!("invalid list layout"),
}
}
ListMapWithIndex => {
// List.map : List before, (before -> after) -> List after
debug_assert_eq!(args.len(), 2);
let (list, list_layout) = load_symbol_and_layout(scope, &args[0]);
let (func, func_layout) = load_symbol_and_layout(scope, &args[1]);
match list_layout {
Layout::Builtin(Builtin::EmptyList) => {
return empty_list(env);
}
Layout::Builtin(Builtin::List(_, element_layout)) => {
list_map_with_index(env, layout_ids, func, func_layout, list, element_layout)
}
_ => unreachable!("invalid list layout"),
}
}
ListKeepIf => {
// List.keepIf : List elem, (elem -> Bool) -> List elem
debug_assert_eq!(args.len(), 2);