lp: bug fix (forgot to transfer registers)

This commit is contained in:
CPunch 2022-08-16 00:26:50 -05:00
parent 19bed999ee
commit bc4e762e26
2 changed files with 8 additions and 3 deletions

View File

@ -71,8 +71,9 @@ R[5]: i
==== [[example.lua's pseudo-code]] ==== ==== [[example.lua's pseudo-code]] ====
local tbl = {"He", "llo", " ", "Wo", "rld", "!", } local tbl = {"He", "llo", " ", "Wo", "rld", "!", }
local str = ""
for i = 1, #tbl, 1 do for i = 1, #tbl, 1 do
local str = str .. tbl[i] str = str .. tbl[i]
end end
print(str) print(str)

View File

@ -207,7 +207,6 @@ class LuaDecomp:
self.__endStatement() self.__endStatement()
# =====================================[[ Instructions ]]====================================== # =====================================[[ Instructions ]]======================================
def __emitOperand(self, a: int, b: str, c: str, op: str) -> None: def __emitOperand(self, a: int, b: str, c: str, op: str) -> None:
@ -268,7 +267,7 @@ class LuaDecomp:
tblOps = [Opcodes.LOADK, Opcodes.SETLIST] tblOps = [Opcodes.LOADK, Opcodes.SETLIST]
instr = self.__getNextInstr() instr = self.__getNextInstr()
cachedRegs = self.top cachedRegs = {}
tbl = "{" tbl = "{"
while instr.opcode in tblOps: while instr.opcode in tblOps:
if instr.opcode == Opcodes.LOADK: # operate on registers if instr.opcode == Opcodes.LOADK: # operate on registers
@ -278,6 +277,7 @@ class LuaDecomp:
for i in range(numElems): for i in range(numElems):
tbl += "%s, " % cachedRegs[instr.A + i + 1] tbl += "%s, " % cachedRegs[instr.A + i + 1]
del cachedRegs[instr.A + i + 1]
self.pc += 1 self.pc += 1
instr = self.__getNextInstr() instr = self.__getNextInstr()
@ -289,6 +289,10 @@ class LuaDecomp:
self.__setReg(indx, tbl, forceLocal=True) self.__setReg(indx, tbl, forceLocal=True)
self.__endStatement() self.__endStatement()
# if we have leftovers... oops, set those
for i, v in cachedRegs.items():
self.__setReg(i, v)
def parseInstr(self): def parseInstr(self):
instr = self.__getCurrInstr() instr = self.__getCurrInstr()