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_value_array(code: Code, exp): items = exp['items'] t = exp['type'] if t.dim > 1: desc = _create_field_descriptor(TypeArray(t.dim - 1, t.inner)) else: desc = _create_field_descriptor(t.inner) code.const_int(len(items)) code.new_array(desc) for (i, item) in enumerate(items): code.dup() code.const_int(i) item_type = item['type'] _expression(code, item) if isinstance(item_type, TypeInt): code.array_store_int() elif isinstance(item_type, TypeReal): code.array_store_double() elif isinstance(item_type, TypeBool): code.array_store_boolean() elif isinstance(item_type, TypeStr): code.array_store_reference() elif isinstance(item_type, TypeArray): code.array_store_reference() else: raise NotImplementedError()