Box expressions to reduce memory usage

This commit is contained in:
Rerumu 2022-08-25 10:15:38 -04:00
parent 8ccbba9571
commit 5887efa841
3 changed files with 19 additions and 19 deletions

View File

@ -104,8 +104,8 @@ impl StatList {
store_type, store_type,
memory, memory,
offset, offset,
value: self.stack.pop(), value: self.stack.pop().into(),
pointer: self.stack.pop(), pointer: self.stack.pop().into(),
}); });
self.leak_memory_write(memory); self.leak_memory_write(memory);
@ -312,7 +312,7 @@ impl<'a> Factory<'a> {
let stat = match now.block_data { let stat = match now.block_data {
BlockData::Forward { .. } | BlockData::Backward { .. } => Statement::Block(now.into()), BlockData::Forward { .. } | BlockData::Backward { .. } => Statement::Block(now.into()),
BlockData::If { .. } => Statement::If(If { BlockData::If { .. } => Statement::If(If {
condition: self.target.stack.pop(), condition: self.target.stack.pop().into(),
on_true: now.into(), on_true: now.into(),
on_false: None, on_false: None,
}), }),
@ -376,7 +376,7 @@ impl<'a> Factory<'a> {
fn add_call_indirect(&mut self, ty: usize, table: usize) { fn add_call_indirect(&mut self, ty: usize, table: usize) {
let (num_param, num_result) = self.type_info.by_type_index(ty); let (num_param, num_result) = self.type_info.by_type_index(ty);
let index = self.target.stack.pop(); let index = self.target.stack.pop().into();
let param_list = self.target.stack.pop_len(num_param).collect(); let param_list = self.target.stack.pop_len(num_param).collect();
self.target.leak_pre_call(); self.target.leak_pre_call();
@ -458,7 +458,7 @@ impl<'a> Factory<'a> {
Operator::BrIf { relative_depth } => { Operator::BrIf { relative_depth } => {
let target = relative_depth.try_into().unwrap(); let target = relative_depth.try_into().unwrap();
let data = Statement::BrIf(BrIf { let data = Statement::BrIf(BrIf {
condition: self.target.stack.pop(), condition: self.target.stack.pop().into(),
target: self.get_br_terminator(target), target: self.get_br_terminator(target),
}); });
@ -466,7 +466,7 @@ impl<'a> Factory<'a> {
self.target.code.push(data); self.target.code.push(data);
} }
Operator::BrTable { ref table } => { Operator::BrTable { ref table } => {
let condition = self.target.stack.pop(); let condition = self.target.stack.pop().into();
let data = table let data = table
.targets() .targets()
.map(Result::unwrap) .map(Result::unwrap)
@ -532,7 +532,7 @@ impl<'a> Factory<'a> {
let var = local_index.try_into().unwrap(); let var = local_index.try_into().unwrap();
let data = Statement::SetLocal(SetLocal { let data = Statement::SetLocal(SetLocal {
var, var,
value: self.target.stack.pop(), value: self.target.stack.pop().into(),
}); });
self.target.leak_local_write(var); self.target.leak_local_write(var);
@ -543,7 +543,7 @@ impl<'a> Factory<'a> {
let get = Expression::GetLocal(GetLocal { var }); let get = Expression::GetLocal(GetLocal { var });
let set = Statement::SetLocal(SetLocal { let set = Statement::SetLocal(SetLocal {
var, var,
value: self.target.stack.pop(), value: self.target.stack.pop().into(),
}); });
self.target.leak_local_write(var); self.target.leak_local_write(var);
@ -560,7 +560,7 @@ impl<'a> Factory<'a> {
let var = global_index.try_into().unwrap(); let var = global_index.try_into().unwrap();
let data = Statement::SetGlobal(SetGlobal { let data = Statement::SetGlobal(SetGlobal {
var, var,
value: self.target.stack.pop(), value: self.target.stack.pop().into(),
}); });
self.target.leak_global_write(var); self.target.leak_global_write(var);

View File

@ -849,7 +849,7 @@ impl Br {
} }
pub struct BrTable { pub struct BrTable {
pub(crate) condition: Expression, pub(crate) condition: Box<Expression>,
pub(crate) data: Vec<Br>, pub(crate) data: Vec<Br>,
pub(crate) default: Br, pub(crate) default: Br,
} }
@ -908,7 +908,7 @@ impl Block {
} }
pub struct BrIf { pub struct BrIf {
pub(crate) condition: Expression, pub(crate) condition: Box<Expression>,
pub(crate) target: Br, pub(crate) target: Br,
} }
@ -925,7 +925,7 @@ impl BrIf {
} }
pub struct If { pub struct If {
pub(crate) condition: Expression, pub(crate) condition: Box<Expression>,
pub(crate) on_true: Block, pub(crate) on_true: Block,
pub(crate) on_false: Option<Block>, pub(crate) on_false: Option<Block>,
} }
@ -972,7 +972,7 @@ impl Call {
pub struct CallIndirect { pub struct CallIndirect {
pub(crate) table: usize, pub(crate) table: usize,
pub(crate) index: Expression, pub(crate) index: Box<Expression>,
pub(crate) result: Range<usize>, pub(crate) result: Range<usize>,
pub(crate) param_list: Vec<Expression>, pub(crate) param_list: Vec<Expression>,
} }
@ -1001,7 +1001,7 @@ impl CallIndirect {
pub struct SetTemporary { pub struct SetTemporary {
pub(crate) var: usize, pub(crate) var: usize,
pub(crate) value: Expression, pub(crate) value: Box<Expression>,
} }
impl SetTemporary { impl SetTemporary {
@ -1018,7 +1018,7 @@ impl SetTemporary {
pub struct SetLocal { pub struct SetLocal {
pub(crate) var: usize, pub(crate) var: usize,
pub(crate) value: Expression, pub(crate) value: Box<Expression>,
} }
impl SetLocal { impl SetLocal {
@ -1035,7 +1035,7 @@ impl SetLocal {
pub struct SetGlobal { pub struct SetGlobal {
pub(crate) var: usize, pub(crate) var: usize,
pub(crate) value: Expression, pub(crate) value: Box<Expression>,
} }
impl SetGlobal { impl SetGlobal {
@ -1054,8 +1054,8 @@ pub struct StoreAt {
pub(crate) store_type: StoreType, pub(crate) store_type: StoreType,
pub(crate) memory: usize, pub(crate) memory: usize,
pub(crate) offset: u32, pub(crate) offset: u32,
pub(crate) pointer: Expression, pub(crate) pointer: Box<Expression>,
pub(crate) value: Expression, pub(crate) value: Box<Expression>,
} }
impl StoreAt { impl StoreAt {

View File

@ -139,7 +139,7 @@ impl Stack {
let get = Expression::GetTemporary(GetTemporary { var }); let get = Expression::GetTemporary(GetTemporary { var });
let set = Statement::SetTemporary(SetTemporary { let set = Statement::SetTemporary(SetTemporary {
var, var,
value: std::mem::replace(&mut old.data, get), value: std::mem::replace(&mut old.data, get).into(),
}); });
self.capacity = self.capacity.max(var + 1); self.capacity = self.capacity.max(var + 1);