mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +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
|
@ -1549,7 +1549,7 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
|
|||
StrToNum => RC::NoRc,
|
||||
ListPrepend => RC::Rc,
|
||||
StrJoinWith => RC::NoRc,
|
||||
ListMap | ListMap2 | ListMap3 | ListMap4 | ListSortWith => RC::Rc,
|
||||
ListSortWith => RC::Rc,
|
||||
|
||||
ListAppendUnsafe
|
||||
| ListReserve
|
||||
|
|
|
@ -1103,72 +1103,7 @@ fn insert_refcount_operations_binding<'a>(
|
|||
// This should always be true, not sure where this could be set to false.
|
||||
debug_assert!(passed_function.owns_captured_environment);
|
||||
|
||||
// define macro that inserts a decref statement for a symbol amount of symbols
|
||||
macro_rules! decref_lists {
|
||||
($stmt:expr, $symbol:expr) => {
|
||||
arena.alloc(Stmt::Refcounting(ModifyRc::DecRef($symbol), $stmt))
|
||||
};
|
||||
|
||||
($stmt:expr, $symbol:expr, $($symbols:expr),+) => {{
|
||||
decref_lists!(decref_lists!($stmt, $symbol), $($symbols),+)
|
||||
}};
|
||||
}
|
||||
|
||||
match operator {
|
||||
HigherOrder::ListMap { xs } => {
|
||||
if let [_xs_symbol, _function_symbol, closure_symbol] = &arguments {
|
||||
let new_stmt = dec_borrowed!([*closure_symbol], stmt);
|
||||
let new_stmt = decref_lists!(new_stmt, *xs);
|
||||
|
||||
let new_let = new_let!(new_stmt);
|
||||
|
||||
inc_owned!([*xs].into_iter(), new_let)
|
||||
} else {
|
||||
panic!("ListMap should have 3 arguments");
|
||||
}
|
||||
}
|
||||
HigherOrder::ListMap2 { xs, ys } => {
|
||||
if let [_xs_symbol, _ys_symbol, _function_symbol, closure_symbol] =
|
||||
&arguments
|
||||
{
|
||||
let new_stmt = dec_borrowed!([*closure_symbol], stmt);
|
||||
let new_stmt = decref_lists!(new_stmt, *xs, *ys);
|
||||
|
||||
let new_let = new_let!(new_stmt);
|
||||
|
||||
inc_owned!([*xs, *ys].into_iter(), new_let)
|
||||
} else {
|
||||
panic!("ListMap2 should have 4 arguments");
|
||||
}
|
||||
}
|
||||
HigherOrder::ListMap3 { xs, ys, zs } => {
|
||||
if let [_xs_symbol, _ys_symbol, _zs_symbol, _function_symbol, closure_symbol] =
|
||||
&arguments
|
||||
{
|
||||
let new_stmt = dec_borrowed!([*closure_symbol], stmt);
|
||||
let new_stmt = decref_lists!(new_stmt, *xs, *ys, *zs);
|
||||
|
||||
let new_let = new_let!(new_stmt);
|
||||
|
||||
inc_owned!([*xs, *ys, *zs].into_iter(), new_let)
|
||||
} else {
|
||||
panic!("ListMap3 should have 5 arguments");
|
||||
}
|
||||
}
|
||||
HigherOrder::ListMap4 { xs, ys, zs, ws } => {
|
||||
if let [_xs_symbol, _ys_symbol, _zs_symbol, _ws_symbol, _function_symbol, closure_symbol] =
|
||||
&arguments
|
||||
{
|
||||
let new_stmt = dec_borrowed!([*closure_symbol], stmt);
|
||||
let new_stmt = decref_lists!(new_stmt, *xs, *ys, *zs, *ws);
|
||||
|
||||
let new_let = new_let!(new_stmt);
|
||||
|
||||
inc_owned!([*xs, *ys, *zs, *ws].into_iter(), new_let)
|
||||
} else {
|
||||
panic!("ListMap4 should have 6 arguments");
|
||||
}
|
||||
}
|
||||
HigherOrder::ListSortWith { xs } => {
|
||||
// TODO if non-unique, elements have been consumed, must still consume the list itself
|
||||
if let [_xs_symbol, _function_symbol, closure_symbol] = &arguments {
|
||||
|
@ -1343,10 +1278,6 @@ pub(crate) fn lowlevel_borrow_signature(op: LowLevel) -> &'static [Ownership] {
|
|||
StrToNum => &[BORROWED],
|
||||
ListPrepend => &[OWNED, OWNED],
|
||||
StrJoinWith => &[BORROWED, BORROWED],
|
||||
ListMap => &[OWNED, FUNCTION, CLOSURE_DATA],
|
||||
ListMap2 => &[OWNED, OWNED, FUNCTION, CLOSURE_DATA],
|
||||
ListMap3 => &[OWNED, OWNED, OWNED, FUNCTION, CLOSURE_DATA],
|
||||
ListMap4 => &[OWNED, OWNED, OWNED, OWNED, FUNCTION, CLOSURE_DATA],
|
||||
ListSortWith => &[OWNED, FUNCTION, CLOSURE_DATA],
|
||||
ListAppendUnsafe => &[OWNED, OWNED],
|
||||
ListReserve => &[OWNED, IRRELEVANT],
|
||||
|
|
|
@ -5812,43 +5812,11 @@ pub fn with_hole<'a>(
|
|||
|
||||
use LowLevel::*;
|
||||
match op {
|
||||
ListMap => {
|
||||
debug_assert_eq!(arg_symbols.len(), 2);
|
||||
let xs = arg_symbols[0];
|
||||
match_on_closure_argument!(ListMap, [xs])
|
||||
}
|
||||
ListSortWith => {
|
||||
debug_assert_eq!(arg_symbols.len(), 2);
|
||||
let xs = arg_symbols[0];
|
||||
match_on_closure_argument!(ListSortWith, [xs])
|
||||
}
|
||||
ListMap2 => {
|
||||
debug_assert_eq!(arg_symbols.len(), 3);
|
||||
|
||||
let xs = arg_symbols[0];
|
||||
let ys = arg_symbols[1];
|
||||
|
||||
match_on_closure_argument!(ListMap2, [xs, ys])
|
||||
}
|
||||
ListMap3 => {
|
||||
debug_assert_eq!(arg_symbols.len(), 4);
|
||||
|
||||
let xs = arg_symbols[0];
|
||||
let ys = arg_symbols[1];
|
||||
let zs = arg_symbols[2];
|
||||
|
||||
match_on_closure_argument!(ListMap3, [xs, ys, zs])
|
||||
}
|
||||
ListMap4 => {
|
||||
debug_assert_eq!(arg_symbols.len(), 5);
|
||||
|
||||
let xs = arg_symbols[0];
|
||||
let ys = arg_symbols[1];
|
||||
let zs = arg_symbols[2];
|
||||
let ws = arg_symbols[3];
|
||||
|
||||
match_on_closure_argument!(ListMap4, [xs, ys, zs, ws])
|
||||
}
|
||||
BoxExpr => {
|
||||
debug_assert_eq!(arg_symbols.len(), 1);
|
||||
let x = arg_symbols[0];
|
||||
|
|
|
@ -2,36 +2,12 @@ use roc_module::symbol::Symbol;
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum HigherOrder {
|
||||
ListMap {
|
||||
xs: Symbol,
|
||||
},
|
||||
ListMap2 {
|
||||
xs: Symbol,
|
||||
ys: Symbol,
|
||||
},
|
||||
ListMap3 {
|
||||
xs: Symbol,
|
||||
ys: Symbol,
|
||||
zs: Symbol,
|
||||
},
|
||||
ListMap4 {
|
||||
xs: Symbol,
|
||||
ys: Symbol,
|
||||
zs: Symbol,
|
||||
ws: Symbol,
|
||||
},
|
||||
ListSortWith {
|
||||
xs: Symbol,
|
||||
},
|
||||
ListSortWith { xs: Symbol },
|
||||
}
|
||||
|
||||
impl HigherOrder {
|
||||
pub fn function_arity(&self) -> usize {
|
||||
match self {
|
||||
HigherOrder::ListMap { .. } => 1,
|
||||
HigherOrder::ListMap2 { .. } => 2,
|
||||
HigherOrder::ListMap3 { .. } => 3,
|
||||
HigherOrder::ListMap4 { .. } => 4,
|
||||
HigherOrder::ListSortWith { .. } => 2,
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +18,7 @@ impl HigherOrder {
|
|||
use HigherOrder::*;
|
||||
|
||||
match self {
|
||||
ListMap { .. } | ListSortWith { .. } => 2,
|
||||
ListMap2 { .. } => 3,
|
||||
ListMap3 { .. } => 4,
|
||||
ListMap4 { .. } => 5,
|
||||
ListSortWith { .. } => 2,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue