Skip to content

Commit 3eecd3a

Browse files
committed
Added some comments that explain some '???' moments
1 parent efb4ef5 commit 3eecd3a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

luac.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,17 @@ def decode_chunk(self):
210210
template = instr_lookup_tbl[opcode]
211211
instruction = Instruction(template.type, template.name)
212212

213+
# i read the lopcodes.h file to get these bit position and sizes.
213214
instruction.opcode = opcode
214-
instruction.A = _get_bits(data, 6, 8)
215+
instruction.A = _get_bits(data, 6, 8) # starts after POS_OP + SIZE_OP (6), with a size of 8
215216

216217
if instruction.type == InstructionType.ABC:
217-
instruction.B = _get_bits(data, 23, 9)
218-
instruction.C = _get_bits(data, 14, 9)
218+
instruction.B = _get_bits(data, 23, 9) # starts after POS_C + SIZE_C (23), with a size of 9
219+
instruction.C = _get_bits(data, 14, 9) # starts after POS_A + SIZE_A (14), with a size of 9
219220
elif instruction.type == InstructionType.ABx:
220-
instruction.B = _get_bits(data, 14, 18)
221+
instruction.B = _get_bits(data, 14, 18) # starts after POS_A + SIZE_A (14), with a size of 18
221222
elif instruction.type == InstructionType.AsBx:
222-
instruction.B = _get_bits(data, 14, 18) - 131071
223+
instruction.B = _get_bits(data, 14, 18) - 131071 # Bx is now signed, so just sub half of the MAX_UINT for 18 bits
223224

224225
chunk.appendInstruction(instruction)
225226

@@ -247,7 +248,8 @@ def decode_chunk(self):
247248
for i in range(num):
248249
chunk.appendProto(self.decode_chunk())
249250

250-
# debug stuff
251+
# debug stuff, maybe i'll add this to chunks to have better disassembly annotation in the future?
252+
# eh, for now just consume the bytes.
251253

252254
# line numbers
253255
num = self.get_int()

0 commit comments

Comments
 (0)