feat: добавил возможность писать сообщения об ошибках к исключениям виратуальной машинки

This commit is contained in:
ElectronixTM
2025-03-31 03:02:56 +03:00
parent 6b2d5fa31e
commit 44f3e622c8
4 changed files with 5 additions and 2 deletions

0
src/emulator/__init__.py Normal file
View File

View File

@ -37,6 +37,7 @@ class VMExceptionType(Enum):
class VMException(Exception):
cause: VMExceptionType
pc: int
message: str = ""
@dataclass
class VM:
@ -125,7 +126,8 @@ class VM:
if self._to_raw_bytes_offset(self.pc) > len(self.mem) - WORD_SIZE:
raise VMException(
VMExceptionType.END_OF_MEM,
self.pc.value
self.pc.value,
"couldn't perform step because end of memory occured"
)
opcode, *_ = instr = self._fetch_instr()
opdesc = self._get_opcode_desc(opcode)
@ -175,7 +177,8 @@ class VM:
if not opcode in OPCODES:
raise VMException(
VMExceptionType.INVALID_OPCODE,
self.pc.value
self.pc.value,
f"Couldn't resolve an opcode {hex(opcode)}"
)
return OPCODES[opcode]