feat: добавил возможность писать сообщения об ошибках к исключениям виратуальной машинки
This commit is contained in:
0
src/emulator/__init__.py
Normal file
0
src/emulator/__init__.py
Normal 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]
|
||||
|
||||
Reference in New Issue
Block a user