Skip to content

Commit 2fbce30

Browse files
committed
Make array human construction language-specific
1 parent 5560902 commit 2fbce30

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

gen_type_mapping.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
183183
to_hu_conv = None
184184
to_hu_conv_name = None
185185
if subty.to_hu_conv is not None:
186-
base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
187-
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", "new " + base_ty + "[" + arr_name + ".length]")
188-
if "[" in ty_info.subty.java_hu_ty.split("<")[0]:
189-
# Do a bit of a dance to move any excess [] to the end
190-
to_hu_conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1]
186+
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", self.consts.constr_hu_array(ty_info, arr_name + ".length"))
191187
to_hu_conv += ";\n" + self.consts.for_n_in_range(idxc, "0", arr_name + ".length") + "\n"
192188
to_hu_conv += "\t" + self.consts.var_decl_statement(subty.java_ty, conv_name, arr_name + "[" + idxc + "]") + ";\n"
193189
to_hu_conv += "\t" + subty.to_hu_conv.replace("\n", "\n\t") + "\n"

java_strings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,14 @@ def init_str(self):
652652
def var_decl_statement(self, ty_string, var_name, statement):
653653
return ty_string + " " + var_name + " = " + statement
654654

655+
def constr_hu_array(self, ty_info, arr_len):
656+
base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
657+
conv = "new " + base_ty + "[" + arr_len + "]"
658+
if "[" in ty_info.subty.java_hu_ty.split("<")[0]:
659+
# Do a bit of a dance to move any excess [] to the end
660+
conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1]
661+
return conv
662+
655663
def for_n_in_range(self, n, minimum, maximum):
656664
return "for (int " + n + " = " + minimum + "; " + n + " < " + maximum + "; " + n + "++) {"
657665
def for_n_in_arr(self, n, arr_name, arr_elem_ty):

typescript_strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ def wasm_import_header(self, target):
548548
def init_str(self):
549549
return ""
550550

551+
def constr_hu_array(self, ty_info, arr_len):
552+
return "new Array(" + arr_len + ").fill(null)"
553+
551554
def var_decl_statement(self, ty_string, var_name, statement):
552555
return "const " + var_name + ": " + ty_string + " = " + statement
553556

0 commit comments

Comments
 (0)