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