wasm: Get List.map2 working

This commit is contained in:
Brian Carroll 2022-04-07 12:05:53 +01:00
parent 5cce24bc8f
commit 7b96e953ba
5 changed files with 86 additions and 21 deletions

View file

@ -25,7 +25,7 @@ const ARG_2: Symbol = Symbol::ARG_2;
pub const REFCOUNT_MAX: usize = 0;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum HelperOp {
pub enum HelperOp {
Inc,
Dec,
DecRef(JoinPointId),
@ -185,16 +185,16 @@ impl<'a> CodeGenHelp<'a> {
/// Generate a refcount increment procedure, *without* a Call expression.
/// *This method should be rarely used* - only when the proc is to be called from Zig.
/// Otherwise you want to generate the Proc and the Call together, using another method.
/// This only supports the 'inc' operation, as it's the only real use case we have.
pub fn gen_refcount_inc_proc(
pub fn gen_refcount_proc(
&mut self,
ident_ids: &mut IdentIds,
layout: Layout<'a>,
op: HelperOp,
) -> (Symbol, Vec<'a, (Symbol, ProcLayout<'a>)>) {
let mut ctx = Context {
new_linker_data: Vec::new_in(self.arena),
recursive_union: None,
op: HelperOp::Inc,
op,
};
let proc_name = self.find_or_create_proc(ident_ids, &mut ctx, layout);

View file

@ -107,7 +107,9 @@ pub fn refcount_generic<'a>(
match layout {
Layout::Builtin(Builtin::Int(_) | Builtin::Float(_) | Builtin::Bool | Builtin::Decimal) => {
unreachable!("Not refcounted: {:?}", layout)
// Generate a dummy function that immediately returns Unit
// Some higher-order Zig builtins *always* call an RC function on List elements.
rc_return_stmt(root, ident_ids, ctx)
}
Layout::Builtin(Builtin::Str) => refcount_str(root, ident_ids, ctx),
Layout::Builtin(Builtin::List(elem_layout)) => {