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
3 changes: 1 addition & 2 deletions crates/forge/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::path::PathBuf;

use steel::path::PathBuf;
use steel::steel_vm::engine::Engine;

fn main() {
Expand Down
10 changes: 5 additions & 5 deletions crates/steel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ steel-parser = { path = "../steel-parser", version = "0.7.0" }
steel-derive = { path = "../steel-derive", version = "0.7.0" }
cargo-steel-lib = { path = "../cargo-steel-lib", version = "0.2.0", optional = true }
chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"], optional = true }
env_home = "0.1.0"
env_home = { version = "0.1.0", optional = true }
weak-table = "0.3.2"
# TODO: Consider whether rand needs to be here
rand = "0.9.0"
Expand Down Expand Up @@ -98,10 +98,10 @@ ureq = { version = "3.0.12", optional = true }
arc-swap = "1.7.1"

md-5 = "0.10.6"
glob = "0.3.2"
glob = { version = "0.3.2", optional = true }

# For helping discover the steel home location
xdg = "3.0.0"
xdg = { version = "3.0.0", optional = true }

shared_vector = "0.4.4"

Expand All @@ -118,7 +118,7 @@ js-sys = "0.3.69"
polling = "3.10.0"

[target.'cfg(not(any(target_family = "wasm", target_env = "newlib")))'.dependencies]
which = "8.0.0"
which = { version = "8.0.0", optional = true }

[dev-dependencies]
proptest = "1.1.0"
Expand All @@ -127,7 +127,7 @@ criterion = "0.5.1"
[features]
# TODO: Deprecate the modules feature flag, it no longer does anything
default = ["std", "modules"]
std = ["dep:chrono"]
std = ["dep:chrono", "dep:env_home", "dep:glob", "dep:xdg", "dep:which"]
modules = []
jit = ["dep:cranelift", "dep:cranelift-module", "dep:cranelift-jit"]
sandbox = []
Expand Down
10 changes: 4 additions & 6 deletions crates/steel-core/src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ use crate::{
parser::parser::Sources,
};

use crate::path::PathBuf;
use alloc::borrow::Cow;
use core::iter::Iterator;
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
};
use std::collections::{HashMap, HashSet};

use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -742,7 +740,7 @@ impl Compiler {
// Could fail here
let parsed: core::result::Result<Vec<ExprKind>, ParseError> = path
.as_ref()
.map(|p| Parser::new_from_source(expr_str.as_ref(), p.clone(), Some(id)))
.map(|p| Parser::new_from_source(expr_str.as_ref(), p.to_path_buf(), Some(id)))
.unwrap_or_else(|| Parser::new(expr_str.as_ref(), Some(id)))
.without_lowering()
.map(|x| x.and_then(lower_macro_and_require_definitions))
Expand Down Expand Up @@ -772,7 +770,7 @@ impl Compiler {
// Could fail here
let parsed: core::result::Result<Vec<ExprKind>, ParseError> = path
.as_ref()
.map(|p| Parser::new_from_source(expr_str.as_ref(), p.clone(), Some(id)))
.map(|p| Parser::new_from_source(expr_str.as_ref(), p.to_path_buf(), Some(id)))
.unwrap_or_else(|| Parser::new(expr_str.as_ref(), Some(id)))
.without_lowering()
.map(|x| x.and_then(lower_macro_and_require_definitions))
Expand Down
41 changes: 22 additions & 19 deletions crates/steel-core/src/compiler/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ use rustc_hash::{FxHashMap, FxHashSet};
// use smallvec::SmallVec;
use steel_parser::{ast::PROTO_HASH_GET, expr_list, parser::SourceId, span::Span};

use thin_vec::{thin_vec, ThinVec};

use crate::path::PathBuf;
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
io::Read,
path::PathBuf,
sync::Arc,
};
use thin_vec::{thin_vec, ThinVec};

use crate::parser::expander::SteelMacro;
use crate::stop;
Expand Down Expand Up @@ -145,9 +144,11 @@ create_prelude!(

#[cfg(not(target_family = "wasm"))]
pub static STEEL_SEARCH_PATHS: Lazy<Option<Vec<PathBuf>>> = Lazy::new(|| {
std::env::var("STEEL_SEARCH_PATHS")
.ok()
.map(|x| std::env::split_paths(x.as_str()).collect::<Vec<_>>())
std::env::var("STEEL_SEARCH_PATHS").ok().map(|x| {
std::env::split_paths(x.as_str())
.map(PathBuf::from)
.collect::<Vec<_>>()
})
});

pub fn steel_search_dirs() -> Vec<PathBuf> {
Expand All @@ -161,11 +162,11 @@ pub fn steel_search_dirs() -> Vec<PathBuf> {
#[cfg(not(target_family = "wasm"))]
pub static STEEL_HOME: Lazy<Option<String>> = Lazy::new(|| {
std::env::var("STEEL_HOME").ok().or_else(|| {
let home = env_home::env_home_dir().map(|x| x.join(".steel"));
let home = env_home::env_home_dir().map(|x| PathBuf::from(x.join(".steel")));

if let Some(home) = home {
if home.exists() {
return Some(home.into_os_string().into_string().unwrap());
return Some(home.to_str().unwrap().to_owned());
}

#[cfg(target_os = "windows")]
Expand All @@ -174,14 +175,14 @@ pub static STEEL_HOME: Lazy<Option<String>> = Lazy::new(|| {
eprintln!("Unable to create steel home directory {:?}: {}", home, e)
}

return Some(home.into_os_string().into_string().unwrap());
return Some(home.to_str().unwrap().to_owned());
}
}

#[cfg(not(target_os = "windows"))]
{
let bd = xdg::BaseDirectories::new();
let home = bd.data_home;
let home = bd.data_home.map(PathBuf::from);

home.map(|mut x: PathBuf| {
x.push("steel");
Expand All @@ -196,7 +197,7 @@ pub static STEEL_HOME: Lazy<Option<String>> = Lazy::new(|| {
}
}

x.into_os_string().into_string().unwrap()
x.to_str().unwrap().to_owned()
})
}

Expand Down Expand Up @@ -1485,7 +1486,7 @@ impl CompiledModule {

builtin_definitions.append(&mut provide_definitions);

let module = self.name.as_os_str().to_str().unwrap().to_owned();
let module = self.name.as_path().as_os_str().to_str().unwrap().to_owned();

// Introduce a call to set the current module context?
builtin_definitions.push(expr_list!(
Expand Down Expand Up @@ -1657,7 +1658,9 @@ impl RequireObjectBuilder {
}

fn try_canonicalize(path: PathBuf) -> PathBuf {
std::fs::canonicalize(&path).unwrap_or_else(|_| path)
std::fs::canonicalize(&path)
.map(PathBuf::from)
.unwrap_or(path)
}

/*
Expand Down Expand Up @@ -1796,7 +1799,7 @@ impl CompiledModuleCache {
Ok(mut value) => {
value.emitted = false;
value.cached_prefix =
path_to_prefix_name(value.name.to_path_buf()).into();
path_to_prefix_name(value.name.clone()).into();

log::info!(
"Successfully read cached module in background -> {:?}",
Expand Down Expand Up @@ -1848,7 +1851,7 @@ impl CompiledModuleCache {
let mut value: CompiledModule = bincode::deserialize(&contents).unwrap();

value.emitted = false;
value.cached_prefix = path_to_prefix_name(value.name.to_path_buf()).into();
value.cached_prefix = path_to_prefix_name(value.name.clone()).into();

for downstream in value
.downstream
Expand Down Expand Up @@ -1991,9 +1994,9 @@ impl<'a> ModuleBuilder<'a> {

#[cfg(not(target_family = "wasm"))]
let name = if let Some(p) = name {
std::fs::canonicalize(p)?
PathBuf::from(std::fs::canonicalize(p)?)
} else {
std::env::current_dir()?
PathBuf::from(std::env::current_dir()?)
};

#[cfg(target_family = "wasm")]
Expand Down Expand Up @@ -3250,7 +3253,7 @@ impl<'a> ModuleBuilder<'a> {
.sources
.add_source(input.clone(), Some(self.name.clone()));

let parsed = Parser::new_from_source(&input, self.name.clone(), Some(id))
let parsed = Parser::new_from_source(&input, self.name.to_path_buf(), Some(id))
.without_lowering()
.map(|x| x.and_then(lower_macro_and_require_definitions))
.collect::<core::result::Result<Vec<_>, ParseError>>()?;
Expand Down Expand Up @@ -3295,7 +3298,7 @@ impl<'a> ModuleBuilder<'a> {

let exprs = guard.get(id).unwrap();

let mut parsed = Parser::new_from_source(exprs, self.name.clone(), Some(id))
let mut parsed = Parser::new_from_source(exprs, self.name.to_path_buf(), Some(id))
.without_lowering()
.map(|x| x.and_then(lower_macro_and_require_definitions))
.collect::<core::result::Result<Vec<_>, ParseError>>()?;
Expand Down
3 changes: 2 additions & 1 deletion crates/steel-core/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use crate::rvals::SteelVal;
#[cfg(not(feature = "sync"))]
use core::cell::RefCell;

use crate::path::OsStr;
use core::fmt::Pointer;
use core::ops::Deref;
use std::fmt;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{ffi::OsStr, fmt};

pub static OBJECT_COUNT: AtomicUsize = AtomicUsize::new(0);
pub(crate) static MAXIMUM_OBJECTS: usize = 50000;
Expand Down
1 change: 1 addition & 0 deletions crates/steel-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod env;
#[macro_use]
pub mod core;
pub mod compiler;
pub mod path;
pub mod primitives;
pub mod time;
#[macro_use]
Expand Down
5 changes: 3 additions & 2 deletions crates/steel-core/src/parser/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::parser::tokens::TokenType;

use crate::parser::span::Span;

use crate::path::PathBuf;
use crate::rvals::{IntoSteelVal, Result};
use core::cell::RefCell;
use quickscope::ScopeSet;
Expand All @@ -16,7 +17,7 @@ use std::{
fs::File,
io::{Read, Write},
iter::FromIterator,
path::{Path, PathBuf},
path::Path,
};

use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
Expand All @@ -39,7 +40,7 @@ fn update_extension(mut path: PathBuf, extension: &str) -> PathBuf {

// Prepend the given path with the working directory
pub fn path_from_working_dir<P: AsRef<Path>>(path: P) -> std::io::Result<PathBuf> {
let mut working_dir = std::env::current_dir()?;
let mut working_dir = PathBuf::from(std::env::current_dir()?);
working_dir.push(path);
Ok(working_dir)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/steel-core/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use crate::rvals::{IntoSteelVal, SteelComplex, SteelString};
use crate::HashSet;
use crate::{parser::tokens::TokenType::*, rvals::FromSteelVal};

use crate::path::PathBuf;
use alloc::borrow::Cow;
use alloc::sync::Arc;
use num_rational::{BigRational, Rational32};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use std::path::{Path, PathBuf};
use std::path::Path;
use steel_parser::interner::InternedString;
use steel_parser::tokens::{IntLiteral, NumberLiteral, RealLiteral, TokenType};

Expand Down
Loading
Loading