Skip to content

Commit

Permalink
Add comp_thic
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Mar 26, 2024
1 parent effb1cf commit c5bab19
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/instrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub type Slot = (State, Color);
pub type Instr = (Color, Shift, State);

pub type CompThin = HashMap<Slot, Instr>;
pub type CompThic = HashMap<Slot, Option<Instr>>;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod rust_stuff {

#[pymodule_export]
use crate::parse::{
comp_thin, init_prog, parse_to_vec, read_slot, show_instr, show_slot, show_state,
comp_thic, comp_thin, init_prog, parse_to_vec, read_slot, show_instr, show_slot, show_state,
};

#[pymodule_export]
Expand Down
15 changes: 14 additions & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pyo3::prelude::*;

use crate::instrs::{Color, CompThin, Instr, Shift, Slot, State};
use crate::instrs::{Color, CompThic, CompThin, Instr, Shift, Slot, State};

const UNDF: char = '.';

Expand Down Expand Up @@ -33,6 +33,19 @@ pub fn comp_thin(prog: &str) -> CompThin {
program
}

#[pyfunction]
pub fn comp_thic(prog: &str) -> CompThic {
let mut program = CompThic::new();

for (state, instrs) in parse(prog).enumerate() {
for (color, instr) in instrs.enumerate() {
program.insert((state as State, color as Color), instr);
}
}

program
}

/**************************************/

fn read_color(color: char) -> Color {
Expand Down
2 changes: 2 additions & 0 deletions tm/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tm.rust_stuff import (
parse_to_vec as parse,
comp_thin,
comp_thic,
read_slot,
init_prog,
)
Expand All @@ -18,6 +19,7 @@
Instr = tuple[Color, Shift, State]

CompThin = dict[Slot, Instr]
CompThic = dict[Slot, Instr | None]

Switch = dict[Color, Instr | None]

Expand Down
3 changes: 3 additions & 0 deletions tm/rust_stuff.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ Slot = tuple[State, Color]
Instr = tuple[Color, Shift, State]

CompThin = dict[Slot, Instr]
CompThic = dict[Slot, Instr | None]

LetterState = str

def parse_to_vec(program: str) -> list[list[Instr | None]]: ...

def comp_thin(program: str) -> CompThin: ...

def comp_thic(program: str) -> CompThic: ...

def halt_slots(prog: str) -> list[Slot]: ...

def erase_slots(prog: str) -> list[Slot]: ...
Expand Down

0 comments on commit c5bab19

Please sign in to comment.