@@ -66,45 +66,46 @@ int lisp_execute_file(char *file_path) {
66
66
std::string data ((std::istreambuf_iterator<char >(script_file)),
67
67
std::istreambuf_iterator<char >());
68
68
yaksha_macros mm{};
69
- yaksha_lisp_tokenizer tokenizer{&mm} ;
70
- tokenizer. tokenize (file_name, data, mm.get_yk_token_pool ());
71
- if (!tokenizer. errors_ .empty ()) {
72
- errors::print_errors (tokenizer. errors_ );
69
+ yaksha_lisp_tokenizer* tokenizer = mm. create_tokenizer () ;
70
+ tokenizer-> tokenize (file_name, data, mm.get_yk_token_pool ());
71
+ if (!tokenizer-> errors_ .empty ()) {
72
+ errors::print_errors (tokenizer-> errors_ );
73
73
return EXIT_FAILURE;
74
74
}
75
- yaksha_lisp_parser parser{&tokenizer, &mm} ;
76
- parser. parse ();
77
- if (!parser. errors_ .empty ()) {
78
- errors::print_errors (parser. errors_ );
75
+ yaksha_lisp_parser * parser = mm. create_parser (tokenizer) ;
76
+ parser-> parse ();
77
+ if (!parser-> errors_ .empty ()) {
78
+ errors::print_errors (parser-> errors_ );
79
79
return EXIT_FAILURE;
80
80
}
81
- yaksha_envmap environment{&mm};
82
- environment.setup_builtins ();
83
- environment.setup_prelude ();
81
+ std::string f_path{file_path};
82
+ std::unordered_map<std::string, import_stmt*> no_imports{};
83
+ mm.init_env (f_path, no_imports);
84
+ yaksha_envmap *environment = mm.validate_and_get_environment_root (f_path);
84
85
try {
85
- environment. eval (parser. exprs_ );
86
+ environment-> eval (parser-> exprs_ );
86
87
} catch (parsing_error &ex) {
87
88
errors::print_error (std::cerr, ex);
88
89
return EXIT_FAILURE;
89
90
}
90
91
return EXIT_SUCCESS;
91
92
}
92
- void eval_line (const std::string &code, yaksha_envmap *environment) {
93
- yaksha_lisp_tokenizer tokenizer{environment-> get_memory_manager ()} ;
94
- tokenizer. tokenize (" repl.lisp" , code,
95
- environment-> get_memory_manager () ->get_yk_token_pool ());
96
- if (!tokenizer. errors_ .empty ()) {
97
- errors::print_errors (tokenizer. errors_ );
93
+ void eval_line (const std::string &code, yaksha_envmap *environment, yaksha_macros* mm ) {
94
+ yaksha_lisp_tokenizer * tokenizer = mm-> create_tokenizer () ;
95
+ tokenizer-> tokenize (" repl.lisp" , code,
96
+ mm ->get_yk_token_pool ());
97
+ if (!tokenizer-> errors_ .empty ()) {
98
+ errors::print_errors (tokenizer-> errors_ );
98
99
return ;
99
100
}
100
- yaksha_lisp_parser parser{&tokenizer, environment-> get_memory_manager ()} ;
101
- parser. parse ();
102
- if (!parser. errors_ .empty ()) {
103
- errors::print_errors (parser. errors_ );
101
+ yaksha_lisp_parser * parser = mm-> create_parser (tokenizer) ;
102
+ parser-> parse ();
103
+ if (!parser-> errors_ .empty ()) {
104
+ errors::print_errors (parser-> errors_ );
104
105
return ;
105
106
}
106
107
try {
107
- auto result = environment->eval (parser. exprs_ );
108
+ auto result = environment->eval (parser-> exprs_ );
108
109
if (result != nullptr ) { std::cout << colours::cyan (" -> " ) << result; }
109
110
} catch (parsing_error &ex) { errors::print_error (std::cerr, ex); }
110
111
}
@@ -120,9 +121,9 @@ int lisp_repl() {
120
121
std::cout << " Type in expressions to evaluate them.\n " ;
121
122
std::cout << " Input " << colours::cyan (" (exit)" ) << " to exit from repl.\n " ;
122
123
yaksha_macros mm{};
123
- yaksha_envmap environment{&mm };
124
- environment. setup_builtins ( );
125
- environment. setup_prelude ( );
124
+ std::unordered_map<std::string, import_stmt*> no_imports{ };
125
+ mm. init_env ( " repl.lisp " , no_imports );
126
+ yaksha_envmap * environment = mm. validate_and_get_environment_root ( " repl.lisp " );
126
127
#ifdef PRINT_BUILTINS_YAKSHA_LISP
127
128
std::cout << " Builtins:: " ;
128
129
bool first = true ;
@@ -147,7 +148,7 @@ int lisp_repl() {
147
148
exit = true ;
148
149
continue ;
149
150
}
150
- eval_line (line, & environment);
151
+ eval_line (line, environment, &mm );
151
152
std::cout << " \n " ;
152
153
}
153
154
return EXIT_SUCCESS;
0 commit comments