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

30 lines
751 B
Python
Raw Normal View History

2022-04-15 06:31:58 +00:00
#!/usr/bin/env python3
from textwrap import indent
from ichor import isa
2022-08-09 15:39:33 +00:00
from ichor.bootstrap import BOOTSTRAP
from ichor.interpreter import (
Interpreter,
InterpreterState,
)
2022-06-01 05:17:32 +00:00
import pytest
2022-04-15 06:31:58 +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():
return LoggingInterpreter(BOOTSTRAP)