Skip to content

Commit 52c980d

Browse files
authored
Merge pull request #39 from arbroween/refactor/fix-warnings
Fixed warnings and refactors
2 parents 4c4ed5f + f6c294d commit 52c980d

File tree

13 files changed

+173
-254
lines changed

13 files changed

+173
-254
lines changed

src/clojure_std/thread.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
use crate::value::{ToValue, Value};
2-
use std::rc::Rc;
3-
use crate::ifn::IFn;
4-
use std::io::Read;
5-
use std::error::Error;
61
use crate::error_message;
7-
use nom::lib::std::convert::TryFrom;
2+
use crate::ifn::IFn;
83
use crate::type_tag::TypeTag;
4+
use crate::value::{ToValue, Value};
5+
use std::rc::Rc;
96

10-
use std::thread;
117
use std::time;
128

139
/// provides a sleep function to sleep for given amount of ms
@@ -25,14 +21,14 @@ impl IFn for SleepFn {
2521
let arg = &**args.get(0).unwrap();
2622
match arg {
2723
Value::I32(i) => {
28-
std::thread::sleep(time::Duration::new(0, (*i as u32) * 1000000));
29-
return Value::Nil
30-
},
31-
_ => error_message::type_mismatch(TypeTag::I32, args.get(0).unwrap())
24+
std::thread::sleep(time::Duration::new(0, (*i as u32) * 100_0000));
25+
Value::Nil
26+
}
27+
_ => error_message::type_mismatch(TypeTag::I32, args.get(0).unwrap()),
3228
}
3329
} else {
3430
error_message::wrong_arg_count(1, args.len());
35-
return Value::Nil
31+
Value::Nil
3632
}
3733
}
38-
}
34+
}

src/clojure_std/time.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1+
use crate::error_message;
2+
use crate::ifn::IFn;
13
use crate::value::{ToValue, Value};
24
use std::rc::Rc;
3-
use crate::ifn::IFn;
4-
use std::io::Read;
5-
use std::error::Error;
6-
use crate::error_message;
7-
use nom::lib::std::convert::TryFrom;
8-
use crate::type_tag::TypeTag;
95

10-
use std::thread;
116
use std::time::{SystemTime, UNIX_EPOCH};
127

138
/// provides a function to return current time in nanoseconds
@@ -21,12 +16,15 @@ impl ToValue for NanoTimeFn {
2116

2217
impl IFn for NanoTimeFn {
2318
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
24-
if args.len() == 0 {
25-
let ns = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
26-
return Value::F64(ns as f64)
19+
if args.is_empty() {
20+
let ns = SystemTime::now()
21+
.duration_since(UNIX_EPOCH)
22+
.unwrap()
23+
.as_nanos();
24+
Value::F64(ns as f64)
2725
} else {
2826
error_message::wrong_arg_count(0, args.len());
29-
return Value::Nil
27+
Value::Nil
3028
}
3129
}
32-
}
30+
}

src/environment.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use crate::clojure_std;
12
use crate::namespace::{Namespace, Namespaces};
2-
use crate::repl;
33
use crate::repl::Repl;
44
use crate::rust_core;
5-
use crate::clojure_std;
65
use crate::symbol::Symbol;
76
use crate::value::{ToValue, Value};
87

@@ -118,12 +117,15 @@ impl Environment {
118117
environment.insert(Symbol::intern("eval"), eval_fn.to_rc_value());
119118

120119
// Thread namespace TODO / instead of _
121-
environment.insert(Symbol::intern("Thread_sleep"), thread_sleep_fn.to_rc_value());
120+
environment.insert(
121+
Symbol::intern("Thread_sleep"),
122+
thread_sleep_fn.to_rc_value(),
123+
);
122124

123125
environment.insert(Symbol::intern("System_nanotime"), nanotime_fn.to_rc_value());
124126

125127
// core.clj wraps calls to the rust implementations
126-
// @TODO add this to clojure.rs.core namespace as clojure.rs.core/slurp
128+
// @TODO add this to clojure.rs.core namespace as clojure.rs.core/slurp
127129
environment.insert(Symbol::intern("rust-slurp"), slurp_fn.to_rc_value());
128130

129131
environment.insert(Symbol::intern("+"), add_fn.to_rc_value());
@@ -141,7 +143,7 @@ impl Environment {
141143
lexical_eval_fn.to_rc_value(),
142144
);
143145
environment.insert(Symbol::intern("nth"), nth_fn.to_rc_value());
144-
environment.insert(Symbol::intern("assoc"), assoc_fn.to_rc_value());
146+
environment.insert(Symbol::intern("assoc"), assoc_fn.to_rc_value());
145147
environment.insert(Symbol::intern("concat"), concat_fn.to_rc_value());
146148
environment.insert(
147149
Symbol::intern("print-string"),

src/error_message.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
use crate::type_tag::TypeTag;
22
use crate::value::Value;
3-
use nom::Err;
4-
use nom::error::ErrorKind;
53
use std::error::Error;
64

75
pub fn type_mismatch(expected: TypeTag, got: &Value) -> Value {
86
Value::Condition(format!(
97
"Type mismatch; Expected instance of {}, Recieved type {}",
10-
expected,
11-
got
8+
expected, got
129
))
1310
}
1411

1512
pub fn wrong_arg_count(expected: usize, got: usize) -> Value {
1613
Value::Condition(format!(
1714
"Wrong number of arguments given to function (Given: {}, Expected: {})",
18-
got,
19-
expected
15+
got, expected
2016
))
2117
}
2218

2319
pub fn wrong_varg_count(expected: &[usize], got: usize) -> Value {
2420
Value::Condition(format!(
2521
"Wrong number of arguments given to function (Given: {}, Expected: {:?})",
26-
got,
27-
expected
22+
got, expected
2823
))
2924
}
3025

3126
pub fn zero_arg_count(got: usize) -> Value {
3227
Value::Condition(format!(
33-
"Wrong number of arguments given to function (Given: {})", got))
28+
"Wrong number of arguments given to function (Given: {})",
29+
got
30+
))
3431
}
3532

3633
pub fn index_out_of_bounds(ind: usize, count: usize) -> Value {
@@ -44,6 +41,6 @@ pub fn index_cannot_be_negative(ind: usize) -> Value {
4441
Value::Condition(format!("Index cannot be negative; Index ({})", ind))
4542
}
4643

47-
pub fn generic_err(error: Box<Error>) -> Value {
48-
Value::Condition(format!("{}", error.to_string()))
49-
}
44+
pub fn generic_err(error: Box<dyn Error>) -> Value {
45+
Value::Condition(error.to_string())
46+
}

src/persistent_list_map.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ mod tests {
176176

177177
#[test]
178178
fn test_persistent_list_map() {
179-
let empty = PersistentListMap::Empty;
180179
let map1 = vec![
181180
MapEntry {
182181
key: Symbol::intern("a").to_rc_value(),

0 commit comments

Comments
 (0)