Skip to content

Commit

Permalink
complete newlexwithname and poplexenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Penkace committed Jan 19, 2025
1 parent bdc9588 commit 6d9bb6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ohre/abcre/dis/DisFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,25 @@ def get_external_module_name(
return None

def create_lexical_environment(
self, slots: int, file_class_method_name: str = "") -> Union[str, None]:
self, slots: int, file_class_method_name: str = "", literal_id=None) -> Union[str, None]:
slots_number = slots
lex_env_layer = [None] * slots_number
if literal_id:
print(literal_id)
left_s = literal_id.find('[')
right_s = literal_id.find(']')
literal_content = literal_id[left_s:right_s+1]
literal_content = literal_content.split(',')
cnt = 0
for i in range(slots_number):
literal_value = literal_content[cnt].strip().split(':')
if len(literal_value) == 2:
variable_value = literal_value[1].replace('"', '')
else:
Log.warn(f"newlexenvwithname failed. literal id format is {literal_content[cnt]}")
variable_name = literal_content[cnt+1].strip()
lex_env_layer[i] = variable_value
cnt += 2
self.lex_env.append(lex_env_layer)
self.cur_lex_level += 1
return self.cur_lex_level
Expand All @@ -282,3 +298,10 @@ def get_lex_env(
Log.warn(f"get_lex_env failed, cur_lex {self.cur_lex_level}.\
Wanted fetch level {fetch_lex_env_index}")
return None

def pop_lex_env(self):
if len(self.lex_env) == 0:
Log.warn(f"pop_lex_env failed, self.lex_env is empty")
else:
self.lex_env.pop()
self.cur_lex_level -= 1
7 changes: 7 additions & 0 deletions ohre/abcre/dis/NACtoTAC.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def toTAC(self, nac: NAC, meth: AsmMethod, dis_file: DisFile) -> Union[TAC, List
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.UNDEFINED))
if (nac.op == "asyncfunctionenter"):
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.METHOD_OBJ, name="__asyncfunctionenter"))
if (nac.op == 'poplexenv'):
dis_file.pop_lex_env()
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.LEXENV))
# === inst: constant object loaders # END

# === inst: comparation instructions # START
Expand Down Expand Up @@ -267,6 +270,10 @@ def toTAC(self, nac: NAC, meth: AsmMethod, dis_file: DisFile) -> Union[TAC, List
slots = int(nac.args[0], base=16)
cur_lexenv_level = dis_file.create_lexical_environment(slots, meth.file_class_method_name)
return TAC.tac_assign(AsmArg.ACC(), AsmArg(AsmTypes.LEXENV, value=cur_lexenv_level))
if (nac.op == "newlexenvwithname"):
slots = int(nac.args[0], base=16)
literal_id = nac.args[1]
cur_lexenv_level = dis_file.create_lexical_environment(slots,meth.file_class_method_name,literal_id=literal_id)
# === inst: object creaters # END

# === inst: object visitors # START
Expand Down

0 comments on commit 6d9bb6a

Please sign in to comment.