Fix stack manager references after Quetzal restore

QuetzalParser._parse_stks() creates a new ZStackManager and sets it on
zmachine._stackmanager, but ZCpu._stackmanager and ZOpDecoder._stack
still pointed to the old empty stack. After restore, all stack ops
(local var reads, routine returns, stack pops) used the wrong stack,
causing the interpreter to crash on the first command.
This commit is contained in:
Jared Miller 2026-02-10 11:51:50 -05:00
parent 15e1d807aa
commit 65a080608a
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -248,6 +248,12 @@ class QuetzalParser:
raise QuetzalStackFrameOverflow
self._zmachine._stackmanager = stackmanager
# Update cached references in subsystems that store the stack manager
# (they cache the stack at init time and won't see the replacement)
if hasattr(self._zmachine, "_cpu"):
self._zmachine._cpu._stackmanager = stackmanager
if hasattr(self._zmachine, "_opdecoder"):
self._zmachine._opdecoder._stack = stackmanager
log(" Successfully installed all stack frames.")
def _parse_intd(self, data):