Pad restored local vars to 15 slots
The Quetzal save format only stores the number of local vars the routine declared, but the runtime indexes local_vars[0..14] for any variable access. Restored routines had short lists, causing IndexError on the first command after restore.
This commit is contained in:
parent
1ee89e5e3c
commit
776cfba021
1 changed files with 6 additions and 3 deletions
|
|
@ -214,13 +214,16 @@ class QuetzalParser:
|
||||||
evalstack_size = (bytes[ptr] << 8) + bytes[ptr + 1]
|
evalstack_size = (bytes[ptr] << 8) + bytes[ptr + 1]
|
||||||
ptr += 2
|
ptr += 2
|
||||||
|
|
||||||
# read anywhere from 0 to 15 local vars
|
# read anywhere from 0 to 15 local vars, pad to 15
|
||||||
|
num_locals = flags_bitfield[0:4]
|
||||||
local_vars = []
|
local_vars = []
|
||||||
for _i in range(flags_bitfield[0:4]):
|
for _i in range(num_locals):
|
||||||
var = (bytes[ptr] << 8) + bytes[ptr + 1]
|
var = (bytes[ptr] << 8) + bytes[ptr + 1]
|
||||||
ptr += 2
|
ptr += 2
|
||||||
local_vars.append(var)
|
local_vars.append(var)
|
||||||
log(f" Found {len(local_vars)} local vars")
|
# runtime expects 15 slots, save only stores declared count
|
||||||
|
local_vars.extend([0] * (15 - num_locals))
|
||||||
|
log(f" Found {num_locals} local vars (padded to 15)")
|
||||||
|
|
||||||
# least recent to most recent stack values:
|
# least recent to most recent stack values:
|
||||||
stack_values = []
|
stack_values = []
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue