Rewrite declaration as statement instead of binop
- Declarations are now separate statements - Generate unknown var errors when vars are not declared - Replace Peekable by new custom PutBackIter type that allows for unlimited putback and therefore look-ahead
This commit is contained in:
@@ -40,6 +40,7 @@ impl SimpleAstOptimizer {
|
||||
Self::optimize_block(body_false);
|
||||
}
|
||||
Statement::Print(expr) => Self::optimize_expr(expr),
|
||||
Statement::Declaration(_, _, expr) => Self::optimize_expr(expr),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +75,7 @@ impl SimpleAstOptimizer {
|
||||
BinOpType::Greater => Expression::I64(if lhs > rhs { 1 } else { 0 }),
|
||||
BinOpType::GreaterEqu => Expression::I64(if lhs >= rhs { 1 } else { 0 }),
|
||||
|
||||
BinOpType::Declare | BinOpType::Assign => unreachable!(),
|
||||
BinOpType::Assign => unreachable!(),
|
||||
};
|
||||
*expr = new_expr;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user