mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
remove box and unbox expressions
This commit is contained in:
parent
a9813aeae7
commit
d64930c17f
12 changed files with 9 additions and 196 deletions
|
@ -1136,10 +1136,6 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
|
|||
storage,
|
||||
),
|
||||
|
||||
Expr::ExprBox { symbol: arg_sym } => self.expr_box(sym, *arg_sym, layout, storage),
|
||||
|
||||
Expr::ExprUnbox { symbol: arg_sym } => self.expr_unbox(sym, *arg_sym),
|
||||
|
||||
Expr::Reset { symbol: arg, .. } => self.expr_reset(*arg, sym, storage),
|
||||
|
||||
Expr::ResetRef { symbol: arg, .. } => self.expr_resetref(*arg, sym, storage),
|
||||
|
@ -2005,40 +2001,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
|
|||
* Box
|
||||
*******************************************************************/
|
||||
|
||||
pub fn expr_box(
|
||||
&mut self,
|
||||
ret_sym: Symbol,
|
||||
arg_sym: Symbol,
|
||||
layout: InLayout<'a>,
|
||||
storage: &StoredValue,
|
||||
) {
|
||||
// create a local variable for the heap pointer
|
||||
let ptr_local_id = match self.storage.ensure_value_has_local(
|
||||
&mut self.code_builder,
|
||||
ret_sym,
|
||||
storage.clone(),
|
||||
) {
|
||||
StoredValue::Local { local_id, .. } => local_id,
|
||||
_ => internal_error!("A heap pointer will always be an i32"),
|
||||
};
|
||||
|
||||
// allocate heap memory and load its data address onto the value stack
|
||||
let arg_layout = match self.layout_interner.get_repr(layout) {
|
||||
LayoutRepr::Boxed(arg) => arg,
|
||||
_ => internal_error!("ExprBox should always produce a Boxed layout"),
|
||||
};
|
||||
let (size, alignment) = self.layout_interner.stack_size_and_alignment(arg_layout);
|
||||
self.allocate_with_refcount(Some(size), alignment, 1);
|
||||
|
||||
// store the pointer value from the value stack into the local variable
|
||||
self.code_builder.set_local(ptr_local_id);
|
||||
|
||||
// copy the argument to the pointer address
|
||||
self.storage
|
||||
.copy_value_to_memory(&mut self.code_builder, ptr_local_id, 0, arg_sym);
|
||||
}
|
||||
|
||||
pub(crate) fn expr_unbox(&mut self, ret_sym: Symbol, arg_sym: Symbol) {
|
||||
pub(crate) fn ptr_load(&mut self, ret_sym: Symbol, arg_sym: Symbol) {
|
||||
let (from_addr_val, from_offset) = match self.storage.get(&arg_sym) {
|
||||
StoredValue::VirtualMachineStack { .. } => {
|
||||
self.storage
|
||||
|
|
|
@ -1978,7 +1978,7 @@ impl<'a> LowLevelCall<'a> {
|
|||
value,
|
||||
);
|
||||
}
|
||||
PtrLoad => backend.expr_unbox(self.ret_symbol, self.arguments[0]),
|
||||
PtrLoad => backend.ptr_load(self.ret_symbol, self.arguments[0]),
|
||||
PtrClearTagId => {
|
||||
let ptr = self.arguments[0];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue