Merge pull request #2101 from rtfeldman/wasm_empty_array

WASM: EmptyArray
This commit is contained in:
Folkert de Vries 2021-11-30 10:17:33 +01:00 committed by GitHub
commit d67cc883ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -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)),
}
}

View file

@ -1,4 +1,5 @@
#![cfg(feature = "gen-llvm")]
#![cfg(feature = "gen-wasm")]
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
@ -6,8 +7,8 @@ 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 +23,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<i64>);
}
@ -34,6 +35,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<i64>);
}