@@ -18,107 +18,20 @@ mod value;
18
18
19
19
use environment:: Environment ;
20
20
21
- use std:: collections:: HashMap ;
22
- use std:: fs:: File ;
23
21
use std:: io:: BufRead ;
24
- use std:: io:: { self , Read } ;
22
+ use std:: io:: { self } ;
23
+ use std:: io:: Write ;
25
24
use std:: rc:: Rc ;
26
- use std:: str:: FromStr ;
27
25
28
- use crate :: maps:: * ;
29
- use crate :: persistent_list:: { PersistentList , ToPersistentList } ;
30
- use crate :: persistent_list_map:: * ;
31
- use crate :: persistent_vector:: { PersistentVector , ToPersistentVector } ;
32
26
use crate :: value:: Value ;
33
27
use crate :: value:: { Evaluable , ToValue } ;
34
- use rust_core:: { AddFn , StrFn } ;
35
28
use symbol:: Symbol ;
36
29
37
- use nom:: error:: convert_error;
38
30
use nom:: Err :: Incomplete ;
39
- use nom:: Needed :: Size ;
40
31
41
32
fn main ( ) {
42
- println ! ( "Clojure RS 0.0.1" ) ;
43
-
44
- // Register our macros / functions ahead of time
45
- let add_fn = rust_core:: AddFn { } ;
46
- let str_fn = rust_core:: StrFn { } ;
47
- let do_fn = rust_core:: DoFn { } ;
48
- let nth_fn = rust_core:: NthFn { } ;
49
- let do_macro = rust_core:: DoMacro { } ;
50
- let concat_fn = rust_core:: ConcatFn { } ;
51
- let print_string_fn = rust_core:: PrintStringFn { } ;
52
- // Hardcoded fns
53
- let lexical_eval_fn = Value :: LexicalEvalFn { } ;
54
- // Hardcoded macros
55
- let let_macro = Value :: LetMacro { } ;
56
- let quote_macro = Value :: QuoteMacro { } ;
57
- let def_macro = Value :: DefMacro { } ;
58
- let fn_macro = Value :: FnMacro { } ;
59
- let defmacro_macro = Value :: DefmacroMacro { } ;
60
-
61
- let environment = Rc :: new ( Environment :: new_main_environment ( ) ) ;
62
-
63
- let eval_fn = rust_core:: EvalFn :: new ( Rc :: clone ( & environment) ) ;
64
-
65
- environment. insert ( Symbol :: intern ( "+" ) , add_fn. to_rc_value ( ) ) ;
66
- environment. insert ( Symbol :: intern ( "let" ) , let_macro. to_rc_value ( ) ) ;
67
- environment. insert ( Symbol :: intern ( "str" ) , str_fn. to_rc_value ( ) ) ;
68
- environment. insert ( Symbol :: intern ( "quote" ) , quote_macro. to_rc_value ( ) ) ;
69
- environment. insert ( Symbol :: intern ( "do-fn*" ) , do_fn. to_rc_value ( ) ) ;
70
- environment. insert ( Symbol :: intern ( "do" ) , do_macro. to_rc_value ( ) ) ;
71
- environment. insert ( Symbol :: intern ( "def" ) , def_macro. to_rc_value ( ) ) ;
72
- environment. insert ( Symbol :: intern ( "fn" ) , fn_macro. to_rc_value ( ) ) ;
73
- environment. insert ( Symbol :: intern ( "defmacro" ) , defmacro_macro. to_rc_value ( ) ) ;
74
- environment. insert ( Symbol :: intern ( "eval" ) , eval_fn. to_rc_value ( ) ) ;
75
- environment. insert (
76
- Symbol :: intern ( "lexical-eval" ) ,
77
- lexical_eval_fn. to_rc_value ( ) ,
78
- ) ;
79
- environment. insert ( Symbol :: intern ( "nth" ) , nth_fn. to_rc_value ( ) ) ;
80
- environment. insert ( Symbol :: intern ( "concat" ) , concat_fn. to_rc_value ( ) ) ;
81
- environment. insert (
82
- Symbol :: intern ( "print-string" ) ,
83
- print_string_fn. to_rc_value ( ) ,
84
- ) ;
85
- //
86
- // Read in clojure.core
87
- //
88
- repl:: try_eval_file ( & environment, "./src/clojure/core.clj" ) ;
89
33
//
90
34
// Start repl
91
35
//
92
- let stdin = io:: stdin ( ) ;
93
- print ! ( "user=> " ) ;
94
- let mut remaining_input_buffer = String :: from ( "" ) ;
95
- for line in stdin. lock ( ) . lines ( ) {
96
- let line = line. unwrap ( ) ;
97
- remaining_input_buffer. push_str ( & line) ;
98
- let mut remaining_input_bytes = remaining_input_buffer. as_bytes ( ) ;
99
- loop {
100
- let next_read_parse = reader:: try_read ( remaining_input_bytes) ;
101
- match next_read_parse {
102
- Ok ( ( _remaining_input_bytes, value) ) => {
103
- print ! (
104
- "{} " ,
105
- value. eval( Rc :: clone( & environment) ) . to_string_explicit( )
106
- ) ;
107
- remaining_input_bytes = _remaining_input_bytes;
108
- }
109
- Err ( Incomplete ( _) ) => {
110
- remaining_input_buffer =
111
- String :: from_utf8 ( remaining_input_bytes. to_vec ( ) ) . unwrap ( ) ;
112
- break ;
113
- }
114
- err => {
115
- print ! ( "{}" , Value :: Condition ( format!( "Reader Error: {:?}" , err) ) ) ;
116
- remaining_input_buffer = String :: from ( "" ) ;
117
- break ;
118
- }
119
- }
120
- }
121
- println ! ( ) ;
122
- print ! ( "user=> " ) ;
123
- }
36
+ repl:: repl ( ) ;
124
37
}
0 commit comments