11use crate :: namespace:: { Namespace , Namespaces } ;
22use crate :: rust_core;
3- use crate :: rust_core:: { AddFn , StrFn } ;
43use crate :: value:: { ToValue , Value } ;
54use crate :: Symbol ;
5+ use crate :: repl;
66
77use std:: cell:: RefCell ;
88use std:: collections:: HashMap ;
@@ -68,16 +68,22 @@ impl Environment {
6868 }
6969 pub fn clojure_core_environment ( ) -> Rc < Environment > {
7070 // Register our macros / functions ahead of time
71- let add_fn = rust_core:: AddFn { } ;
72- let str_fn = rust_core:: StrFn { } ;
73- // Hardcoded macros
74- let let_macro = Value :: LetMacro { } ;
75- let quote_macro = Value :: QuoteMacro { } ;
76- let def_macro = Value :: DefMacro { } ;
77- let fn_macro = Value :: FnMacro { } ;
78- let defmacro_macro = Value :: DefmacroMacro { } ;
79-
80- let mut environment = Rc :: new ( Environment :: new_main_environment ( ) ) ;
71+ let add_fn = rust_core:: AddFn { } ;
72+ let str_fn = rust_core:: StrFn { } ;
73+ let do_fn = rust_core:: DoFn { } ;
74+ let nth_fn = rust_core:: NthFn { } ;
75+ let do_macro = rust_core:: DoMacro { } ;
76+ let concat_fn = rust_core:: ConcatFn { } ;
77+ let print_string_fn = rust_core:: PrintStringFn { } ;
78+ // Hardcoded fns
79+ let lexical_eval_fn = Value :: LexicalEvalFn { } ;
80+ // Hardcoded macros
81+ let let_macro = Value :: LetMacro { } ;
82+ let quote_macro = Value :: QuoteMacro { } ;
83+ let def_macro = Value :: DefMacro { } ;
84+ let fn_macro = Value :: FnMacro { } ;
85+ let defmacro_macro = Value :: DefmacroMacro { } ;
86+ let environment = Rc :: new ( Environment :: new_main_environment ( ) ) ;
8187
8288 let eval_fn = rust_core:: EvalFn :: new ( Rc :: clone ( & environment) ) ;
8389
@@ -90,6 +96,33 @@ impl Environment {
9096 environment. insert ( Symbol :: intern ( "defmacro" ) , defmacro_macro. to_rc_value ( ) ) ;
9197 environment. insert ( Symbol :: intern ( "eval" ) , eval_fn. to_rc_value ( ) ) ;
9298
93- environment
99+ environment. insert ( Symbol :: intern ( "+" ) , add_fn. to_rc_value ( ) ) ;
100+ environment. insert ( Symbol :: intern ( "let" ) , let_macro. to_rc_value ( ) ) ;
101+ environment. insert ( Symbol :: intern ( "str" ) , str_fn. to_rc_value ( ) ) ;
102+ environment. insert ( Symbol :: intern ( "quote" ) , quote_macro. to_rc_value ( ) ) ;
103+ environment. insert ( Symbol :: intern ( "do-fn*" ) , do_fn. to_rc_value ( ) ) ;
104+ environment. insert ( Symbol :: intern ( "do" ) , do_macro. to_rc_value ( ) ) ;
105+ environment. insert ( Symbol :: intern ( "def" ) , def_macro. to_rc_value ( ) ) ;
106+ environment. insert ( Symbol :: intern ( "fn" ) , fn_macro. to_rc_value ( ) ) ;
107+ environment. insert ( Symbol :: intern ( "defmacro" ) , defmacro_macro. to_rc_value ( ) ) ;
108+ environment. insert ( Symbol :: intern ( "eval" ) , eval_fn. to_rc_value ( ) ) ;
109+ environment. insert (
110+ Symbol :: intern ( "lexical-eval" ) ,
111+ lexical_eval_fn. to_rc_value ( ) ,
112+ ) ;
113+
114+ environment. insert ( Symbol :: intern ( "nth" ) , nth_fn. to_rc_value ( ) ) ;
115+ environment. insert ( Symbol :: intern ( "concat" ) , concat_fn. to_rc_value ( ) ) ;
116+ environment. insert (
117+ Symbol :: intern ( "print-string" ) ,
118+ print_string_fn. to_rc_value ( ) ,
119+ ) ;
120+
121+ //
122+ // Read in clojure.core
123+ //
124+ let _ = repl:: try_eval_file ( & environment, "./src/clojure/core.clj" ) ;
125+
126+ environment
94127 }
95128}
0 commit comments