Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
fix: Only free if there's something to free
Browse files Browse the repository at this point in the history
  • Loading branch information
06Games committed Jun 13, 2024
1 parent 74b07ca commit aacafa0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions generation_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def gen_listeInstructions(listeInstructions: arbre_abstrait.Instructions, deallo
for instruction in listeInstructions.instructions:
gen_instruction(instruction)
removed = tableSymboles.quitBlock(deallocate)
if deallocate:
if deallocate and len(removed) > 0:
arm_instruction("add", "sp", f"#{len(removed)*4}")


Expand Down Expand Up @@ -172,7 +172,9 @@ def gen_function(instruction):
tableSymboles.checkArgsType(instruction.fct, argsType)
if inProgram:
arm_instruction("bl", f"_{instruction.fct}")
arm_instruction("add", "sp", f"#{tableSymboles.memory(instruction.fct)}")
memory = tableSymboles.memory(instruction.fct)
if memory > 0:
arm_instruction("add", "sp", f"#{memory}")
else:
if instruction.fct == "lire":
gen_lire()
Expand All @@ -192,7 +194,7 @@ def gen_return(instruction):
if returnType != expectedType:
erreur(f"Incorrect return type expected {typeStr(expectedType)} got {typeStr(returnType)}")
arm_instruction("pop", "{r2}", comment="Return value")
removed = list(filter(lambda symbol: tableSymboles._symbols[symbol].get("depth", 0) > 1, tableSymboles._symbols))
removed = tableSymboles.symbolsToFree(2)
arm_instruction("add", "sp", f"#{len(removed)*4}")
arm_instruction("pop", "{fp, pc}")

Expand Down
5 changes: 4 additions & 1 deletion table_des_symboles.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ def enterBlock(self, print=True):
if print:
gen_code.printift(f"Entering depth {self._depth}\n{self}")

def symbolsToFree(self, depth):
return list(filter(lambda symbol: self._symbols[symbol].get("depth", -1) >= depth, self._symbols))

def quitBlock(self, print=True):
if print:
gen_code.printift(f"Quitting depth {self._depth}\n{self}")
toRemove = list(filter(lambda symbol: self._symbols[symbol].get("depth", 0) >= self._depth, self._symbols))
toRemove = self.symbolsToFree(self._depth)
for symbol in toRemove:
self.remove(symbol)
if print:
Expand Down

0 comments on commit aacafa0

Please sign in to comment.