Skip to content

Commit

Permalink
Convert tape in simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed May 20, 2024
1 parent 54fd582 commit ce1e111
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tm/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if TYPE_CHECKING:
from tm.parse import Color, State, Slot, Instr, CompProg

Tape = list[Color]
Tape = tuple[Color, ...]
Config = tuple[State, tuple[bool, Tape]]
Params = tuple[int, int]

Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(self, base_colors: int, cells: int):
def color_to_tape(self, color: Color) -> Tape:
assert (prev := self.color_to_tape_cache.get(color)) is not None

return list(prev)
return prev

def tape_to_color(self, tape: Tape) -> Color:
if (cached := self.tape_to_color_cache.get(
Expand Down Expand Up @@ -184,7 +184,9 @@ def calculate_instr(self, slot: Slot) -> Instr:
slot)))

def run_simulator(self, config: Config) -> Config:
state, (right_edge, tape) = config
state, (right_edge, in_tape) = config

tape = list(in_tape)

cells = len(tape)

Expand Down Expand Up @@ -232,7 +234,7 @@ def run_simulator(self, config: Config) -> Config:
else:
raise MacroInfLoop

return state, (cells <= pos, tape)
return state, (cells <= pos, tuple(tape))

########################################

Expand Down Expand Up @@ -353,9 +355,9 @@ def deconstruct_inputs(self, slot: Slot) -> Config:
backspan = self.converter.color_to_tape(backsymbol)

return state, (
(False, [macro_color] + backspan)
(False, (macro_color,) + backspan)
if at_right else
( True, backspan + [macro_color])
( True, backspan + (macro_color,))
)

def reconstruct_outputs(self, config: Config) -> Instr:
Expand Down

0 comments on commit ce1e111

Please sign in to comment.