Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ categories = [
description = "This crate focuses on building concrete implementations for Turing Machines."
edition = "2024"
homepage = "https://github.com/FL03/rstm/wiki"
keywords = ["turing machine", "tm", "fsm", "computation"]
keywords = ["turing-machine", "tm", "fsm", "computation"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/FL03/rstm.git"
rust-version = "1.91.0"
version = "0.1.4"
version = "0.1.5"

[workspace.dependencies]
# local
rstm = { default-features = false, path = "crates/rstm", version = "0.1.4" }
rstm-core = { default-features = false, path = "crates/core", version = "0.1.4" }
rstm-macros = { default-features = false, path = "crates/macros", version = "0.1.4" }
rstm-state = { default-features = false, path = "crates/state", version = "0.1.4" }
rstm-tape = { default-features = false, path = "crates/tape", version = "0.1.4" }
rstm-traits = { default-features = false, path = "crates/traits", version = "0.1.4" }
rstm = { default-features = false, path = "crates/rstm", version = "0.1.5" }
rstm-core = { default-features = false, path = "crates/core", version = "0.1.5" }
rstm-macros = { default-features = false, path = "crates/macros", version = "0.1.5" }
rstm-state = { default-features = false, path = "crates/state", version = "0.1.5" }
rstm-tape = { default-features = false, path = "crates/tape", version = "0.1.5" }
rstm-traits = { default-features = false, path = "crates/traits", version = "0.1.5" }
# custom
contained = { default-features = false, features = ["macros"], version = "0.2.3" }
rspace-traits = { default-features = false, version = "0.0.9" }
Expand Down
14 changes: 13 additions & 1 deletion crates/core/src/programs/impls/imp_program_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,24 @@ where
{
self.rules().get(head)
}

/// given a state and symbol, returns the corresponding tail if it exists within the
/// ruleset
pub fn find_tail(&self, state: State<&Q>, sym: &A) -> Option<&Tail<Q, A>>
where
R: Ruleset<Q, A>,
R::Rule: Instruction<Q, A, Head = Head<Q, A>, Tail = Tail<Q, A>>,
{
self.rules().find_tail(state, sym)
}
/// returns the number of rules within the ruleset
pub fn len(&self) -> usize
{
self.rules().len()
}
/// returns true if the ruleset is considered empty (i.e. contains no rules),
/// otherwise false.
pub fn is_empty(&self) -> bool
{
self.rules().is_empty()
}
}
113 changes: 110 additions & 3 deletions crates/core/src/programs/traits/ruleset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,27 @@ where
type Rule: Instruction<Q, A>;

private! {}

fn len(&self) -> usize;

fn is_empty(&self) -> bool {
self.len() == 0
}
}

pub trait Ruleset<Q, A>: RawRuleset<Q, A>
where
Q: RawState,
Self::Rule: Instruction<Q, A, Head = Head<Q, A>, Tail = Tail<Q, A>>,
{
fn get(&self, head: &Head<Q, A>) -> Option<&Tail<Q, A>>;

fn find_tail(&self, state: State<&Q>, sym: &A) -> Option<&Tail<Q, A>>;

fn get(&self, head: &Head<Q, A>) -> Option<&Tail<Q, A>>;

fn find_head(&self, Head { state, symbol }: Head<&Q, &A>) -> Option<&Tail<Q, A>> {
self.find_tail(state, symbol)
}
}

pub trait RuleSetMut<Q, A>: RawRuleset<Q, A>
Expand All @@ -47,6 +58,10 @@ where
type Rule = R::Rule;

seal! {}

fn len(&self) -> usize {
(*self).len()
}
}

macro_rules! get_tail {
Expand Down Expand Up @@ -81,6 +96,14 @@ where
type Rule = I;

seal! {}

fn len(&self) -> usize {
<[I]>::len(self)
}

fn is_empty(&self) -> bool {
<[I]>::is_empty(self)
}
}

impl<I, Q, A> Ruleset<Q, A> for [I]
Expand All @@ -105,6 +128,14 @@ where
type Rule = I;

seal! {}

fn len(&self) -> usize {
<[I]>::len(self)
}

fn is_empty(&self) -> bool {
<[I]>::is_empty(self)
}
}

impl<I, Q, A> Ruleset<Q, A> for &[I]
Expand All @@ -130,6 +161,14 @@ where
type Rule = I;

seal! {}

fn len(&self) -> usize {
<[I]>::len(self)
}

fn is_empty(&self) -> bool {
<[I]>::is_empty(self)
}
}

impl<I, Q, A> Ruleset<Q, A> for &mut [I]
Expand Down Expand Up @@ -172,6 +211,14 @@ where
type Rule = I;

seal! {}

fn len(&self) -> usize {
<[I]>::len(self)
}

fn is_empty(&self) -> bool {
<[I]>::is_empty(self)
}
}

impl<const N: usize, I, Q, A> Ruleset<Q, A> for [I; N]
Expand Down Expand Up @@ -205,6 +252,14 @@ mod impl_alloc {
type Rule = I;

seal! {}

fn len(&self) -> usize {
<Vec<I>>::len(self)
}

fn is_empty(&self) -> bool {
<Vec<I>>::is_empty(self)
}
}

impl<I, Q, A> Ruleset<Q, A> for Vec<I>
Expand All @@ -228,7 +283,16 @@ mod impl_alloc {
I: Instruction<Q, A>,
{
type Rule = I;

seal! {}

fn len(&self) -> usize {
<BTreeSet<I>>::len(self)
}

fn is_empty(&self) -> bool {
<BTreeSet<I>>::is_empty(self)
}
}

impl<I, Q, A> Ruleset<Q, A> for BTreeSet<I>
Expand All @@ -254,7 +318,16 @@ mod impl_alloc {
type Rule = Rule<Q, A>;

seal! {}

fn len(&self) -> usize {
<BTreeMap<Head<Q, A>, Tail<Q, A>>>::len(self)
}

fn is_empty(&self) -> bool {
<BTreeMap<Head<Q, A>, Tail<Q, A>>>::is_empty(self)
}
}

impl<Q, A> Ruleset<Q, A> for BTreeMap<Head<Q, A>, Tail<Q, A>>
where
Q: RawState + Ord,
Expand Down Expand Up @@ -282,14 +355,23 @@ mod impl_hashbrown {
use core::hash::Hash;
use hashbrown::{HashMap, HashSet};

impl<Q, A> RawRuleset<Q, A> for HashSet<Rule<Q, A>>
impl<I, Q, A> RawRuleset<Q, A> for HashSet<I>
where
I: Instruction<Q, A>,
Q: RawState + Eq + Hash,
A: Eq + Hash,
{
type Rule = Rule<Q, A>;

seal! {}

fn len(&self) -> usize {
<HashSet<I>>::len(self)
}

fn is_empty(&self) -> bool {
<HashSet<I>>::is_empty(self)
}
}

impl<Q, A> Ruleset<Q, A> for HashSet<Rule<Q, A>>
Expand All @@ -314,6 +396,14 @@ mod impl_hashbrown {
type Rule = Rule<Q, A>;

seal! {}

fn len(&self) -> usize {
<HashMap<Head<Q, A>, Tail<Q, A>>>::len(self)
}

fn is_empty(&self) -> bool {
<HashMap<Head<Q, A>, Tail<Q, A>>>::is_empty(self)
}
}

impl<Q, A> Ruleset<Q, A> for HashMap<Head<Q, A>, Tail<Q, A>>
Expand Down Expand Up @@ -343,14 +433,23 @@ mod impl_std {
use core::hash::Hash;
use std::collections::{HashMap, HashSet};

impl<Q, A> RawRuleset<Q, A> for HashSet<Rule<Q, A>>
impl<I, Q, A> RawRuleset<Q, A> for HashSet<I>
where
I: Instruction<Q, A>,
Q: RawState + Eq + Hash,
A: Eq + Hash,
{
type Rule = Rule<Q, A>;

seal! {}

fn len(&self) -> usize {
<HashSet<I>>::len(self)
}

fn is_empty(&self) -> bool {
<HashSet<I>>::is_empty(self)
}
}

impl<Q, A> Ruleset<Q, A> for HashSet<Rule<Q, A>>
Expand All @@ -375,6 +474,14 @@ mod impl_std {
type Rule = Rule<Q, A>;

seal! {}

fn len(&self) -> usize {
<HashMap<Head<Q, A>, Tail<Q, A>>>::len(self)
}

fn is_empty(&self) -> bool {
<HashMap<Head<Q, A>, Tail<Q, A>>>::is_empty(self)
}
}

impl<Q, A> Ruleset<Q, A> for HashMap<Head<Q, A>, Tail<Q, A>>
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let
};

common = {
version = "0.1.4";
version = "0.1.5";
src = self;

cargoLock = {
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
in rec {
packages.default = pkgs.rustPlatform.buildRustPackage {
pname = "rstm";
version = "0.1.4";
version = "0.1.5";
src = self; # ./.;
cargoLock = { lockFile = ./Cargo.lock; };
};
Expand Down