|
1 | 1 | use crate::clojure_std; |
2 | 2 | use crate::clojure_string; |
3 | | -use crate::namespace::{Namespaces}; |
| 3 | +use crate::namespace::Namespaces; |
4 | 4 | use crate::repl::Repl; |
5 | 5 | use crate::rust_core; |
6 | 6 | use crate::symbol::Symbol; |
@@ -219,6 +219,7 @@ impl Environment { |
219 | 219 | let triml_fn = clojure_string::triml::TrimLFn {}; |
220 | 220 | let trimr_fn = clojure_string::trimr::TrimRFn {}; |
221 | 221 | let trim_newline_fn = clojure_string::trim_newline::TrimNewlineFn {}; |
| 222 | + let split_fn = clojure_string::split::SplitFn {}; |
222 | 223 |
|
223 | 224 | // Hardcoded fns |
224 | 225 | let lexical_eval_fn = Value::LexicalEvalFn {}; |
@@ -255,23 +256,23 @@ impl Environment { |
255 | 256 | environment.insert(Symbol::intern("eval"), eval_fn.to_rc_value()); |
256 | 257 |
|
257 | 258 | // Thread namespace |
258 | | - environment.insert_into_namespace( |
259 | | - &Symbol::intern("Thread"), |
260 | | - Symbol::intern("sleep"), |
261 | | - thread_sleep_fn.to_rc_value() |
262 | | - ); |
263 | | - |
264 | | - // System namespace |
265 | | - environment.insert_into_namespace( |
266 | | - &Symbol::intern("System"), |
267 | | - Symbol::intern("nanoTime"), |
268 | | - nanotime_fn.to_rc_value() |
269 | | - ); |
270 | | - environment.insert_into_namespace( |
271 | | - &Symbol::intern("System"), |
272 | | - Symbol::intern("getenv"), |
273 | | - get_env_fn.to_rc_value() |
274 | | - ); |
| 259 | + environment.insert_into_namespace( |
| 260 | + &Symbol::intern("Thread"), |
| 261 | + Symbol::intern("sleep"), |
| 262 | + thread_sleep_fn.to_rc_value(), |
| 263 | + ); |
| 264 | + |
| 265 | + // System namespace |
| 266 | + environment.insert_into_namespace( |
| 267 | + &Symbol::intern("System"), |
| 268 | + Symbol::intern("nanoTime"), |
| 269 | + nanotime_fn.to_rc_value(), |
| 270 | + ); |
| 271 | + environment.insert_into_namespace( |
| 272 | + &Symbol::intern("System"), |
| 273 | + Symbol::intern("getenv"), |
| 274 | + get_env_fn.to_rc_value(), |
| 275 | + ); |
275 | 276 |
|
276 | 277 | // core.clj wraps calls to the rust implementations |
277 | 278 | // @TODO add this to clojure.rs.core namespace as clojure.rs.core/slurp |
@@ -350,6 +351,12 @@ impl Environment { |
350 | 351 | trim_newline_fn.to_rc_value(), |
351 | 352 | ); |
352 | 353 |
|
| 354 | + environment.insert_into_namespace( |
| 355 | + &Symbol::intern("clojure.string"), |
| 356 | + Symbol::intern("split"), |
| 357 | + split_fn.to_rc_value(), |
| 358 | + ); |
| 359 | + |
353 | 360 | environment.insert(Symbol::intern("+"), add_fn.to_rc_value()); |
354 | 361 | environment.insert(Symbol::intern("let"), let_macro.to_rc_value()); |
355 | 362 | environment.insert(Symbol::intern("str"), str_fn.to_rc_value()); |
@@ -389,12 +396,19 @@ impl Environment { |
389 | 396 | ); |
390 | 397 | environment.insert(Symbol::intern("read-line"), read_line_fn.to_rc_value()); |
391 | 398 |
|
392 | | - environment.insert(Symbol::intern("="),equals_fn.to_rc_value()); |
| 399 | + environment.insert(Symbol::intern("="), equals_fn.to_rc_value()); |
393 | 400 | // |
394 | 401 | // Read in clojure.core |
395 | 402 | // |
396 | 403 | // @TODO its time for a RT (runtime), which environment seems to be becoming |
397 | 404 | let _ = Repl::new(Rc::clone(&environment)).try_eval_file("./src/clojure/core.clj"); |
| 405 | + println!( |
| 406 | + "{:#?} {:#?}", |
| 407 | + &environment.get_current_namespace(), |
| 408 | + &environment.get_current_namespace_name() |
| 409 | + ); |
| 410 | + // TODO: should read into namespace if (ns ..) is given in source file |
| 411 | + let _ = Repl::new(Rc::clone(&environment)).try_eval_file("./src/clojure/string.clj"); |
398 | 412 |
|
399 | 413 | // We can add this back once we have requires |
400 | 414 | // environment.change_namespace(Symbol::intern("user")); |
@@ -528,8 +542,7 @@ mod tests { |
528 | 542 | MainEnvironment(EnvironmentVal { |
529 | 543 | curr_ns_sym: _, |
530 | 544 | namespaces, |
531 | | - }) => namespaces |
532 | | - .get(&Symbol::intern("user"),&Symbol::intern("+")), |
| 545 | + }) => namespaces.get(&Symbol::intern("user"), &Symbol::intern("+")), |
533 | 546 | _ => panic!("new_main_environment() should return Main"), |
534 | 547 | }; |
535 | 548 |
|
|
0 commit comments