commit a7112b3f8ef5863bfef9c781280f7903d7931d98 Author: Amneesh Singh Date: Thu Apr 6 17:05:58 2023 +0530 initial commit Signed-off-by: Amneesh Singh diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a3064e3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "tricc" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b6d5f73 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "tricc" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0192d55 --- /dev/null +++ b/flake.lock @@ -0,0 +1,160 @@ +{ + "nodes": { + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1680584903, + "narHash": "sha256-uraq+D3jcLzw/UVk0xMHcnfILfIMa0DLrtAEq2nNlxU=", + "owner": "ipetkov", + "repo": "crane", + "rev": "65d3f6a3970cd46bef5eedfd458300f72c56b3c5", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1680724564, + "narHash": "sha256-eeUUGOTKTelYKDbUxKs0V7GUa186L2fym7jM2QQ4Oss=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "36adaa6aaa6b03e59102df0c1b12cdc3f23fd112", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay_2" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1680488274, + "narHash": "sha256-0vYMrZDdokVmPQQXtFpnqA2wEgCCUXf5a3dDuDVshn0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "7ec2ff598a172c6e8584457167575b3a1a5d80d8", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1680660688, + "narHash": "sha256-XeQTCxWBR0Ai1VMzI5ZXYpA2lu1F8FzZKjw8RtByZOg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "2f40052be98347b479c820c00fb2fc1d87b3aa28", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b1b857f --- /dev/null +++ b/flake.nix @@ -0,0 +1,68 @@ +{ + description = "tricc"; + + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/release-22.11; + + crane = { + url = github:ipetkov/crane; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + rust-overlay = { + url = github:oxalica/rust-overlay; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-utils.url = github:numtide/flake-utils; + }; + + outputs = inputs@{ self, nixpkgs, crane, rust-overlay, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + + inherit (pkgs) lib; + + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + src = craneLib.cleanCargoSource (craneLib.path ./.); + + commonArgs = { inherit src; }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + tricc = craneLib.buildPackage (commonArgs // { + inherit cargoArtifacts; + }); + in + { + checks = { + inherit tricc; + + clippy = craneLib.cargoClippy (commonArgs // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + fmt = craneLib.cargoFmt { + inherit src; + }; + }; + + packages = { + inherit tricc; + default = tricc; + }; + + devShells.default = pkgs.mkShell { + nativeBuildInputs = [ toolchain ]; + }; + + formatter = pkgs.nixpkgs-fmt; + }); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..a713b91 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly-2023-04-01" +components = [ "rustfmt", "clippy", "rust-analyzer", "rust-src" ] diff --git a/src/args.rs b/src/args.rs new file mode 100644 index 0000000..a102f5b --- /dev/null +++ b/src/args.rs @@ -0,0 +1,50 @@ +use std::env; +use std::process::exit; + +const VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const CRATE: &'static str = env!("CARGO_CRATE_NAME"); + +#[derive(Default)] +struct Options { + version: bool, + file: String, +} + +// naive argument handling +pub fn handle() -> String { + let args: Vec = env::args().collect(); + + if args.len() < 2 { + println!("Usage: {} [-v] ", CRATE); + exit(0); + } + + let mut options: Options = Default::default(); + + for arg in &args[1..] { + match arg.as_str() { + "-v" | "--version" => options.version = true, + flag if flag.chars().next() == Some('-') => panic!("option {} not implemented!", flag), + file @ _ => { + if !options.file.is_empty() { + panic!("please specify only a single source file!"); + } + options.file = file.to_string(); + } + } + } + + if options.version { + println!("{} version: {}", CRATE, VERSION); + } + + if options.file.is_empty() { + if options.version { + exit(0); + } else { + panic!("no file supplied!"); + } + } + + options.file +} diff --git a/src/lexer.rs b/src/lexer.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..6e10f4a --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod args; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5b96ae2 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,5 @@ +use tricc::args; + +fn main() { + println!("Hello World!"); +}