diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 685b93a..470a576 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -7,6 +7,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - run: rm rust-toolchain.toml - uses: EmbarkStudios/cargo-deny-action@v1 with: arguments: --all-features @@ -16,9 +24,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - run: rm rust-toolchain.toml - uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly + toolchain: nightly-2023-06-19 components: clippy, rust-src - run: cargo clippy --all-features -- --deny warnings code-format: @@ -26,8 +42,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - run: rm rust-toolchain.toml - uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly + toolchain: nightly-2023-06-19 components: rustfmt, rust-src - run: cargo fmt -- --check diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e4994ea..09de330 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -12,12 +12,23 @@ jobs: - macos rust: - stable - - nightly + - nightly-2023-06-19 name: Test Rust ${{ matrix.rust }} on ${{ matrix.os }} runs-on: ${{ matrix.os }}-latest steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - run: rm rust-toolchain.toml - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} + - uses: KyleMayes/install-llvm-action@v1 + with: + version: "15.0" - run: cargo test --all-features --no-fail-fast diff --git a/Cargo.toml b/Cargo.toml index cd103f5..62c6d45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "sloth" ] [workspace.package] diff --git a/flake.nix b/flake.nix index 5c82957..5143ddf 100644 --- a/flake.nix +++ b/flake.nix @@ -27,9 +27,17 @@ rustc = rustStable; }; in + let + baseNativeBuildInputs = with pkgs; [ pkg-config ]; + baseBuildInputs = with pkgs; [ + llvmPackages_15.libllvm + libffi + libxml2 + ]; + in with pkgs; { - packages.default = rustPlatform.buildRustPackage rec { + packages.default = rustPlatform.buildRustPackage { pname = "sloth"; version = "0.1.0"; src = ./.; @@ -40,14 +48,20 @@ lockFile = ./Cargo.lock; }; + nativeBuildInputs = baseNativeBuildInputs; + buildInputs = baseBuildInputs; + meta = with lib; { description = "The Sloth programming language"; homepage = "https://slothlang.tech"; license = with licenses; [ mit asl20 ]; }; + + LLVM_SYS_150_PREFIX = "${llvmPackages_15.libllvm.dev}"; }; devShells.default = mkShell { - buildInputs = [ + nativeBuildInputs = baseNativeBuildInputs; + buildInputs = baseBuildInputs ++ [ (rustNightly.override { extensions = [ "rust-src" "rust-analyzer" ]; targets = [ "wasm32-unknown-unknown" ]; @@ -57,16 +71,11 @@ cargo-deny cargo-release - pkg-config - - # Packages required for LLVM - llvmPackages_15.libllvm - libffi - libxml2 - # C compiler for debugging clang ]; + + RUST_BACKTRACE = 1; }; } ); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4e70b08..0a8868e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,5 @@ [toolchain] -channel = "nightly-2023-06-15" +channel = "nightly-2023-06-19" +components = [ "rust-src", "rust-analyzer" ] +targets = [ "wasm32-unknown-unknown" ] +profile = "default" diff --git a/sloth/src/analysis/mod.rs b/sloth/src/analysis/mod.rs index 1c2f0d2..a569c50 100644 --- a/sloth/src/analysis/mod.rs +++ b/sloth/src/analysis/mod.rs @@ -34,12 +34,26 @@ pub fn analyze(root: &mut Stmt) -> Result<(), AnalysisError> { } fn check_usage(node: &AstNode) -> Result<(), AnalysisError> { - if let AstNode::Expr(expr) = node && let ExprKind::Identifier(identifier) = &expr.kind && !expr.symtable.clone().contains(identifier) { - return Err(AnalysisError::UnknownIdentifier(expr.line, identifier.clone())); + if let AstNode::Expr(expr) = node { + if let ExprKind::Identifier(identifier) = &expr.kind { + if !expr.symtable.clone().contains(identifier) { + return Err(AnalysisError::UnknownIdentifier( + expr.line, + identifier.clone(), + )); + } + } } - if let AstNode::Stmt(stmt) = node && let StmtKind::AssignVariable { identifier, .. } = &stmt.kind && !stmt.symtable.clone().contains(identifier) { - return Err(AnalysisError::UnknownIdentifier(stmt.line, identifier.clone())); + if let AstNode::Stmt(stmt) = node { + if let StmtKind::AssignVariable { identifier, .. } = &stmt.kind { + if !stmt.symtable.clone().contains(identifier) { + return Err(AnalysisError::UnknownIdentifier( + stmt.line, + identifier.clone(), + )); + } + } } for child in node.children() { diff --git a/sloth/src/main.rs b/sloth/src/main.rs index b34dd4f..c181a3b 100644 --- a/sloth/src/main.rs +++ b/sloth/src/main.rs @@ -1,4 +1,3 @@ -#![feature(let_chains)] #![warn( clippy::wildcard_imports, clippy::string_add,