aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornic-gaffney <gaffney_nic@protonmail.com>2023-07-31 00:08:04 -0500
committernic-gaffney <gaffney_nic@protonmail.com>2023-07-31 00:08:04 -0500
commit7275a607d45d7e4f206f005584eef9ea5e331044 (patch)
tree1dc6d8ad482ed85787feccebbdbbb1aaf54bb98c
parent9b2fe27e03ae1962305f9032823e9984b2cf503c (diff)
parent7cd943581febdf20f4f0590907cfc05986453f53 (diff)
downloadsloth-7275a607d45d7e4f206f005584eef9ea5e331044.tar.gz
Merge branch 'master' of github.com-Nic:slothlang/sloth
-rw-r--r--.github/workflows/linting.yml28
-rw-r--r--.github/workflows/testing.yml22
-rw-r--r--.gitignore2
-rw-r--r--Cargo.toml1
-rw-r--r--examples/mandelbrot.sloth24
-rw-r--r--examples/webserver.html10
-rw-r--r--examples/webserver.sloth12
-rw-r--r--flake.nix29
-rw-r--r--rust-toolchain.toml5
-rw-r--r--sloth/src/analysis/mod.rs22
-rw-r--r--sloth/src/main.rs1
-rw-r--r--std/testing.sloth54
12 files changed, 172 insertions, 38 deletions
diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml
index 685b93a..473f58f 100644
--- a/.github/workflows/linting.yml
+++ b/.github/workflows/linting.yml
@@ -6,7 +6,8 @@ jobs:
name: Dependency linting
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
+ - run: rm rust-toolchain.toml
- uses: EmbarkStudios/cargo-deny-action@v1
with:
arguments: --all-features
@@ -15,19 +16,36 @@ jobs:
name: Code linting
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
+ - run: rm rust-toolchain.toml
+
+ # Cache files like by target directory
+ - uses: actions/cache@v3
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ target
+ key: ${{ runner.os }}-rustc-nightly-2023-06-19-cargo-${{ hashFiles('**/Cargo.lock') }}-linting
+
+ # Prepare toolchain related stuff
- uses: dtolnay/rust-toolchain@stable
with:
- toolchain: nightly
+ toolchain: nightly-2023-06-19
components: clippy, rust-src
+ - uses: KyleMayes/install-llvm-action@v1
+ with:
+ version: "15.0"
+
- run: cargo clippy --all-features -- --deny warnings
code-format:
name: Check formatting
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
+ - 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..ad93c36 100644
--- a/.github/workflows/testing.yml
+++ b/.github/workflows/testing.yml
@@ -8,16 +8,32 @@ jobs:
matrix:
os:
- ubuntu
- - windows
- 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/checkout@v3
+ - run: rm rust-toolchain.toml
+
+ # Cache files like by target directory
+ - uses: actions/cache@v3
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ target
+ key: ${{ runner.os }}-rustc-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
+
+ # Prepare toolchain related stuff
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
+ - uses: KyleMayes/install-llvm-action@v1
+ with:
+ version: "15.0"
+
+ - run: cargo build --all-features
- run: cargo test --all-features --no-fail-fast
diff --git a/.gitignore b/.gitignore
index 982e9ba..b9e98f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
node_modules/
*.vsix
-
+cbuild.sh
# Added by cargo
/target
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/examples/mandelbrot.sloth b/examples/mandelbrot.sloth
index c7c559a..275d32b 100644
--- a/examples/mandelbrot.sloth
+++ b/examples/mandelbrot.sloth
@@ -1,25 +1,25 @@
fn main() Int {
# Configure
- var size: Float = 1000.0;
- var maxVal: Float = 4.0;
- var maxIter: Float = 50.0;
- var plane: Float = 4.0;
+ var size = 1000.0;
+ var maxVal = 4.0;
+ var maxIter = 50.0;
+ var plane = 4.0;
# loop over coordinates
- var x: Float = 0.0;
+ var x = 0.0;
while x < size {
- var y: Float = 0.0;
+ var y = 0.0;
while y < size {
# Initialize
- var cReal: Float = (x * plane / size) - 2.0;
- var cImg: Float = (y * plane / size) - 2.0;
- var zReal: Float = 0.0;
- var zImg: Float = 0.0;
- var count: Float = 0.0;
+ var cReal = (x * plane / size) - 2.0;
+ var cImg = (y * plane / size) - 2.0;
+ var zReal = 0.0;
+ var zImg = 0.0;
+ var count = 0.0;
# Calculate
while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter {
- var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal;
+ var temp = (zReal * zReal) - (zImg * zImg) + cReal;
zImg = 2.0 * zReal * zImg + cImg;
zReal = temp;
count = count + 1.0;
diff --git a/examples/webserver.html b/examples/webserver.html
new file mode 100644
index 0000000..a934b67
--- /dev/null
+++ b/examples/webserver.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<head>
+ <title>sloth</title>
+</head>
+<html>
+ <body>
+ <h1>Sloth</h1>
+ <p>paragraph</p>
+ </body>
+</html>
diff --git a/examples/webserver.sloth b/examples/webserver.sloth
new file mode 100644
index 0000000..a0c7f17
--- /dev/null
+++ b/examples/webserver.sloth
@@ -0,0 +1,12 @@
+fn main() Int {
+ var port: Int = 8080;
+ var addr: String = "auto";
+ while true {
+ var server: Int = serversock(port, addr, 10, true);
+ sendsock("HTTP/1.0 200 OK\r\nServer: webserver-c\r\nContent-type: text/html\r\n\r\n<html>hello, world</html>\r\n", server);
+ wait(0.5);
+ closesock(server, false);
+ }
+
+ return 0;
+}
diff --git a/flake.nix b/flake.nix
index 5c82957..a4f64b4 100644
--- a/flake.nix
+++ b/flake.nix
@@ -27,27 +27,39 @@
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 = ./.;
- # FIXME: Tests do not run in release mode
- checkType = "debug";
cargoLock = {
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 +69,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,
diff --git a/std/testing.sloth b/std/testing.sloth
new file mode 100644
index 0000000..8a13283
--- /dev/null
+++ b/std/testing.sloth
@@ -0,0 +1,54 @@
+fn main() Int {
+ print("print()");
+ println("println()");
+ var read: String = readln();
+ println(read);
+ var file: String = filer("std/testing.sloth");
+ println(file);
+ curshide();
+ readln();
+ cursshow();
+ readln();
+ wait(3);
+ var sle: Int = slen("Sloth");
+ println(istr(sle));
+ var parse: Int = parse_int("45");
+ if sequals("Sloth", "Sloth") {
+ println("sequals");
+ }
+ if sequals("sloth", "Sloth") {
+ println("sequals error");
+ }
+ var asint: Int = as_int(3.0);
+ system("echo hello_echo");
+ wait(5);
+ termclear();
+ print("randGen: ");
+ println(istr(randGen(0,10)));
+ print("abs: ");
+ println(istr(abs(-5)));
+ print("fabs: ");
+ println(istr(as_int(fabs(-3.0))));
+ print("max: ");
+ println(istr(max(3, 10)));
+ print("min: ");
+ println(istr(min(3, 10)));
+ print("fmax: ");
+ println(istr(as_int(fmax(3.0, 10.0))));
+ print("fmin: ");
+ println(istr(as_int(fmin(3.0, 10.0))));
+ print("pow: ");
+ println(istr(as_int(pow(5.0, 2.0))));
+ print("floor: ");
+ println(istr(floor(3.7)));
+ print("ceil: ");
+ println(istr(ceil(3.3)));
+ print("round: ");
+ println(istr(round(3.5)));
+ print("round: ");
+ println(istr(round(3.4)));
+ print("round: ");
+ println(istr(round(3.6)));
+
+ return 0;
+}