mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
wasm: Add support for Expr::Reuse
This commit is contained in:
parent
5de539b9fa
commit
1f82310832
1 changed files with 17 additions and 6 deletions
|
@ -580,7 +580,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
tag_id,
|
tag_id,
|
||||||
arguments,
|
arguments,
|
||||||
..
|
..
|
||||||
} => self.expr_tag(union_layout, *tag_id, arguments, sym, storage),
|
} => self.expr_tag(union_layout, *tag_id, arguments, sym, storage, None),
|
||||||
|
|
||||||
Expr::GetTagId {
|
Expr::GetTagId {
|
||||||
structure,
|
structure,
|
||||||
|
@ -598,9 +598,13 @@ impl<'a> WasmBackend<'a> {
|
||||||
todo!("Expression `{}`", expr.to_pretty(100))
|
todo!("Expression `{}`", expr.to_pretty(100))
|
||||||
}
|
}
|
||||||
|
|
||||||
Expr::Reuse { .. } => {
|
Expr::Reuse {
|
||||||
todo!("Expression `{}`", expr.to_pretty(100))
|
tag_layout,
|
||||||
}
|
tag_id,
|
||||||
|
arguments,
|
||||||
|
symbol: reused,
|
||||||
|
..
|
||||||
|
} => self.expr_tag(tag_layout, *tag_id, arguments, sym, storage, Some(*reused)),
|
||||||
|
|
||||||
Expr::Reset { symbol: arg, .. } => self.expr_reset(*arg, sym, storage),
|
Expr::Reset { symbol: arg, .. } => self.expr_reset(*arg, sym, storage),
|
||||||
|
|
||||||
|
@ -1082,6 +1086,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
arguments: &'a [Symbol],
|
arguments: &'a [Symbol],
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
stored: &StoredValue,
|
stored: &StoredValue,
|
||||||
|
maybe_reused: Option<Symbol>,
|
||||||
) {
|
) {
|
||||||
if union_layout.tag_is_null(tag_id) {
|
if union_layout.tag_is_null(tag_id) {
|
||||||
self.code_builder.i32_const(0);
|
self.code_builder.i32_const(0);
|
||||||
|
@ -1102,8 +1107,14 @@ impl<'a> WasmBackend<'a> {
|
||||||
location.local_and_offset(self.storage.stack_frame_pointer)
|
location.local_and_offset(self.storage.stack_frame_pointer)
|
||||||
}
|
}
|
||||||
StoredValue::Local { local_id, .. } => {
|
StoredValue::Local { local_id, .. } => {
|
||||||
// Tag is stored as a pointer to the heap. Call the allocator to get a memory address.
|
// Tag is stored as a heap pointer.
|
||||||
self.allocate_with_refcount(Some(data_size), data_alignment, 1);
|
if let Some(reused) = maybe_reused {
|
||||||
|
// Reuse an existing heap allocation
|
||||||
|
self.storage.load_symbols(&mut self.code_builder, &[reused]);
|
||||||
|
} else {
|
||||||
|
// Call the allocator to get a memory address.
|
||||||
|
self.allocate_with_refcount(Some(data_size), data_alignment, 1);
|
||||||
|
}
|
||||||
self.code_builder.set_local(local_id);
|
self.code_builder.set_local(local_id);
|
||||||
(local_id, 0)
|
(local_id, 0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue