From 7657d5b192c28e44a072568bd8df377bf7a2d4bd Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 29 Nov 2021 15:06:45 -0500 Subject: [PATCH 1/3] test: enable wasm in gen_list --- compiler/test_gen/src/gen_list.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 3ed20624f1..42999c5e6c 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1,13 +1,11 @@ -#![cfg(feature = "gen-llvm")] - #[cfg(feature = "gen-llvm")] use crate::helpers::llvm::assert_evals_to; // #[cfg(feature = "gen-dev")] // use crate::helpers::dev::assert_evals_to; -// #[cfg(feature = "gen-wasm")] -// use crate::helpers::wasm::assert_evals_to; +#[cfg(feature = "gen-wasm")] +use crate::helpers::wasm::assert_evals_to; use crate::helpers::with_larger_debug_stack; //use crate::assert_wasm_evals_to as assert_evals_to; @@ -22,7 +20,7 @@ fn roc_list_construction() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] fn empty_list_literal() { assert_evals_to!("[]", RocList::from_slice(&[]), RocList); } @@ -34,6 +32,7 @@ fn list_literal_empty_record() { } #[test] +#[cfg(any(feature = "gen-llvm"))] fn int_singleton_list_literal() { assert_evals_to!("[1, 2]", RocList::from_slice(&[1, 2]), RocList); } From 27e77f446f2361fd740248a7257f5ccea10e92ad Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 29 Nov 2021 15:08:52 -0500 Subject: [PATCH 2/3] feat(wasm): implement EmptyArray --- compiler/gen_wasm/src/backend.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/compiler/gen_wasm/src/backend.rs b/compiler/gen_wasm/src/backend.rs index 4fd555d8e3..750b9521a9 100644 --- a/compiler/gen_wasm/src/backend.rs +++ b/compiler/gen_wasm/src/backend.rs @@ -561,6 +561,27 @@ impl<'a> WasmBackend<'a> { Ok(()) } + Expr::Array { .. } => Err(format!("Expression is not yet implemented {:?}", 2)), + + Expr::EmptyArray => { + if let StoredValue::StackMemory { location, .. } = storage { + let (local_id, offset) = + location.local_and_offset(self.storage.stack_frame_pointer); + + // This is a minor cheat. We only need the first two 32 bit + // chunks here. We fill both chunks with zeros, so we + // can simplify things to a single group of 64 bit operations instead of + // doing the below twice for 32 bits. + self.code_builder.get_local(local_id); + self.code_builder.i64_const(0); + self.code_builder.i64_store(Align::Bytes4, offset); + + Ok(()) + } else { + unreachable!("Unexpected storage for {:?}", sym) + } + } + x => Err(format!("Expression is not yet implemented {:?}", x)), } } From 6305947b1a87ab47f5c4ed4e6800ca4140551af6 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 29 Nov 2021 18:08:12 -0500 Subject: [PATCH 3/3] fix: exclude gen-dev from gen_list test compilation --- compiler/test_gen/src/gen_list.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 42999c5e6c..34e02bfff8 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1,3 +1,6 @@ +#![cfg(feature = "gen-llvm")] +#![cfg(feature = "gen-wasm")] + #[cfg(feature = "gen-llvm")] use crate::helpers::llvm::assert_evals_to;