Skip to content

Commit

Permalink
Yield from instr_seq
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Jun 4, 2024
1 parent efb11a8 commit 14d31fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions test/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ def test_reasoner(self):
cant_halt(
"1RB ... 1LC 0RC 1RA 0LC"))

_ = instr_seq(
"1RB 1LB 1LA ...")
_ = list(instr_seq(
"1RB 1LB 1LA ..."))

_ = instr_seq(
"1RB ... 0RC 0LA 1LC 1LD 0RB 0RD")
_ = list(instr_seq(
"1RB ... 0RC 0LA 1LC 1LD 0RB 0RD"))

def test_mixed_divs(self):
self.assertIsNotNone(
Expand Down
12 changes: 4 additions & 8 deletions tools/instr_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
from tools.normalize import Normalizer

if TYPE_CHECKING:
from tm.machine import Slot, Undfnd
from collections.abc import Iterator

InstrSeq = list[tuple[str, int, Slot]]
from tm.machine import Slot, Undfnd


def instr_seq(prog: str) -> InstrSeq:
def instr_seq(prog: str) -> Iterator[tuple[str, int, Slot]]:
program = Normalizer(prog)

seqs: InstrSeq = []

partial = Normalizer.init(
states := len(program.states),
colors := len(program.colors))
Expand All @@ -27,15 +25,13 @@ def instr_seq(prog: str) -> InstrSeq:

step, slot = result

seqs.append((str(partial), step, slot))
yield str(partial), step, slot

try:
partial[slot] = program[slot]
except KeyError:
break

return seqs


def run_for_undefined(prog: Normalizer) -> Undfnd | None:
tape = Tape()
Expand Down

0 comments on commit 14d31fc

Please sign in to comment.