def _exp_var_assign(code: Code, exp): name = exp['name'] expression = exp['expression'] t = exp['type'] index = _locals[name] _expression(code, expression) if isinstance(t, TypeInt): code.dup() code.store_int(index) elif isinstance(t, TypeReal): code.dup2() code.store_double(index) elif isinstance(t, TypeBool): code.dup() code.store_int(index) elif isinstance(t, TypeStr): code.dup() code.store_reference(index) elif isinstance(t, TypeArray): code.dup() code.store_reference(index) else: raise NotImplementedError()
def _statement_var_def(code: Code, statement): name = statement['name'] t = statement['type'] expression = statement['expression'] _expression(code, expression) if isinstance(t, TypeInt): index = code.variable_int() code.store_int(index) elif isinstance(t, TypeReal): index = code.variable_double() code.store_double(index) elif isinstance(t, TypeBool): index = code.variable_int() code.store_int(index) elif isinstance(t, TypeStr): index = code.variable_reference() code.store_reference(index) elif isinstance(t, TypeArray): index = code.variable_reference() code.store_reference(index) else: raise NotImplementedError() _locals[name] = index