feat: more scaffolding for machine and tape
This commit is contained in:
1 parent
a52c90d10b
commit
af728ec0bb
2 files changed
+33
-1
No files matched your search
@@ -2,11 +2,31 @@ use std::{collections::HashMap, num::NonZeroU8};
|
|||||||
|
|
||||||
use crate::tape::{Tape, TapeSymbol};
|
use crate::tape::{Tape, TapeSymbol};
|
||||||
|
|
||||||
|
const MAX_STATE_COUNT: u8 = 255;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct TuringMachine {
|
struct TuringMachine {
|
||||||
state_table: HashMap<(MachineState, TapeSymbol), MachineAction>,
|
state_table: HashMap<(MachineState, TapeSymbol), MachineAction>,
|
||||||
tape: Tape,
|
tape: Tape,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TuringMachine {
|
||||||
|
fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_state_entries(
|
||||||
|
state_entries: impl Iterator<Item = (MachineState, TapeSymbol, MachineAction)>,
|
||||||
|
) -> Self {
|
||||||
|
let mut machine = TuringMachine::new();
|
||||||
|
for (state, symbol, action) in state_entries {
|
||||||
|
machine.state_table.insert((state, symbol), action);
|
||||||
|
}
|
||||||
|
machine
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Eq, Hash, PartialEq)]
|
||||||
enum MachineState {
|
enum MachineState {
|
||||||
Halt,
|
Halt,
|
||||||
StateNumber(NonZeroU8),
|
StateNumber(NonZeroU8),
|
||||||
|
|||||||
+13
-1
@@ -1,6 +1,18 @@
|
|||||||
pub struct Tape {}
|
#[derive(Default)]
|
||||||
|
pub struct Tape {
|
||||||
|
left_half: Vec<TapeSymbol>,
|
||||||
|
right_half: Vec<TapeSymbol>,
|
||||||
|
head: isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Eq, Hash, PartialEq)]
|
||||||
pub enum TapeSymbol {
|
pub enum TapeSymbol {
|
||||||
Zero,
|
Zero,
|
||||||
One,
|
One,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for TapeSymbol {
|
||||||
|
fn default() -> Self {
|
||||||
|
TapeSymbol::Zero
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user