From e0999c5137383580e2ed84e603cb22caf6671629 Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Fri, 7 Jun 2024 14:19:45 -0400 Subject: [PATCH] Port make_instrs --- src/lib.rs | 2 +- src/tree.rs | 25 ++++++++++++++++++++++++- tm/rust_stuff.pyi | 2 ++ tm/tree.py | 11 +---------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3a9b451a..ad0e1d3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,6 @@ mod rust_stuff { prover::PastConfigs, reason::{cant_blank, cant_halt, cant_spin_out}, rules::{InfiniteRule, RuleLimit, UnknownRule}, - tree::{run_for_undefined, TreeSkip}, + tree::{make_instrs, run_for_undefined, TreeSkip}, }; } diff --git a/src/tree.rs b/src/tree.rs index bfa0744a..c414cf6f 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -2,12 +2,35 @@ use pyo3::{ create_exception, exceptions::PyException, pyfunction, PyResult, }; -use crate::{instrs::Slot, parse::tcompile, tape::BasicTape as Tape}; +use crate::{ + instrs::{Color, Instr, Slot, State}, + parse::tcompile, + tape::BasicTape as Tape, +}; type Step = u64; /**************************************/ +#[pyfunction] +pub fn make_instrs(states: State, colors: Color) -> Vec { + let mut instrs = vec![]; + + let shifts = [false, true]; + + for color in 0..colors { + for shift in shifts { + for state in 0..states { + instrs.push((color, shift, state)); + } + } + } + + instrs +} + +/**************************************/ + create_exception!(tree, TreeSkip, PyException); #[pyfunction] diff --git a/tm/rust_stuff.pyi b/tm/rust_stuff.pyi index 4f70d5a2..a093cde3 100644 --- a/tm/rust_stuff.pyi +++ b/tm/rust_stuff.pyi @@ -128,3 +128,5 @@ def cant_spin_out(prog: str) -> bool: ... class TreeSkip(Exception): ... def run_for_undefined(prog: str, sim_lim: int) -> Slot | None: ... + +def make_instrs(states: int, colors: int) -> list[Instr]: ... diff --git a/tm/tree.py b/tm/tree.py index ce391bca..c06e801d 100644 --- a/tm/tree.py +++ b/tm/tree.py @@ -3,7 +3,6 @@ import os import json import signal -from itertools import product from typing import TYPE_CHECKING from collections import defaultdict @@ -12,7 +11,7 @@ from tm.show import show_comp from tm.parse import init_prog, tcompile from tm.machine import quick_term_or_rec -from tm.rust_stuff import run_for_undefined, TreeSkip +from tm.rust_stuff import run_for_undefined, TreeSkip, make_instrs if TYPE_CHECKING: from collections.abc import Callable, Iterator @@ -128,14 +127,6 @@ def handle_interrupt(_,__):# type: ignore[no-untyped-def] # no-cover ######################################## -def make_instrs(states: int, colors: int) -> list[Instr]: - return sorted( - product( - range(colors), - (False, True), - range(states))) - - class Program: prog: CompProg