1
1
use crate :: namespace:: { Namespace , Namespaces } ;
2
2
use crate :: rust_core;
3
- use crate :: rust_core:: { AddFn , StrFn } ;
4
3
use crate :: value:: { ToValue , Value } ;
5
4
use crate :: Symbol ;
5
+ use crate :: repl;
6
6
7
7
use std:: cell:: RefCell ;
8
8
use std:: collections:: HashMap ;
@@ -68,16 +68,22 @@ impl Environment {
68
68
}
69
69
pub fn clojure_core_environment ( ) -> Rc < Environment > {
70
70
// 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 ( ) ) ;
81
87
82
88
let eval_fn = rust_core:: EvalFn :: new ( Rc :: clone ( & environment) ) ;
83
89
@@ -90,6 +96,33 @@ impl Environment {
90
96
environment. insert ( Symbol :: intern ( "defmacro" ) , defmacro_macro. to_rc_value ( ) ) ;
91
97
environment. insert ( Symbol :: intern ( "eval" ) , eval_fn. to_rc_value ( ) ) ;
92
98
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
94
127
}
95
128
}
0 commit comments