Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
name: CI

on:
push: {}
on: [push, pull_request]

jobs:
bazel:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Mount build cache
uses: actions/cache@v1
with:
path: "target"
key: slang-cache

- name: Test
uses: actions-rs/cargo@v1
with:
command: test

- name: Lint
uses: actions-rs/cargo@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
command: clippy
args: --all-features
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo test
- run: cargo clippy --all-features -- -D warnings
23 changes: 11 additions & 12 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
run: cargo tarpaulin --out xml
env:
RUST_LOG: trace
with:
version: '0.9.0'
args: '-- --test-threads 1'

- name: Upload to codecov.io
uses: codecov/codecov-action@v1.0.7
uses: codecov/codecov-action@v5

- name: Archive code coverage results
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: cobertura.xml
path: cobertura.xml
40 changes: 0 additions & 40 deletions .github/workflows/release.yml

This file was deleted.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "3"
members = [
"argot",
"assembler",
Expand Down
12 changes: 6 additions & 6 deletions argot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "argot"
version = "0.1.2"
authors = ["William Dussault <dalloriam@gmail.com>"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -15,12 +15,12 @@ name = "argot"
path = "src/argot/lib.rs"

[dependencies]
anyhow = "1.0"
clap = {version = "4.0.18", features = ["derive"]}
anyhow = "1"
clap = {version = "4", features = ["derive"]}

assembler = {path = "../assembler"}
env_logger = "0.9"
log = {version = "0.4.8", features = ["std"]}
env_logger = "0.11"
log = {version = "0.4", features = ["std"]}
instructor = {path = "../instructor"}
nom = "7"
snafu = "0.7.0"
snafu = "0.8"
2 changes: 2 additions & 0 deletions argot/src/argot/compiler/first_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use crate::syntax::types::{Argument, FunctionDeclaration, Program};

#[derive(Clone, Debug)]
pub struct FunctionDecl {
#[allow(dead_code)]
pub name: String,
pub arguments: Vec<Argument>,
#[allow(dead_code)]
pub return_type: String,
}

Expand Down
8 changes: 4 additions & 4 deletions argot/src/argot/compiler/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ impl Iterator for LabelGenerator {
type Item = String;

fn next(&mut self) -> Option<Self::Item> {
if self.current_count != 0 && self.current_count % ASCII_LOWERCASE.len() == 0 {
if self.current_count != 0 && self.current_count.is_multiple_of(ASCII_LOWERCASE.len()) {
let prefix = if let Some(x) = self.sub_endless.as_mut() {
x.next().unwrap()
} else {
let mut gen = Box::new(LabelGenerator::new());
let prefix = gen.next().unwrap();
self.sub_endless = Some(gen);
let mut generator = Box::new(LabelGenerator::new());
let prefix = generator.next().unwrap();
self.sub_endless = Some(generator);
prefix
};

Expand Down
2 changes: 1 addition & 1 deletion argot/src/argot/compiler/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Variable {

impl cmp::PartialOrd for Variable {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
Some(self.offset.cmp(&other.offset))
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion argot/src/argot/compiler/second_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl Visitor for SecondPassVisitor {

fn visit_program(&mut self, v: &mut Program) -> Self::Result {
let mut function_keys: Vec<String> =
v.functions.iter().map(|(key, _v)| key.clone()).collect();
v.functions.keys().cloned().collect();
function_keys.sort();

for fn_name in function_keys.into_iter() {
Expand Down
10 changes: 5 additions & 5 deletions argot/src/argot/syntax/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ pub enum FactorOperator {
Unknown, // TODO: Get more detail.
}

impl ToString for FactorOperator {
fn to_string(&self) -> String {
impl std::fmt::Display for FactorOperator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FactorOperator::Div => String::from("/"),
FactorOperator::Mult => String::from("*"),
FactorOperator::Unknown => String::from("IGL"),
FactorOperator::Div => write!(f, "/"),
FactorOperator::Mult => write!(f, "*"),
FactorOperator::Unknown => write!(f, "IGL"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion argot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {

let root = cli::CLIRoot::parse();
if let Err(e) = root.run() {
log::error!("{}", e.to_string());
log::error!("{}", e);
}
}
8 changes: 4 additions & 4 deletions assembler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
name = "assembler"
version = "0.1.0"
authors = ["William Dussault <dalloriam@gmail.com>"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
byteorder = "1.3"
byteorder = "1.5"
instructor = {path = "../instructor"}
log = {version = "0.4.8", features = ["std"]}
log = {version = "0.4", features = ["std"]}
nom = "7"
snafu = "0.7.0"
snafu = "0.8"
4 changes: 2 additions & 2 deletions instructor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
name = "instructor"
version = "0.1.0"
authors = ["William Dussault <dalloriam@gmail.com>"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
byteorder = "1.3"
byteorder = "1.5"
2 changes: 1 addition & 1 deletion instructor/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Instruction {
// Write all instructions to the stream & gather byte count.
let cur_size = &[&self.operand_1, &self.operand_2, &self.operand_3]
.iter()
.map(|op| Instruction::write_operand(*op, w, converter))
.map(|op| Instruction::write_operand(op, w, converter))
.sum::<usize>();
debug_assert_eq!(self.opcode.as_ref().unwrap().width() - 1, *cur_size as u16);
}
Expand Down
22 changes: 9 additions & 13 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
build +args="":
cargo build {{args}}
cargo build {{ args }}

_clippy target:
@cd {{target}} && cargo check && cargo clippy
@cd {{ target }} && cargo check && cargo clippy

doc target +args="":
@cd {{target}} && cargo doc {{args}}
@cd {{ target }} && cargo doc {{ args }}

lint:
@just _clippy argot
@just _clippy slang-cli
@just _clippy vm
@just _clippy instructor
@just _clippy assembler
@cargo clippy --workspace

release:
@just build --release
Expand All @@ -21,16 +17,16 @@ test:
cargo nextest run

argotc +args="":
@cargo run --bin argotc -- {{args}}
@cargo run --bin argotc -- {{ args }}

gtr f:
@cargo run --bin argotc -- --asm {{f}}
@cargo run --bin argotc -- {{f}}
@cargo run --bin argotc -- --asm {{ f }}
@cargo run --bin argotc -- {{ f }}
@just trace -f ./a.out
@rm ./a.out

run +args="":
@cargo run --bin slang -- {{args}}
@cargo run --bin slang -- {{ args }}

trace +args="":
@RUST_LOG=trace just run {{args}}
@RUST_LOG=trace just run {{ args }}
8 changes: 4 additions & 4 deletions slang-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
name = "slang"
version = "0.1.2"
authors = ["William Dussault <dalloriam@gmail.com>"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
anyhow = "1"
clap = {version = "4", features = ["derive"]}

assembler = {path = "../assembler"}
env_logger = "0.9"
env_logger = "0.11"
instructor = {path = "../instructor"}
log = {version = "0.4.8", features = ["std", "release_max_level_error", "max_level_trace"]}
log = {version = "0.4", features = ["std", "release_max_level_error", "max_level_trace"]}
vm = {path = "../vm"}
2 changes: 1 addition & 1 deletion slang-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl CLIRoot {
match self.file.as_ref() {
Some(f) => {
// Compile & load the program, and start the VM.
let program = load_program(&f)?;
let program = load_program(f)?;
let mut vm = VM::new();
vm.load_bytecode(program)?;
vm.run();
Expand Down
10 changes: 5 additions & 5 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ name = "vm"
description = "The Slang virtual machine runtime."
version = "0.1.0"
authors = ["William Dussault <dalloriam@gmail.com>"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dev-dependencies]
assembler = {path = "../assembler"}
criterion = "0.4"
criterion = "0.5"

[[bench]]
name = "bench"
harness = false

[dependencies]
byteorder = "1.3"
byteorder = "1.5"
instructor = {path = "../instructor"}
log = {version = "0.4.8", features = ["std"]}
snafu = "0.7.0"
log = {version = "0.4", features = ["std"]}
snafu = "0.8"
3 changes: 2 additions & 1 deletion vm/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl Header {
}

pub struct Program {
#[allow(dead_code)]
pub header: Header,
pub ro_block: Vec<u8>,
pub program_text: Vec<u8>,
Expand All @@ -39,7 +40,7 @@ impl Program {
let header = Header::from_bytes(&data[0..ELIS_HEADER_LENGTH])?;

ensure!(
(header.ro_block_size + ELIS_HEADER_LENGTH) as usize <= data.len(),
(header.ro_block_size + ELIS_HEADER_LENGTH) <= data.len(),
ReadOnlySectionTooLongSnafu
);
Comment on lines 42 to 45

Copilot AI Feb 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header.ro_block_size + ELIS_HEADER_LENGTH can overflow on 32-bit (and will panic in debug or wrap in release), which can bypass this length check and later cause slicing panics when parsing untrusted bytecode. Consider using checked_add (and failing with ReadOnlySectionTooLong) before comparing against data.len() and before computing the slice bounds.

Copilot uses AI. Check for mistakes.

Expand Down
2 changes: 1 addition & 1 deletion vm/src/memutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const WORD_WIDTH: usize = mem::size_of::<usize>();
/// ```
#[inline]
pub fn align(i: usize) -> usize {
((i + WORD_WIDTH - 1) / WORD_WIDTH) * WORD_WIDTH
i.div_ceil(WORD_WIDTH) * WORD_WIDTH
}

#[cfg(test)]
Expand Down
Loading