source/projects/shoggoth/test/python/ichor/fixtures.py

29 lines
751 B
Python

#!/usr/bin/env python3
from textwrap import indent
from ichor import isa
from ichor.bootstrap import BOOTSTRAP
from ichor.interpreter import (
Interpreter,
InterpreterState,
)
import pytest
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
@pytest.fixture
def vm():
return LoggingInterpreter(BOOTSTRAP)