2022-04-15 06:31:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-08-13 05:26:42 +00:00
|
|
|
from textwrap import indent
|
|
|
|
|
|
|
|
from ichor import isa
|
2022-08-09 15:39:33 +00:00
|
|
|
from ichor.bootstrap import BOOTSTRAP
|
2022-08-13 05:26:42 +00:00
|
|
|
from ichor.interpreter import (
|
|
|
|
Interpreter,
|
|
|
|
InterpreterState,
|
|
|
|
)
|
2022-06-01 05:17:32 +00:00
|
|
|
import pytest
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-08-13 05:26:42 +00:00
|
|
|
class LoggingInterpreter(Interpreter):
|
|
|
|
def pre_instr(self, state: InterpreterState, opcode: isa.Opcode) -> InterpreterState:
|
|
|
|
b = []
|
|
|
|
b.append(f"clock {state.clock}:")
|
|
|
|
b.append(" stack:")
|
|
|
|
for offset, it in zip(range(0, len(state.stackframe), 1), state.stackframe):
|
|
|
|
b.append(f" {offset: <3} {it}")
|
|
|
|
b.append(f" op: {opcode}")
|
|
|
|
print(indent("\n".join(b), " " * state.stackframe.depth))
|
|
|
|
|
|
|
|
return state
|
|
|
|
|
|
|
|
|
2022-04-15 06:31:58 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def vm():
|
2022-08-13 05:26:42 +00:00
|
|
|
return LoggingInterpreter(BOOTSTRAP)
|