diff --git a/src/compile.rs b/src/compile.rs index 8d8bff27..b0a489f2 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -2,11 +2,9 @@ mod include_files; pub use include_files::*; -use std::{ - collections::{BTreeMap, BTreeSet}, - fmt::Write, - hash::{DefaultHasher, Hasher}, -}; +use alloc::collections::{BTreeMap, BTreeSet}; +use core::{fmt::Write, hash::Hasher}; +use std::hash::DefaultHasher; use crate::prelude::*; use hvm64_host::Host; diff --git a/src/main.rs b/src/main.rs index cd7c30e4..14a6d53f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,13 +5,19 @@ mod compile; mod args; mod full; +use crate::prelude::*; + +use core::time::Duration; use std::{ - env::consts::{DLL_PREFIX, DLL_SUFFIX}, + env::{ + self, + consts::{DLL_PREFIX, DLL_SUFFIX}, + }, ffi::OsStr, fs, io, path::PathBuf, process::{self, Stdio}, - time::{Duration, Instant}, + time::Instant, }; use self::full::{CliMode, FullCli}; @@ -21,12 +27,13 @@ use clap::Parser; use hvm64_ast::{Book, Net, Tree}; use hvm64_host::Host; -use hvm64_runtime::{DynDef, Heap, Port, Trg}; +use hvm64_runtime::{trace, DynDef, Heap, Port, Trg}; use hvm64_transform::Transform; +use hvm64_util::pretty_num; fn main() { if cfg!(feature = "trace") { - hvm64_runtime::trace::set_hook(); + trace::set_hook(); } let cli = FullCli::parse(); @@ -70,7 +77,7 @@ fn main() { }; if cfg!(feature = "trace") { - hvm64_runtime::trace::_read_traces(usize::MAX); + trace::_read_traces(usize::MAX); } } @@ -124,7 +131,7 @@ fn load_book(files: &[PathBuf], transform_args: TransformArgs) -> Book { } fn load_dylibs(host: &mut Host, include: &[PathBuf]) { - let current_dir = std::env::current_dir().unwrap(); + let current_dir = env::current_dir().unwrap(); for file in include { unsafe { @@ -163,7 +170,7 @@ fn load_dylibs(host: &mut Host, include: &[PathBuf]) { }); // Leak the lib to avoid unloading it, as code from it is still referenced. - std::mem::forget(lib); + mem::forget(lib); } } } @@ -198,17 +205,6 @@ fn print_stats(net: &hvm64_runtime::Net, elapsed: Duration) { eprintln!("RPS : {:.3} M", (net.rwts.total() as f64) / (elapsed.as_millis() as f64) / 1000.0); } -fn pretty_num(n: u64) -> String { - n.to_string() - .as_bytes() - .rchunks(3) - .rev() - .map(|x| std::str::from_utf8(x).unwrap()) - .flat_map(|x| ["_", x]) - .skip(1) - .collect() -} - /// Compiles the `.hvm` directory, appending the provided `args` to `cargo`. fn compile_temp_hvm() -> Result<(), io::Error> { let output = process::Command::new("cargo") diff --git a/tests/cli.rs b/tests/cli.rs index 58cdacb3..e166ef1f 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -2,6 +2,7 @@ use std::{ error::Error, + fs, io::Read, process::{Command, ExitStatus, Stdio}, }; @@ -253,5 +254,5 @@ fn test_cli_compile() { [#13 #1] "###); - std::fs::remove_file("examples/arithmetic").unwrap(); + fs::remove_file("examples/arithmetic").unwrap(); } diff --git a/tests/tests.rs b/tests/tests.rs index 5f024f3f..2141f71a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,7 @@ +use core::str::FromStr; use dyntest::{dyntest, DynTester}; use hvm64_transform::pre_reduce::PreReduce; -use std::{fs, path::Path, str::FromStr}; +use std::{fs, path::Path}; use hvm64_ast::{self as ast, Book, Net}; use hvm64_host::Host; diff --git a/tests/transform.rs b/tests/transform.rs index 30794c90..66b015f8 100644 --- a/tests/transform.rs +++ b/tests/transform.rs @@ -6,7 +6,7 @@ use hvm64_ast::{Book, Net}; use hvm64_transform::{eta_reduce::EtaReduce, inline::Inline, pre_reduce::PreReduce, prune::Prune, TransformError}; use insta::assert_snapshot; -use std::str::FromStr; +use core::str::FromStr; mod loaders; use loaders::*;