From dc1116c3e5889d4d10d4c20d5459eac0107f85b3 Mon Sep 17 00:00:00 2001 From: Rerumu Date: Mon, 13 Dec 2021 16:23:37 -0500 Subject: [PATCH] Remove implicit recursive cloning of AST --- wasm/src/ast/builder.rs | 6 ++++-- wasm/src/ast/node.rs | 16 +++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/wasm/src/ast/builder.rs b/wasm/src/ast/builder.rs index ea818bc..7e29e44 100644 --- a/wasm/src/ast/builder.rs +++ b/wasm/src/ast/builder.rs @@ -212,7 +212,9 @@ impl<'a> Builder<'a> { // Pending expressions are put to sleep before entering // a control structure so that they are not lost. fn save_pending(&mut self) { - self.pending.push(self.stack.clone()); + let cloned = self.stack.iter().map(Expression::clone_recall).collect(); + + self.pending.push(cloned); } fn load_pending(&mut self) { @@ -456,7 +458,7 @@ impl<'a> Builder<'a> { Inst::TeeLocal(i) => { self.gen_leak_pending(&mut stat); - let value = self.stack.last().unwrap().clone(); + let value = self.stack.last().unwrap().clone_recall(); stat.push(Statement::SetLocal(SetLocal { var: *i, value })); } diff --git a/wasm/src/ast/node.rs b/wasm/src/ast/node.rs index 7b7927d..57cdeb6 100644 --- a/wasm/src/ast/node.rs +++ b/wasm/src/ast/node.rs @@ -9,36 +9,30 @@ pub struct Recall { pub var: usize, } -#[derive(Clone)] pub struct Select { pub cond: Box, pub a: Box, pub b: Box, } -#[derive(Clone)] pub struct GetLocal { pub var: u32, } -#[derive(Clone)] pub struct GetGlobal { pub var: u32, } -#[derive(Clone)] pub struct AnyLoad { pub op: Load, pub offset: u32, pub pointer: Box, } -#[derive(Clone)] pub struct MemorySize { pub memory: u8, } -#[derive(Clone)] pub struct MemoryGrow { pub memory: u8, pub value: Box, @@ -52,20 +46,17 @@ pub enum Value { F64(f64), } -#[derive(Clone)] pub struct AnyUnOp { pub op: UnOp, pub rhs: Box, } -#[derive(Clone)] pub struct AnyBinOp { pub op: BinOp, pub lhs: Box, pub rhs: Box, } -#[derive(Clone)] pub enum Expression { Recall(Recall), Select(Select), @@ -86,6 +77,13 @@ impl Expression { _ => false, } } + + pub fn clone_recall(&self) -> Self { + match self { + Expression::Recall(v) => Expression::Recall(v.clone()), + _ => unreachable!("clone_recall called on non-recall"), + } + } } pub struct Memorize {