added variable updates
This commit is contained in:
parent
4c69228848
commit
b186e45067
2 changed files with 16 additions and 4 deletions
|
@ -214,6 +214,20 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
|
|||
set_register(registers, RegisterState { id: reg.register, used: true, variable: 0, last_used: *op_count });
|
||||
return reg.register;
|
||||
},
|
||||
ASTPart::VarUpdate(upd) => {
|
||||
if !var_ids.contains_key(&upd.variable) {
|
||||
panic!("Variable {} does not exist", upd.variable);
|
||||
}
|
||||
let reg = get_register_by_variable(registers, var_ids[&upd.variable]);
|
||||
if reg.id != 0 {
|
||||
ops.push(Operation { opcode: 8, arg1: Some(reg.id), arg2: None, arg3: None });
|
||||
set_register(registers, RegisterState { id: reg.id, used: false, variable: 0, last_used: 0 });
|
||||
}
|
||||
let value_reg = do_ast_op(*upd.value, op_count, ops, var_ids, next_var_id, strings, next_string_id, functions, next_function_id, registers);
|
||||
ops.push(Operation { opcode: 7, arg1: Some(value_reg), arg2: Some(var_ids[&upd.variable] as i64), arg3: None });
|
||||
set_register(registers, RegisterState { id: value_reg, used: true, variable: var_ids[&upd.variable], last_used: *op_count });
|
||||
garbage_collect_registers(registers);
|
||||
},
|
||||
ASTPart::Assigment(asign) => {
|
||||
if var_ids.contains_key(&asign.variable) {
|
||||
panic!("Variable {} already exists", asign.variable);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue