From ce1e111317645a33dee92398d04acf9fb0cd8687 Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Mon, 20 May 2024 08:56:23 -0500 Subject: [PATCH] Convert tape in simulator --- tm/macro.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tm/macro.py b/tm/macro.py index a375344f..159f0671 100644 --- a/tm/macro.py +++ b/tm/macro.py @@ -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] @@ -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( @@ -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) @@ -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)) ######################################## @@ -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: