Remove implicit recursive cloning of AST

This commit is contained in:
Rerumu 2021-12-13 16:23:37 -05:00
parent 59d0abeb41
commit dc1116c3e5
2 changed files with 11 additions and 11 deletions

View File

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

View File

@ -9,36 +9,30 @@ pub struct Recall {
pub var: usize,
}
#[derive(Clone)]
pub struct Select {
pub cond: Box<Expression>,
pub a: Box<Expression>,
pub b: Box<Expression>,
}
#[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<Expression>,
}
#[derive(Clone)]
pub struct MemorySize {
pub memory: u8,
}
#[derive(Clone)]
pub struct MemoryGrow {
pub memory: u8,
pub value: Box<Expression>,
@ -52,20 +46,17 @@ pub enum Value {
F64(f64),
}
#[derive(Clone)]
pub struct AnyUnOp {
pub op: UnOp,
pub rhs: Box<Expression>,
}
#[derive(Clone)]
pub struct AnyBinOp {
pub op: BinOp,
pub lhs: Box<Expression>,
pub rhs: Box<Expression>,
}
#[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 {