-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (41 loc) · 891 Bytes
/
main.cpp
File metadata and controls
48 lines (41 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// ConsVM - main
//
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
#include <fstream>
#include "consVM.h"
int main(int argc, char** argv)
{
std::ifstream in_file;
if (argc > 1) {
in_file.open(argv[1]);
if (!in_file.is_open()) {
std::cerr << "Error: Could not open " << argv[1] << std::endl;
return 1;
}
std::cin.rdbuf(in_file.rdbuf());
}
init_consvm();
for (;;) {
try {
if (read(true)) {
std::cout << "s-expr: "; print(top()); std::cout << std::endl;
push(global_env);
eval();
std::cout << "=> ";
println(top());
drop(1);
} else {
break;
}
} catch (const LispError& e) {
std::cerr << "Error: " << e.what() << std::endl;
if (e.is_fatal) {
return 1;
}
}
}
// std::cout << "End of sexpr stream" << std::endl;
return 0;
}