assignment: Add variable assignment
* Syntax for x = y * Compiler creates Inst::Store thunks * New Vm::store function Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -37,7 +37,17 @@ impl Compiler {
|
||||
|
||||
fn emit_stmt(&mut self, stmt: &SpStmt) -> Thunk {
|
||||
match stmt.inner() {
|
||||
Stmt::Assign(_lhs_expr, _expr) => todo!(),
|
||||
Stmt::Assign(lhs_expr, expr) => match lhs_expr.inner() {
|
||||
AssignLhs::Name(n) => {
|
||||
let name = self.scope().lookup_scoped(n).unwrap();
|
||||
let mut thunk = self.emit_expr(expr);
|
||||
thunk.push(Inst::Store(name));
|
||||
thunk
|
||||
}
|
||||
AssignLhs::Complex(_, _) => {
|
||||
todo!("Complex LHS foo.bar assign")
|
||||
}
|
||||
},
|
||||
Stmt::Expr(expr) => {
|
||||
let mut thunk = self.emit_expr(expr);
|
||||
thunk.push(Inst::Pop);
|
||||
@@ -91,7 +101,7 @@ impl Compiler {
|
||||
fn gather_names(&mut self, stmts: &Vec<SpStmt>) {
|
||||
for stmt in stmts {
|
||||
match stmt.inner() {
|
||||
Stmt::Assign(lhs, _) => match lhs {
|
||||
Stmt::Assign(lhs, _) => match lhs.inner() {
|
||||
AssignLhs::Name(name) => {
|
||||
self.scope_mut().insert_local(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user