Skip to content

Commit b129bc6

Browse files
authored
Merge pull request #35 from erkkikeranen/slurp
slurp files and http URLs, refactor rust_core structure
2 parents 1a307a2 + e0770e0 commit b129bc6

File tree

15 files changed

+497
-298
lines changed

15 files changed

+497
-298
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ edition = "2018"
1010
dyn-clone = "1.0"
1111
nom = "5.1"
1212
rand = "0.7"
13-
itertools= "0.9"
13+
itertools= "0.9"
14+
url = "2.1.1"
15+
reqwest = { version = "0.10.4", features = ["blocking"] }

src/clojure/core.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
(quote (do
2323
(println (str "Elapsed time: " (_slash_ (- (System_nanotime) start) 1000000.0) " msecs"))
2424
ret))))
25+
26+
(defn slurp [f & opts]
27+
(rust-slurp f opts))

src/environment.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,14 @@ impl Environment {
8181
let concat_fn = rust_core::ConcatFn {};
8282
let print_string_fn = rust_core::PrintStringFn {};
8383
let assoc_fn = rust_core::AssocFn {};
84+
85+
// rust implementations of core functions
86+
let slurp_fn = rust_core::slurp::SlurpFn {};
87+
8488
// clojure.std functions
8589
let thread_sleep_fn = clojure_std::thread::SleepFn {};
8690
let nanotime_fn = clojure_std::time::NanoTimeFn {};
91+
8792
// Hardcoded fns
8893
let lexical_eval_fn = Value::LexicalEvalFn {};
8994
// Hardcoded macros
@@ -113,6 +118,10 @@ impl Environment {
113118

114119
environment.insert(Symbol::intern("System_nanotime"), nanotime_fn.to_rc_value());
115120

121+
// core.clj wraps calls to the rust implementations
122+
// @TODO add this to clojure.rs.core namespace as clojure.rs.core/slurp
123+
environment.insert(Symbol::intern("rust-slurp"), slurp_fn.to_rc_value());
124+
116125
environment.insert(Symbol::intern("+"), add_fn.to_rc_value());
117126
environment.insert(Symbol::intern("let"), let_macro.to_rc_value());
118127
environment.insert(Symbol::intern("str"), str_fn.to_rc_value());

src/error_message.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::type_tag::TypeTag;
22
use crate::value::Value;
3+
use nom::Err;
4+
use nom::error::ErrorKind;
5+
use std::error::Error;
36

47
pub fn type_mismatch(expected: TypeTag, got: &Value) -> Value {
58
Value::Condition(format!(
@@ -40,3 +43,7 @@ pub fn index_out_of_bounds(ind: usize, count: usize) -> Value {
4043
pub fn index_cannot_be_negative(ind: usize) -> Value {
4144
Value::Condition(format!("Index cannot be negative; Index ({})", ind))
4245
}
46+
47+
pub fn generic_err(error: Box<Error>) -> Value {
48+
Value::Condition(format!("{}", error.to_string()))
49+
}

0 commit comments

Comments
 (0)