Skip to content

Commit

Permalink
Merge pull request #15 from FL03/v0.0.4
Browse files Browse the repository at this point in the history
v0.0.4
  • Loading branch information
FL03 authored Sep 9, 2024
2 parents 037db9e + 75cec5d commit 5dae9ef
Show file tree
Hide file tree
Showing 68 changed files with 3,198 additions and 1,772 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: [FL03]
github: [ FL03 ]
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
interval: monthly
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
interval: monthly
- package-ecosystem: cargo
directory: /rstm
schedule:
interval: weekly
- package-ecosystem: cargo
directory: /rstm-core
directory: /core
schedule:
interval: weekly
32 changes: 4 additions & 28 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ concurrency:

env:
BASENAME: ${{ github.event.repository.name }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
CARGO_TERM_COLOR: always

on:
Expand All @@ -19,43 +20,18 @@ jobs:
base:
env:
CRATE_NAME: ${{ github.event.repository.name }}-${{ matrix.suffix }}
name: Publish (${{ matrix.suffix }})
name: Publish Base Modules
runs-on: ubuntu-latest
strategy:
matrix:
suffix: [ core ]
steps:
- uses: actions/checkout@v4
- name: cache
uses: actions/cache@v4
with:
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
path: |
~/.cargo/registry
~/.cargo/git
target/debug
target/release
restore-keys: |
cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
cargo-${{ runner.os }}-
cargo-
- run: cargo publish --all-features -v -p ${{ env.CRATE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- run: cargo publish --all-features -v -p ${{ env.CRATE_NAME }}
publish:
name: Publish (${{ github.event.repository.name }})
name: Publish SDK
needs: base
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: cache
uses: actions/cache@v4
with:
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
path: |
~/.cargo/registry
~/.cargo/git
target/release
restore-keys: |
cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
cargo-${{ runner.os }}-
cargo-
- run: cargo publish --all-features -v -p ${{ github.event.repository.name }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
34 changes: 15 additions & 19 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ env:

on:
pull_request:
branches: [ main ]
push:
tags: [ v*.*.* ]
branches: [ main, v*.*.* ]
release:
types: [ published ]
types: [ created ]
repository_dispatch:
types: [ rust ]
schedule:
Expand All @@ -28,33 +26,31 @@ jobs:
name: Build
strategy:
matrix:
platform: [ ubuntu-latest ]
platform: [ macos-latest, ubuntu-latest, windows-latest ]
toolchain: [ stable, nightly ]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: setup (rustup)
- name: rustup
run: |
rustup default ${{ matrix.toolchain }}
rustup update
- name: build (workspace)
- name: build
run: cargo build --all-features -r -v --workspace
- name: cache
uses: actions/cache@v4
- name: test
run: cargo test -v --workspace -F full
- name: benchmark
if: matrix.toolchain == 'nightly'
run: cargo bench -F full -v --workspace
- uses: actions/cache@v4
with:
key: cargo-${{ matrix.toolchain }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
path: |
~/.cargo/registry
~/.cargo/git
target/debug
target/release
restore-keys: |
cargo-${{ matrix.toolchain }}-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
cargo-${{ matrix.toolchain }}-${{ runner.os }}-
cargo-${{ matrix.toolchain }}-
- name: cargo test (workspace) --full
run: cargo test -v --workspace -F full
- name: cargo (bench)
if: matrix.toolchain == 'nightly'
run: cargo bench -F full -v --workspace

${{ runner.os }}-cargo-${{ matrix.toolchain }}-
${{ runner.os }}-cargo-
${{ runner.os }}-
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ keywords = [ "turing", "turing-machine", "utm" ]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/FL03/rstm.git"
version = "0.0.3"
version = "0.0.4"

[profile.dev]
opt-level = 0
Expand Down
71 changes: 45 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# rstm


[![license](https://img.shields.io/crates/l/rstm.svg)](https://crates.io/crates/rstm)
[![crates.io](https://img.shields.io/crates/v/rstm.svg)](https://crates.io/crates/rstm)
[![docs.rs](https://docs.rs/rstm/badge.svg)](https://docs.rs/rstm)

[![clippy](https://github.com/FL03/rstm/actions/workflows/clippy.yml/badge.svg)](https://github.com/FL03/rstm/actions/workflows/clippy.yml)
[![rust](https://github.com/FL03/rstm/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/rstm/actions/workflows/rust.yml)

[![license](https://img.shields.io/crates/l/rstm.svg)](https://crates.io/crates/rstm)
[![lines of code](https://tokei.rs/b1/github/FL03/rstm?category=code)](https://tokei.rs/b1/github/FL03/rstm?category=code)

***

_**The library is currently in the early stages of development and is still settling in on a feel for the api.**_

This library focuses on building concrete implementations for Turing Machines.
Welcome to `rstm`! This crate provides a simple and easy-to-use interface for creating and executing Turing machines. The crate is designed to be flexible and extensible, allowing developers to create and execute a wide range of Turing machines. Furthermore, the crate focuses on efficiency and leverages feature-gating to reduce overhead.

## Getting Started

Expand All @@ -33,17 +31,19 @@ cargo build --all-features --workspace
#### _Run an example_

```bash
cargo run -f F --example actor
cargo run -f F --example {actor}
```

## Usage

### Creating a new ruleset
### Rulesets

Programs are essentially collections of rules that define the behavior of the machine. Facilitating the creation of these rules is the `ruleset!` macro. The macro allows developers to define a set of rules for the machine in a concise and readable manner while further emulating the transition function defined by "On topological dynamics of Turing machines" by Petr Kůrka; `δ: Q x A -> Q x A x {-1, 0, 1}.`
To faciliate the creation of rules for the machine, the crate provides a `ruleset!` macro. The macro mimics the
structure of the transition function $\delta$ defined by "On topological dynamics of Turing machines" by Petr Kůrka.

$$\delta : Q\times{A}\rarr{Q\times{A}\times{(0, \pm{1})}}$$

`ruleset!` is a macro that allows you to define a set of rules for the machine. The syntax is as follows:
The syntax of the macro is as follows:

```rust
ruleset![
Expand All @@ -52,11 +52,37 @@ Programs are essentially collections of rules that define the behavior of the ma
]
```

The macro is hygenic, meaning developers will not need to import the `Direction` enum nor its variants in order to use the macro.
The macro expands into a `Vec<Rule>` where `Rule` is structure consisting of two other structures, namely: `Head<Q, S>` and the `Tail<Q, S>`. Each of these structures is a direct representation of the two sides of the transition function defined above

#### _Rules_

```rust
pub struct Rule<Q, S> {
pub head: Head<Q, S>,
pub tail: Tail<Q, S>,
}
```

#### Example: Building a ruleset for a three-state, two-symbol Turing machine
where `Head` and `Tail` are defined as follows:

```rust
pub struct Head<Q, S> {
pub state: Q,
pub symbol: S,
}

pub struct Tail<Q, S> {
pub direction: Direction,
pub state: Q,
pub symbol: S,
}
```

**Note:** the macro is hygenic, meaning developers will not need to import the `Direction` enum nor its variants in order to use the macro.

#### _Example usage_

The following example demonstrates the use of the `ruleset!` macro to define a set of rules for a three-state, two-symbol Turing machine.

```rust
use rstm::ruleset;
Expand All @@ -74,18 +100,19 @@ The macro is hygenic, meaning developers will not need to import the `Direction`

### Examples

#### _Executing a program using an `Actor`_

```rust
extern crate rstm;

use rstm::{ruleset, Actor, Program, State};

fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt().with_target(false).init();

// initialize the tape data
let alpha = vec![0i8; 10];
let alpha = vec![0u8; 10];
// initialize the state of the machine
let initial_state = State(0);
let initial_state = State::<isize>::default();
// define the ruleset for the machine
let rules = ruleset![
(0, 0) -> Right(1, 0),
Expand All @@ -95,14 +122,11 @@ The macro is hygenic, meaning developers will not need to import the `Direction`
(-1, 0) -> Left(0, 0),
(-1, 1) -> Left(1, 1),
];

let program = Program::new()
.initial_state(initial_state)
.rules(rules)
.build();

// create a new program from the ruleset
let program = Program::from_iter(rules);
// create a new instance of the machine
let tm = dbg!(Actor::from_state(initial_state).with_tape(alpha));
let tm = dbg!(Actor::new(alpha, initial_state, 0));
// execute the program
tm.execute(program).run()?;
Ok(())
}
Expand All @@ -111,8 +135,3 @@ The macro is hygenic, meaning developers will not need to import the `Direction`
## Contributing

Pull requests are welcome. Any improvements or modifactions should first be disccussed using a pull-request and/or by opening an issue. Additionally, please make sure to update tests as appropriate and to adhear to the feature gates.

## License

* [Apache-2.0](https://choosealicense.com/licenses/apache-2.0/)
* [MIT](https://choosealicense.com/licenses/mit/)
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 18 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version.workspace = true

[features]
default = [
"alloc",
"std",
]

full = [
Expand Down Expand Up @@ -44,18 +44,30 @@ tracing = [
]

# ********* [FF] Environments *********
# std = [
# "alloc",
# "serde?/std",
# "strum/std",
# ]
std = [
"alloc",
"serde?/std",
"strum/std",
]

[lib]
bench = true
crate-type = ["cdylib", "rlib"]
doctest = false
test = true

[[test]]
name = "actor"
required-features = ["alloc"]

[[test]]
name = "rules"
required-features = ["alloc"]

[[test]]
name = "tape"
required-features = ["alloc"]

[dependencies]
thiserror.workspace = true
paste.workspace = true
Expand Down
Loading

0 comments on commit 5dae9ef

Please sign in to comment.