From d4b6c134f963d26ba0cc469a022673b0d71eaf8c Mon Sep 17 00:00:00 2001 From: Leonhard Kost Date: Sun, 8 Nov 2026 12:52:04 +0100 Subject: [PATCH] chore: initial commit --- .gitignore | 1 + Cargo.lock | 7 ++++ Cargo.toml | 6 ++++ flake.lock | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 40 +++++++++++++++++++++ src/lib.rs | 2 ++ src/machine.rs | 24 +++++++++++++ src/tape.rs | 6 ++++ 8 files changed, 182 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/lib.rs create mode 100644 src/machine.rs create mode 100644 src/tape.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a0150e7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "turing_machine" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fa005f6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "turing_machine" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c013026 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1791594108, + "narHash": "sha256-XK4KceonkwD8LuMAt/vNrz982mXJM5jeHAxMwsUXXAQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6510408d147d8c5e6d76043e899e9251756f6a75", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1791707771, + "narHash": "sha256-w3m8HtAVCfGTHw+gcCTAy7jFHSdGbokm8NngbeFrkek=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c1cfa7a2c809d364ac1a7e9b3ec418afa3f19793", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0b3932e --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "implementation of gzip"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + rust-overlay, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + + rustToolchain = pkgs.rust-bin.stable.latest.default.override { + extensions = [ + "rust-src" + "rust-analyzer" + "clippy" + "rustfmt" + ]; + }; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ + rustToolchain + ]; + }; + } + ); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..1dcb265 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +mod machine; +mod tape; diff --git a/src/machine.rs b/src/machine.rs new file mode 100644 index 0000000..f889324 --- /dev/null +++ b/src/machine.rs @@ -0,0 +1,24 @@ +use std::{collections::HashMap, num::NonZeroU8}; + +use crate::tape::{Tape, TapeSymbol}; + +struct TuringMachine { + state_table: HashMap<(MachineState, TapeSymbol), MachineAction>, + tape: Tape, +} + +enum MachineState { + Halt, + StateNumber(NonZeroU8), +} + +struct MachineAction { + tape_write: TapeSymbol, + movement: MachineMovement, + new_state: MachineState, +} + +enum MachineMovement { + Left, + Right, +} diff --git a/src/tape.rs b/src/tape.rs new file mode 100644 index 0000000..2bf822c --- /dev/null +++ b/src/tape.rs @@ -0,0 +1,6 @@ +pub struct Tape {} + +pub enum TapeSymbol { + Zero, + One, +}