mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
wasm: refactor to prepare for HigherOrder calls
This commit is contained in:
parent
19c02aa087
commit
448140d223
4 changed files with 49 additions and 11 deletions
|
@ -799,11 +799,17 @@ impl<'a> WasmBackend<'a> {
|
||||||
ret_storage,
|
ret_storage,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
CallType::LowLevel { op: lowlevel, .. } => {
|
CallType::LowLevel { op: lowlevel, .. } => {
|
||||||
self.expr_call_low_level(*lowlevel, arguments, ret_sym, ret_layout, ret_storage)
|
self.expr_call_low_level(*lowlevel, arguments, ret_sym, ret_layout, ret_storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
x => todo!("call type {:?}", x),
|
CallType::HigherOrder(higher_order_lowlevel) => {
|
||||||
|
// Note: Zig's calling convention bug will require a generated wrapper function!
|
||||||
|
todo!("higher order calls");
|
||||||
|
}
|
||||||
|
|
||||||
|
CallType::Foreign { .. } => todo!("CallType::Foreign"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ pub fn build_module_without_wrapper<'a>(
|
||||||
println!("## procs");
|
println!("## procs");
|
||||||
for proc in procs.iter() {
|
for proc in procs.iter() {
|
||||||
println!("{}", proc.to_pretty(200));
|
println!("{}", proc.to_pretty(200));
|
||||||
// println!("{:#?}", proc);
|
// println!("{:?}", proc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
use roc_builtins::bitcode::{self, FloatWidth, IntWidth};
|
use roc_builtins::bitcode::{self, FloatWidth, IntWidth};
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
use roc_module::low_level::{LowLevel, LowLevel::*};
|
use roc_module::low_level::LowLevel;
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
|
use roc_mono::ir::HigherOrderLowLevel;
|
||||||
use roc_mono::layout::{Builtin, Layout, UnionLayout};
|
use roc_mono::layout::{Builtin, Layout, UnionLayout};
|
||||||
|
use roc_mono::low_level::HigherOrder;
|
||||||
|
|
||||||
use crate::backend::WasmBackend;
|
use crate::backend::WasmBackend;
|
||||||
use crate::layout::CallConv;
|
use crate::layout::CallConv;
|
||||||
|
@ -174,6 +176,7 @@ impl<'a> LowLevelCall<'a> {
|
||||||
|
|
||||||
/// Main entrypoint from WasmBackend
|
/// Main entrypoint from WasmBackend
|
||||||
pub fn generate(&self, backend: &mut WasmBackend<'a>) {
|
pub fn generate(&self, backend: &mut WasmBackend<'a>) {
|
||||||
|
use LowLevel::*;
|
||||||
use CodeGenNumType::*;
|
use CodeGenNumType::*;
|
||||||
|
|
||||||
let panic_ret_type = || {
|
let panic_ret_type = || {
|
||||||
|
@ -260,14 +263,21 @@ impl<'a> LowLevelCall<'a> {
|
||||||
_ => internal_error!("invalid storage for List"),
|
_ => internal_error!("invalid storage for List"),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ListMap | ListMap2 | ListMap3 | ListMap4 | ListMapWithIndex | ListKeepIf | ListWalk
|
||||||
|
| ListWalkUntil | ListWalkBackwards | ListKeepOks | ListKeepErrs | ListSortWith
|
||||||
|
| ListAny | ListAll | ListFindUnsafe | DictWalk => {
|
||||||
|
internal_error!("HigherOrder lowlevels should not be handled here")
|
||||||
|
}
|
||||||
|
|
||||||
ListGetUnsafe | ListReplaceUnsafe | ListSingle | ListRepeat | ListReverse
|
ListGetUnsafe | ListReplaceUnsafe | ListSingle | ListRepeat | ListReverse
|
||||||
| ListConcat | ListContains | ListAppend | ListPrepend | ListJoin | ListRange
|
| ListConcat | ListContains | ListAppend | ListPrepend | ListJoin | ListRange
|
||||||
| ListMap | ListMap2 | ListMap3 | ListMap4 | ListMapWithIndex | ListKeepIf
|
| ListSublist | ListDropAt | ListSwap => {
|
||||||
| ListWalk | ListWalkUntil | ListWalkBackwards | ListKeepOks | ListKeepErrs
|
todo!("{:?}", self.lowlevel);
|
||||||
| ListSortWith | ListSublist | ListDropAt | ListSwap | ListAny | ListAll
|
}
|
||||||
| ListFindUnsafe | DictSize | DictEmpty | DictInsert | DictRemove | DictContains
|
|
||||||
| DictGetUnsafe | DictKeys | DictValues | DictUnion | DictIntersection
|
DictSize | DictEmpty | DictInsert | DictRemove | DictContains | DictGetUnsafe
|
||||||
| DictDifference | DictWalk | SetFromList => {
|
| DictKeys | DictValues | DictUnion | DictIntersection | DictDifference
|
||||||
|
| SetFromList => {
|
||||||
todo!("{:?}", self.lowlevel);
|
todo!("{:?}", self.lowlevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,7 +715,7 @@ impl<'a> LowLevelCall<'a> {
|
||||||
"Cannot do `==` comparison on different types"
|
"Cannot do `==` comparison on different types"
|
||||||
);
|
);
|
||||||
|
|
||||||
let invert_result = matches!(self.lowlevel, NotEq);
|
let invert_result = matches!(self.lowlevel, LowLevel::NotEq);
|
||||||
|
|
||||||
match arg_layout {
|
match arg_layout {
|
||||||
Layout::Builtin(
|
Layout::Builtin(
|
||||||
|
@ -921,3 +931,25 @@ fn num_is_finite(backend: &mut WasmBackend<'_>, argument: Symbol) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gen_higher_order(higher_order: HigherOrder) {
|
||||||
|
use HigherOrder::*;
|
||||||
|
match higher_order {
|
||||||
|
ListMap { .. }
|
||||||
|
| ListMap2 { .. }
|
||||||
|
| ListMap3 { .. }
|
||||||
|
| ListMap4 { .. }
|
||||||
|
| ListMapWithIndex { .. }
|
||||||
|
| ListKeepIf { .. }
|
||||||
|
| ListWalk { .. }
|
||||||
|
| ListWalkUntil { .. }
|
||||||
|
| ListWalkBackwards { .. }
|
||||||
|
| ListKeepOks { .. }
|
||||||
|
| ListKeepErrs { .. }
|
||||||
|
| ListSortWith { .. }
|
||||||
|
| ListAny { .. }
|
||||||
|
| ListAll { .. }
|
||||||
|
| ListFindUnsafe { .. }
|
||||||
|
| DictWalk { .. } => todo!("{:?}", higher_order),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ impl LowLevelWrapperType {
|
||||||
Symbol::LIST_PREPEND => CanBeReplacedBy(ListPrepend),
|
Symbol::LIST_PREPEND => CanBeReplacedBy(ListPrepend),
|
||||||
Symbol::LIST_JOIN => CanBeReplacedBy(ListJoin),
|
Symbol::LIST_JOIN => CanBeReplacedBy(ListJoin),
|
||||||
Symbol::LIST_RANGE => CanBeReplacedBy(ListRange),
|
Symbol::LIST_RANGE => CanBeReplacedBy(ListRange),
|
||||||
Symbol::LIST_MAP => CanBeReplacedBy(ListMap),
|
Symbol::LIST_MAP => WrapperIsRequired,
|
||||||
Symbol::LIST_MAP2 => CanBeReplacedBy(ListMap2),
|
Symbol::LIST_MAP2 => CanBeReplacedBy(ListMap2),
|
||||||
Symbol::LIST_MAP3 => CanBeReplacedBy(ListMap3),
|
Symbol::LIST_MAP3 => CanBeReplacedBy(ListMap3),
|
||||||
Symbol::LIST_MAP4 => CanBeReplacedBy(ListMap4),
|
Symbol::LIST_MAP4 => CanBeReplacedBy(ListMap4),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue