Skip to content

Commit

Permalink
Port make_instrs
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Jun 7, 2024
1 parent dc86ec4 commit e0999c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
}
25 changes: 24 additions & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instr> {
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]
Expand Down
2 changes: 2 additions & 0 deletions tm/rust_stuff.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
11 changes: 1 addition & 10 deletions tm/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import json
import signal
from itertools import product
from typing import TYPE_CHECKING
from collections import defaultdict

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e0999c5

Please sign in to comment.