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:
2022-02-09 16:54:06 +01:00
parent 7ea5f67f9c
commit 383da4ae05
7 changed files with 183 additions and 32 deletions

View File

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