mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-12 23:06:18 +00:00
move List.map* into roc
This commit is contained in:
parent
7d8fbfbe85
commit
c734a27b59
16 changed files with 60 additions and 1445 deletions
|
@ -564,137 +564,6 @@ pub(crate) fn list_sort_with<'a, 'ctx>(
|
|||
)
|
||||
}
|
||||
|
||||
/// List.map : List before, (before -> after) -> List after
|
||||
pub(crate) fn list_map<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
layout_interner: &STLayoutInterner<'a>,
|
||||
roc_function_call: RocFunctionCall<'ctx>,
|
||||
list: BasicValueEnum<'ctx>,
|
||||
element_layout: InLayout<'a>,
|
||||
return_layout: InLayout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
call_list_bitcode_fn_1(
|
||||
env,
|
||||
list.into_struct_value(),
|
||||
&[
|
||||
roc_function_call.caller.into(),
|
||||
pass_as_opaque(env, roc_function_call.data),
|
||||
roc_function_call.inc_n_data.into(),
|
||||
roc_function_call.data_is_owned.into(),
|
||||
env.alignment_intvalue(layout_interner, return_layout),
|
||||
layout_width(env, layout_interner, element_layout),
|
||||
layout_width(env, layout_interner, return_layout),
|
||||
layout_refcounted(env, layout_interner, return_layout),
|
||||
],
|
||||
bitcode::LIST_MAP,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn list_map2<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
layout_interner: &STLayoutInterner<'a>,
|
||||
roc_function_call: RocFunctionCall<'ctx>,
|
||||
list1: BasicValueEnum<'ctx>,
|
||||
list2: BasicValueEnum<'ctx>,
|
||||
element1_layout: InLayout<'a>,
|
||||
element2_layout: InLayout<'a>,
|
||||
return_layout: InLayout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
call_list_bitcode_fn(
|
||||
env,
|
||||
&[list1.into_struct_value(), list2.into_struct_value()],
|
||||
&[
|
||||
roc_function_call.caller.into(),
|
||||
pass_as_opaque(env, roc_function_call.data),
|
||||
roc_function_call.inc_n_data.into(),
|
||||
roc_function_call.data_is_owned.into(),
|
||||
env.alignment_intvalue(layout_interner, return_layout),
|
||||
layout_width(env, layout_interner, element1_layout),
|
||||
layout_width(env, layout_interner, element2_layout),
|
||||
layout_width(env, layout_interner, return_layout),
|
||||
layout_refcounted(env, layout_interner, return_layout),
|
||||
],
|
||||
BitcodeReturns::List,
|
||||
bitcode::LIST_MAP2,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn list_map3<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
layout_interner: &STLayoutInterner<'a>,
|
||||
roc_function_call: RocFunctionCall<'ctx>,
|
||||
list1: BasicValueEnum<'ctx>,
|
||||
list2: BasicValueEnum<'ctx>,
|
||||
list3: BasicValueEnum<'ctx>,
|
||||
element1_layout: InLayout<'a>,
|
||||
element2_layout: InLayout<'a>,
|
||||
element3_layout: InLayout<'a>,
|
||||
result_layout: InLayout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
call_list_bitcode_fn(
|
||||
env,
|
||||
&[
|
||||
list1.into_struct_value(),
|
||||
list2.into_struct_value(),
|
||||
list3.into_struct_value(),
|
||||
],
|
||||
&[
|
||||
roc_function_call.caller.into(),
|
||||
pass_as_opaque(env, roc_function_call.data),
|
||||
roc_function_call.inc_n_data.into(),
|
||||
roc_function_call.data_is_owned.into(),
|
||||
env.alignment_intvalue(layout_interner, result_layout),
|
||||
layout_width(env, layout_interner, element1_layout),
|
||||
layout_width(env, layout_interner, element2_layout),
|
||||
layout_width(env, layout_interner, element3_layout),
|
||||
layout_width(env, layout_interner, result_layout),
|
||||
layout_refcounted(env, layout_interner, result_layout),
|
||||
],
|
||||
BitcodeReturns::List,
|
||||
bitcode::LIST_MAP3,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn list_map4<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
layout_interner: &STLayoutInterner<'a>,
|
||||
roc_function_call: RocFunctionCall<'ctx>,
|
||||
list1: BasicValueEnum<'ctx>,
|
||||
list2: BasicValueEnum<'ctx>,
|
||||
list3: BasicValueEnum<'ctx>,
|
||||
list4: BasicValueEnum<'ctx>,
|
||||
element1_layout: InLayout<'a>,
|
||||
element2_layout: InLayout<'a>,
|
||||
element3_layout: InLayout<'a>,
|
||||
element4_layout: InLayout<'a>,
|
||||
result_layout: InLayout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
call_list_bitcode_fn(
|
||||
env,
|
||||
&[
|
||||
list1.into_struct_value(),
|
||||
list2.into_struct_value(),
|
||||
list3.into_struct_value(),
|
||||
list4.into_struct_value(),
|
||||
],
|
||||
&[
|
||||
roc_function_call.caller.into(),
|
||||
pass_as_opaque(env, roc_function_call.data),
|
||||
roc_function_call.inc_n_data.into(),
|
||||
roc_function_call.data_is_owned.into(),
|
||||
env.alignment_intvalue(layout_interner, result_layout),
|
||||
layout_width(env, layout_interner, element1_layout),
|
||||
layout_width(env, layout_interner, element2_layout),
|
||||
layout_width(env, layout_interner, element3_layout),
|
||||
layout_width(env, layout_interner, element4_layout),
|
||||
layout_width(env, layout_interner, result_layout),
|
||||
layout_refcounted(env, layout_interner, result_layout),
|
||||
],
|
||||
BitcodeReturns::List,
|
||||
bitcode::LIST_MAP4,
|
||||
)
|
||||
}
|
||||
|
||||
/// List.concat : List elem, List elem -> List elem
|
||||
pub(crate) fn list_concat<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
|
|
|
@ -36,9 +36,9 @@ use crate::llvm::{
|
|||
},
|
||||
build_list::{
|
||||
list_append_unsafe, list_clone, list_concat, list_drop_at, list_get_unsafe, list_len_usize,
|
||||
list_map, list_map2, list_map3, list_map4, list_prepend, list_release_excess_capacity,
|
||||
list_replace_unsafe, list_reserve, list_sort_with, list_sublist, list_swap,
|
||||
list_symbol_to_c_abi, list_with_capacity, pass_update_mode,
|
||||
list_prepend, list_release_excess_capacity, list_replace_unsafe, list_reserve,
|
||||
list_sort_with, list_sublist, list_swap, list_symbol_to_c_abi, list_with_capacity,
|
||||
pass_update_mode,
|
||||
},
|
||||
compare::{generic_eq, generic_neq},
|
||||
convert::{
|
||||
|
@ -1306,7 +1306,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
ListMap | ListMap2 | ListMap3 | ListMap4 | ListSortWith => {
|
||||
ListSortWith => {
|
||||
unreachable!("these are higher order, and are handled elsewhere")
|
||||
}
|
||||
|
||||
|
@ -2772,7 +2772,7 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
|
|||
layout_interner: &STLayoutInterner<'a>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
return_layout: InLayout<'a>,
|
||||
_return_layout: InLayout<'a>,
|
||||
func_spec: FuncSpec,
|
||||
higher_order: &HigherOrderLowLevel<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
|
@ -2811,198 +2811,6 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
|
|||
}
|
||||
|
||||
match op {
|
||||
ListMap { xs } => {
|
||||
// List.map : List before, (before -> after) -> List after
|
||||
let (list, list_layout) = scope.load_symbol_and_layout(xs);
|
||||
|
||||
let (function, closure, closure_layout) = function_details!();
|
||||
|
||||
match (
|
||||
layout_interner.get_repr(list_layout),
|
||||
layout_interner.get_repr(return_layout),
|
||||
) {
|
||||
(
|
||||
LayoutRepr::Builtin(Builtin::List(element_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(result_layout)),
|
||||
) => {
|
||||
let argument_layouts = &[element_layout];
|
||||
|
||||
let roc_function_call = roc_function_call(
|
||||
env,
|
||||
layout_interner,
|
||||
layout_ids,
|
||||
function,
|
||||
closure,
|
||||
closure_layout,
|
||||
function_owns_closure_data,
|
||||
argument_layouts,
|
||||
result_layout,
|
||||
);
|
||||
|
||||
list_map(
|
||||
env,
|
||||
layout_interner,
|
||||
roc_function_call,
|
||||
list,
|
||||
element_layout,
|
||||
result_layout,
|
||||
)
|
||||
}
|
||||
_ => unreachable!("invalid list layout"),
|
||||
}
|
||||
}
|
||||
ListMap2 { xs, ys } => {
|
||||
let (list1, list1_layout) = scope.load_symbol_and_layout(xs);
|
||||
let (list2, list2_layout) = scope.load_symbol_and_layout(ys);
|
||||
|
||||
let (function, closure, closure_layout) = function_details!();
|
||||
|
||||
match (
|
||||
layout_interner.get_repr(list1_layout),
|
||||
layout_interner.get_repr(list2_layout),
|
||||
layout_interner.get_repr(return_layout),
|
||||
) {
|
||||
(
|
||||
LayoutRepr::Builtin(Builtin::List(element1_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(element2_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(result_layout)),
|
||||
) => {
|
||||
let argument_layouts = &[element1_layout, element2_layout];
|
||||
|
||||
let roc_function_call = roc_function_call(
|
||||
env,
|
||||
layout_interner,
|
||||
layout_ids,
|
||||
function,
|
||||
closure,
|
||||
closure_layout,
|
||||
function_owns_closure_data,
|
||||
argument_layouts,
|
||||
result_layout,
|
||||
);
|
||||
|
||||
list_map2(
|
||||
env,
|
||||
layout_interner,
|
||||
roc_function_call,
|
||||
list1,
|
||||
list2,
|
||||
element1_layout,
|
||||
element2_layout,
|
||||
result_layout,
|
||||
)
|
||||
}
|
||||
_ => unreachable!("invalid list layout"),
|
||||
}
|
||||
}
|
||||
ListMap3 { xs, ys, zs } => {
|
||||
let (list1, list1_layout) = scope.load_symbol_and_layout(xs);
|
||||
let (list2, list2_layout) = scope.load_symbol_and_layout(ys);
|
||||
let (list3, list3_layout) = scope.load_symbol_and_layout(zs);
|
||||
|
||||
let (function, closure, closure_layout) = function_details!();
|
||||
|
||||
match (
|
||||
layout_interner.get_repr(list1_layout),
|
||||
layout_interner.get_repr(list2_layout),
|
||||
layout_interner.get_repr(list3_layout),
|
||||
layout_interner.get_repr(return_layout),
|
||||
) {
|
||||
(
|
||||
LayoutRepr::Builtin(Builtin::List(element1_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(element2_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(element3_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(result_layout)),
|
||||
) => {
|
||||
let argument_layouts = &[element1_layout, element2_layout, element3_layout];
|
||||
|
||||
let roc_function_call = roc_function_call(
|
||||
env,
|
||||
layout_interner,
|
||||
layout_ids,
|
||||
function,
|
||||
closure,
|
||||
closure_layout,
|
||||
function_owns_closure_data,
|
||||
argument_layouts,
|
||||
result_layout,
|
||||
);
|
||||
|
||||
list_map3(
|
||||
env,
|
||||
layout_interner,
|
||||
roc_function_call,
|
||||
list1,
|
||||
list2,
|
||||
list3,
|
||||
element1_layout,
|
||||
element2_layout,
|
||||
element3_layout,
|
||||
result_layout,
|
||||
)
|
||||
}
|
||||
_ => unreachable!("invalid list layout"),
|
||||
}
|
||||
}
|
||||
ListMap4 { xs, ys, zs, ws } => {
|
||||
let (list1, list1_layout) = scope.load_symbol_and_layout(xs);
|
||||
let (list2, list2_layout) = scope.load_symbol_and_layout(ys);
|
||||
let (list3, list3_layout) = scope.load_symbol_and_layout(zs);
|
||||
let (list4, list4_layout) = scope.load_symbol_and_layout(ws);
|
||||
|
||||
let (function, closure, closure_layout) = function_details!();
|
||||
|
||||
match (
|
||||
layout_interner.get_repr(list1_layout),
|
||||
layout_interner.get_repr(list2_layout),
|
||||
layout_interner.get_repr(list3_layout),
|
||||
layout_interner.get_repr(list4_layout),
|
||||
layout_interner.get_repr(return_layout),
|
||||
) {
|
||||
(
|
||||
LayoutRepr::Builtin(Builtin::List(element1_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(element2_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(element3_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(element4_layout)),
|
||||
LayoutRepr::Builtin(Builtin::List(result_layout)),
|
||||
) => {
|
||||
let argument_layouts = &[
|
||||
element1_layout,
|
||||
element2_layout,
|
||||
element3_layout,
|
||||
element4_layout,
|
||||
];
|
||||
|
||||
let roc_function_call = roc_function_call(
|
||||
env,
|
||||
layout_interner,
|
||||
layout_ids,
|
||||
function,
|
||||
closure,
|
||||
closure_layout,
|
||||
function_owns_closure_data,
|
||||
argument_layouts,
|
||||
result_layout,
|
||||
);
|
||||
|
||||
list_map4(
|
||||
env,
|
||||
layout_interner,
|
||||
roc_function_call,
|
||||
list1,
|
||||
list2,
|
||||
list3,
|
||||
list4,
|
||||
element1_layout,
|
||||
element2_layout,
|
||||
element3_layout,
|
||||
element4_layout,
|
||||
result_layout,
|
||||
)
|
||||
}
|
||||
_ => unreachable!("invalid list layout"),
|
||||
}
|
||||
}
|
||||
ListSortWith { xs } => {
|
||||
// List.sortWith : List a, (a, a -> Ordering) -> List a
|
||||
let (list, list_layout) = scope.load_symbol_and_layout(xs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue