Skip to content

Commit f5012ff

Browse files
committed
fix(yakshalisp): fix yaksha lisp command, properly initialize the interpreter
1 parent a6918b6 commit f5012ff

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

compiler/src/lisp_main.cpp

+28-27
Original file line numberDiff line numberDiff line change
@@ -66,45 +66,46 @@ int lisp_execute_file(char *file_path) {
6666
std::string data((std::istreambuf_iterator<char>(script_file)),
6767
std::istreambuf_iterator<char>());
6868
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_);
7373
return EXIT_FAILURE;
7474
}
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_);
7979
return EXIT_FAILURE;
8080
}
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);
8485
try {
85-
environment.eval(parser.exprs_);
86+
environment->eval(parser->exprs_);
8687
} catch (parsing_error &ex) {
8788
errors::print_error(std::cerr, ex);
8889
return EXIT_FAILURE;
8990
}
9091
return EXIT_SUCCESS;
9192
}
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_);
9899
return;
99100
}
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_);
104105
return;
105106
}
106107
try {
107-
auto result = environment->eval(parser.exprs_);
108+
auto result = environment->eval(parser->exprs_);
108109
if (result != nullptr) { std::cout << colours::cyan("-> ") << result; }
109110
} catch (parsing_error &ex) { errors::print_error(std::cerr, ex); }
110111
}
@@ -120,9 +121,9 @@ int lisp_repl() {
120121
std::cout << "Type in expressions to evaluate them.\n";
121122
std::cout << "Input " << colours::cyan("(exit)") << " to exit from repl.\n";
122123
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");
126127
#ifdef PRINT_BUILTINS_YAKSHA_LISP
127128
std::cout << "Builtins:: ";
128129
bool first = true;
@@ -147,7 +148,7 @@ int lisp_repl() {
147148
exit = true;
148149
continue;
149150
}
150-
eval_line(line, &environment);
151+
eval_line(line, environment, &mm);
151152
std::cout << "\n";
152153
}
153154
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)