Skip to content

Commit

Permalink
Merge branch 'main' into chore/eval-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Feb 21, 2025
2 parents 728082d + 71a6f5f commit 8e47fe8
Show file tree
Hide file tree
Showing 39 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ members = [
]

[workspace.package]
edition = "2021"
edition = "2024"
keywords = ["interpreter", "language", "scheme"]
license-file = "LICENSE"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion bench/benches/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(missing_docs)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use stak::{
device::FixedBufferDevice,
file::VoidFileSystem,
Expand Down
2 changes: 1 addition & 1 deletion bench/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod error;

use alloc::sync::Arc;
pub use error::BuildError;
use glob::{glob, Paths};
use glob::{Paths, glob};
use stak_compiler::compile_r7rs;
use std::{
env,
Expand Down
2 changes: 1 addition & 1 deletion cmd/minimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["interpret", "run"]

[workspace.package]
edition = "2021"
edition = "2024"
keywords = ["interpreter", "language", "scheme"]
license-file = "../../LICENSE"
readme = "../../README.md"
Expand Down
18 changes: 10 additions & 8 deletions cmd/minimal/interpret/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,31 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { libc::exit(1) }
}

#[cfg_attr(not(test), no_mangle)]
#[cfg_attr(not(test), unsafe(no_mangle))]
unsafe extern "C" fn main(argc: isize, argv: *const *const i8) -> isize {
let Some(&file) = &slice::from_raw_parts(argv, argc as _).get(1) else {
let Some(&file) = unsafe { slice::from_raw_parts(argv, argc as _) }.get(1) else {
return 1;
};

let heap = slice::from_raw_parts_mut(
libc::malloc(size_of::<Value>() * HEAP_SIZE) as *mut Value,
HEAP_SIZE,
);
let heap = unsafe {
slice::from_raw_parts_mut(
libc::malloc(size_of::<Value>() * HEAP_SIZE) as *mut Value,
HEAP_SIZE,
)
};

let mut vm = Vm::new(
heap,
SmallPrimitiveSet::new(
ReadWriteDevice::new(Stdin::new(), Stdout::new(), Stderr::new()),
LibcFileSystem::new(),
LibcProcessContext::new(argc, argv),
unsafe { LibcProcessContext::new(argc, argv) },
LibcClock::new(),
),
)
.unwrap();

let mmap = Mmap::new(CStr::from_ptr(file as _));
let mmap = Mmap::new(unsafe { CStr::from_ptr(file as _) });

vm.initialize(mmap.as_slice().iter().copied()).unwrap();
vm.run().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions cmd/profile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use stak_device::StdioDevice;
use stak_file::OsFileSystem;
use stak_process_context::OsProcessContext;
use stak_profiler::{
calculate_durations, calculate_flamegraph, collapse_stacks, read_records, reverse_stacks,
write_records, DurationRecord, ProcedureRecord, StackProfiler,
DurationRecord, ProcedureRecord, StackProfiler, calculate_durations, calculate_flamegraph,
collapse_stacks, read_records, reverse_stacks, write_records,
};
use stak_r7rs::SmallPrimitiveSet;
use stak_time::OsClock;
use stak_vm::Vm;
use std::{
fs::{read, OpenOptions},
io::{stdin, stdout, BufWriter},
fs::{OpenOptions, read},
io::{BufWriter, stdin, stdout},
path::PathBuf,
};

Expand Down
2 changes: 1 addition & 1 deletion device/src/device/libc/device.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{error::LibcError, Read, Write};
use super::{Read, Write, error::LibcError};
use crate::Device;

/// A device composed of objects implementing `Read` and `Write` traits.
Expand Down
2 changes: 1 addition & 1 deletion device/src/device/libc/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{error::LibcError, Read, Write};
use super::{Read, Write, error::LibcError};
use rustix::{
fd::BorrowedFd,
io,
Expand Down
2 changes: 1 addition & 1 deletion device/src/device/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Device, ReadWriteDevice};
use std::io::{stderr, stdin, stdout, Error, Stderr, Stdin, Stdout};
use std::io::{Error, Stderr, Stdin, Stdout, stderr, stdin, stdout};

/// A standard I/O device of a current process.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion dynamic/src/primitive_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl PrimitiveSet for DynamicPrimitiveSet<'_, '_> {
#[cfg(test)]
mod tests {
use super::*;
use any_fn::{r#fn, value, Ref};
use any_fn::{Ref, r#fn, value};

const HEAP_SIZE: usize = 1 << 8;

Expand Down
2 changes: 1 addition & 1 deletion engine/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion engine/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{primitive_set::EnginePrimitiveSet, EngineError};
use crate::{EngineError, primitive_set::EnginePrimitiveSet};
use any_fn::AnyFn;
use stak_dynamic::SchemeValue;
use stak_module::Module;
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-vm/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion examples/embedded-script/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion examples/embedded-script/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The pie-throwing duel.
use any_fn::{r#fn, Ref};
use any_fn::{Ref, r#fn};
use core::error::Error;
use rand::random;
use stak::{
Expand Down
2 changes: 1 addition & 1 deletion examples/hot-reload/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion examples/hot-reload/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A `stak-build` example.
use axum::{http::StatusCode, response, routing::post, serve, Router};
use axum::{Router, http::StatusCode, response, routing::post, serve};
use core::error::Error;
use stak::{
device::ReadWriteDevice,
Expand Down
2 changes: 1 addition & 1 deletion examples/no-std-no-alloc/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion file/src/file_system/libc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{utility::decode_path, FileDescriptor, FileError, FileSystem};
use super::{FileDescriptor, FileError, FileSystem, utility::decode_path};
use core::ffi::CStr;
use heapless::{FnvIndexMap, Vec};
use rustix::{
Expand Down
2 changes: 1 addition & 1 deletion file/src/file_system/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::str;
use stak_vm::{Memory, Value};
use std::{
collections::HashMap,
fs::{remove_file, File, OpenOptions},
fs::{File, OpenOptions, remove_file},
io::{self, ErrorKind, Read, Write},
path::{Path, PathBuf},
};
Expand Down
6 changes: 3 additions & 3 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use cfg_elif::expr::feature;
use core::error::Error;
use proc_macro::TokenStream;
use proc_macro2::Literal;
use quote::{quote, ToTokens};
use quote::{ToTokens, quote};
use stak_compiler::CompileError;
use stak_macro_util::{convert_result, read_source_file};
use std::path::{Path, MAIN_SEPARATOR_STR};
use syn::{parse::Parse, parse_macro_input, Ident, LitStr, Token};
use std::path::{MAIN_SEPARATOR_STR, Path};
use syn::{Ident, LitStr, Token, parse::Parse, parse_macro_input};

struct IncludeModuleInput {
path: LitStr,
Expand Down
2 changes: 1 addition & 1 deletion minifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use stak_process_context::VoidProcessContext;
use stak_r7rs::{SmallError, SmallPrimitiveSet};
use stak_time::VoidClock;
use stak_vm::Vm;
use std::io::{empty, Read, Write};
use std::io::{Read, Write, empty};

/// Minifies given source codes.
pub fn minify(reader: impl Read, writer: impl Write) -> Result<(), SmallError> {
Expand Down
2 changes: 1 addition & 1 deletion minifier_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use proc_macro::TokenStream;
use proc_macro2::Literal;
use quote::quote;
use stak_macro_util::{convert_result, read_source_file};
use syn::{parse_macro_input, LitStr};
use syn::{LitStr, parse_macro_input};

/// Minifies source codes in Scheme.
///
Expand Down
2 changes: 1 addition & 1 deletion profiler/src/record/duration_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Record, StackedRecord};
use crate::{Error, Stack, COLUMN_SEPARATOR};
use crate::{COLUMN_SEPARATOR, Error, Stack};
use core::{
fmt::{self, Display, Formatter},
str::FromStr,
Expand Down
2 changes: 1 addition & 1 deletion profiler/src/record/procedure_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Record, StackedRecord};
use crate::{Error, ProcedureOperation, Stack, COLUMN_SEPARATOR};
use crate::{COLUMN_SEPARATOR, Error, ProcedureOperation, Stack};
use core::{
fmt::{self, Display, Formatter},
str::FromStr,
Expand Down
2 changes: 1 addition & 1 deletion profiler/src/stack_profiler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ProcedureOperation, COLUMN_SEPARATOR, FRAME_SEPARATOR};
use crate::{COLUMN_SEPARATOR, FRAME_SEPARATOR, ProcedureOperation};
use stak_vm::{Cons, Memory, Profiler, StackSlot};
use std::{io::Write, time::Instant};

Expand Down
2 changes: 1 addition & 1 deletion root/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down
2 changes: 1 addition & 1 deletion sac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ macro_rules! libc_main {
unsafe { exit(1) }
}

#[cfg_attr(not(test), no_mangle)]
#[cfg_attr(not(test), unsafe(no_mangle))]
unsafe extern "C" fn main(argc: isize, argv: *const *const i8) -> isize {
let mut heap = Heap::new($heap_size, Default::default);
let mut vm = Vm::new(
Expand Down
2 changes: 1 addition & 1 deletion time/src/clock/libc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Clock;
use core::convert::Infallible;
use rustix::time::{clock_gettime, ClockId};
use rustix::time::{ClockId, clock_gettime};
use stak_vm::Number;

/// A clock based on libc.
Expand Down
2 changes: 1 addition & 1 deletion util/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::read_file_size;
use core::{ffi::CStr, ptr::null_mut, slice};
use rustix::{
fs::{self, Mode, OFlags},
mm::{mmap, munmap, MapFlags, ProtFlags},
mm::{MapFlags, ProtFlags, mmap, munmap},
};

/// A mmap.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/cons.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{value::Value, Error};
use crate::{Error, value::Value};
use cfg_elif::expr::feature;
use core::fmt::{self, Display, Formatter};

Expand Down
2 changes: 1 addition & 1 deletion vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use memory::Memory;
pub use number::{Number, NumberRepresentation};
pub use primitive_set::PrimitiveSet;
pub use profiler::Profiler;
pub use r#type::Type;
pub use stack_slot::StackSlot;
pub use r#type::Type;
pub use value::Value;
pub use vm::Vm;
10 changes: 3 additions & 7 deletions vm/src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
cons::{Cons, Tag, NEVER},
Error,
cons::{Cons, NEVER, Tag},
number::Number,
r#type::Type,
value::Value,
Error,
};
use core::fmt::{self, Display, Formatter};

Expand Down Expand Up @@ -239,11 +239,7 @@ impl<'a> Memory<'a> {
/// Returns an allocation start index.
#[inline]
pub const fn allocation_start(&self) -> usize {
if self.space {
self.space_size()
} else {
0
}
if self.space { self.space_size() } else { 0 }
}

/// Returns an allocation end index.
Expand Down
4 changes: 2 additions & 2 deletions vm/src/number.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{value::Value, Error};
use crate::{Error, value::Value};
use cfg_elif::{expr::feature, item};
use core::{
fmt::{self, Display, Formatter},
Expand All @@ -25,7 +25,7 @@ impl Number {
/// Creates a number.
#[inline]
pub const fn new(number: NumberRepresentation) -> Self {
Self(feature!(if ("float") { number } else { number << 1 | 1 }))
Self(feature!(if ("float") { number } else { (number << 1) | 1 }))
}

/// Converts a number to a number representation.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/primitive_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{memory::Memory, Error};
use crate::{Error, memory::Memory};
use core::error;

/// A primitive set.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Display for Value {
#[cfg(test)]
mod tests {
use super::*;
use crate::{cons::NEVER, Type};
use crate::{Type, cons::NEVER};

#[test]
fn convert_cons() {
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(feature = "profile")]
use crate::profiler::Profiler;
use crate::{
Error, StackSlot,
code::{INTEGER_BASE, NUMBER_BASE, SHARE_BASE, TAG_BASE},
cons::{Cons, NEVER},
instruction::Instruction,
Expand All @@ -9,7 +10,6 @@ use crate::{
primitive_set::PrimitiveSet,
r#type::Type,
value::{TypedValue, Value},
Error, StackSlot,
};
#[cfg(feature = "profile")]
use core::cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion wasm/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A build script.
use stak_build::{build_r7rs, BuildError};
use stak_build::{BuildError, build_r7rs};

fn main() -> Result<(), BuildError> {
build_r7rs()
Expand Down

0 comments on commit 8e47fe8

Please sign in to comment.