Skip to content

Commit

Permalink
Fix macro cells
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed May 20, 2024
1 parent ce1e111 commit f78c5fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 7 additions & 6 deletions test/test_turing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from tm.parse import tcompile
from tm.show import show_comp
from tm.tree import Program
from tm.macro import opt_block
from tm.macro import opt_block, MacroProg
from tm.reason import (
cant_halt,
cant_blank,
Expand Down Expand Up @@ -611,10 +611,10 @@ def assert_spinout(self) -> None:
self.machine.spnout)

def assert_macro_cells(self, cells: int):
assert not isinstance(macro := self.machine.program, dict)
assert isinstance(macro := self.machine.program, MacroProg)

self.assertEqual(
macro.cells, # type: ignore[attr-defined]
macro.cells,
cells)

def assert_mult_rules(self) -> None:
Expand Down Expand Up @@ -770,9 +770,10 @@ def _test_prover_est(self, prog_data: ProverEst):
self.assert_mult_rules()

if is_macro := (
not isinstance(
macro := self.machine.program, dict)):
result *= macro.cells # type: ignore[attr-defined]
isinstance(
macro := self.machine.program,
MacroProg)):
result *= macro.cells

if isinstance(marks, int):
self.assertEqual(result, marks)
Expand Down
7 changes: 5 additions & 2 deletions tm/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ def __str__(self) -> str:
str(comp)
)

# pylint: disable = line-too-long
return f'{comp_str} ({self.logic.cells}-cell {self.logic.name} macro)'
return f'{comp_str} ({self.cells}-cell {self.logic.name} macro)'

@property
def macro_states(self) -> int:
Expand All @@ -167,6 +166,10 @@ def macro_states(self) -> int:
def macro_colors(self) -> int:
return self.logic.macro_colors

@property
def cells(self) -> int:
return self.logic.cells

def __getitem__(self, slot: Slot) -> Instr:
try:
instr = self.instrs[slot]
Expand Down

0 comments on commit f78c5fb

Please sign in to comment.