def _exp_array_load(code: Code, exp): name = exp['name'] index_exps = exp['indexes'] t = exp['type'] index = _locals.get(name) if index is not None: code.load_reference(index) else: name = PREFIX + name field = _fields.get(name) code.load_static_field(field[0], field[1], field[2]) # subarrays load if multidim for e in index_exps[:-1]: _expression(code, e) code.array_load_reference() # item load _expression(code, index_exps[-1]) if isinstance(t, TypeInt): code.array_load_int() elif isinstance(t, TypeReal): code.array_load_double() elif isinstance(t, TypeBool): code.array_load_boolean() elif isinstance(t, TypeStr): code.array_load_reference() elif isinstance(t, TypeArray): code.array_load_reference() else: raise NotImplementedError()
def _exp_array_assign(code: Code, exp): name = exp['name'] index_exps = exp['indexes'] expression = exp['expression'] t = exp['type'] # top array load index = _locals[name] code.load_reference(index) # subarrays load if multidim for e in index_exps[:-1]: _expression(code, e) code.array_load_reference() # item store _expression(code, index_exps[-1]) _expression(code, expression) if isinstance(t.inner, TypeInt): code.dup_x1() code.array_store_int() elif isinstance(t.inner, TypeReal): code.dup2_x1() code.array_store_double() elif isinstance(t.inner, TypeBool): code.dup_x1() code.array_store_boolean() elif isinstance(t.inner, TypeStr): code.dup_x1() code.array_store_reference() elif isinstance(t.inner, TypeArray): code.dup_x1() code.array_store_reference() else: raise NotImplementedError()
def _exp_var_load(code: Code, exp): name = exp['name'] t = exp['type'] index = _locals.get(name) if index is not None: if isinstance(t, TypeInt): code.load_int(index) elif isinstance(t, TypeReal): code.load_double(index) elif isinstance(t, TypeBool): code.load_int(index) elif isinstance(t, TypeStr): code.load_reference(index) elif isinstance(t, TypeArray): code.load_reference(index) else: raise NotImplementedError() else: name = PREFIX + name field = _fields.get(name) code.load_static_field(field[0], field[1], field[2])