Fix: rename enterpreter to interpreter
This commit is contained in:
3
src/interpreter/util/__init__.py
Normal file
3
src/interpreter/util/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .hexdump import hexdump
|
||||
|
||||
__all__ = ["hexdump"]
|
||||
45
src/interpreter/util/hexdump.py
Normal file
45
src/interpreter/util/hexdump.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from colorama import Fore, Style, init
|
||||
|
||||
# Initialize colorama (especially important on Windows)
|
||||
init()
|
||||
|
||||
|
||||
def hexdump(
|
||||
data: bytearray,
|
||||
width: int = 16,
|
||||
program_counter: int = None,
|
||||
memory_pointer: int = None,
|
||||
):
|
||||
"""
|
||||
Print a hex+ASCII memory dump of the given bytearray.
|
||||
Highlights:
|
||||
- Program counter (PC) in bright red
|
||||
- Memory pointer (MP) in bright blue
|
||||
"""
|
||||
for i in range(0, len(data), width):
|
||||
chunk = data[i : i + width]
|
||||
hex_parts = []
|
||||
ascii_parts = []
|
||||
|
||||
for j, byte in enumerate(chunk):
|
||||
addr = i + j
|
||||
|
||||
# Apply color based on PC or MP
|
||||
if addr == program_counter:
|
||||
style = Style.BRIGHT + Fore.RED
|
||||
elif addr == memory_pointer:
|
||||
style = Style.BRIGHT + Fore.BLUE
|
||||
else:
|
||||
style = ""
|
||||
reset = Style.RESET_ALL if style else ""
|
||||
|
||||
# Hex and ASCII views
|
||||
hex_parts.append(f"{style}{byte:02x}{reset}")
|
||||
ascii_parts.append(
|
||||
f"{style}{chr(byte) if 32 <= byte <= 126 else '.'}{reset}"
|
||||
)
|
||||
|
||||
# Format line: address, hex bytes, ASCII chars
|
||||
hex_field = " ".join(hex_parts).ljust(width * 3 - 1)
|
||||
ascii_field = "".join(ascii_parts)
|
||||
print(f"{i:08x}: {hex_field} {ascii_field}")
|
||||
Reference in New Issue
Block a user