Skip to content

Commit

Permalink
Merge branch 'master' of github.com-Nic:slothlang/sloth
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-gaffney committed Jul 31, 2023
2 parents 9b2fe27 + 7cd9435 commit 7275a60
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 38 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 19 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules/
*.vsix

cbuild.sh
# Added by cargo

/target
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [ "sloth" ]

[workspace.package]
Expand Down
24 changes: 12 additions & 12 deletions examples/mandelbrot.sloth
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 10 additions & 0 deletions examples/webserver.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<head>
<title>sloth</title>
</head>
<html>
<body>
<h1>Sloth</h1>
<p>paragraph</p>
</body>
</html>
12 changes: 12 additions & 0 deletions examples/webserver.sloth
Original file line number Diff line number Diff line change
@@ -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;
}
29 changes: 18 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand All @@ -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;
};
}
);
Expand Down
5 changes: 4 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 18 additions & 4 deletions sloth/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion sloth/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(let_chains)]
#![warn(
clippy::wildcard_imports,
clippy::string_add,
Expand Down
54 changes: 54 additions & 0 deletions std/testing.sloth
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 7275a60

Please sign in to comment.