-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (52 loc) · 1.55 KB
/
main.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <memory>
#include <map>
#include <stack>
#include <variant>
#include <algorithm>
#include <sstream>
#include "lisp_interpreter.h"
#define PRM(msg) std::cout << __FUNCTION__ << ':' << __LINE__ << '\t' << msg << std::endl
#define assert(x) if (!(x)) PRM("ASSERT " #x)
int main() {
using namespace lisp_interpreter;
// R E P L
{
auto env = std::make_shared<env_t>();
std::string str;
while (true) {
context_t ctx;
std::cout << "lisp $ ";
std::getline(std::cin, str);
if (str == ":l") {
env = std::make_shared<env_t>();
str = "(__kernel_load \"standart.lispam\")";
} else if (str == "") {
break;
}
try {
object_sptr_t l;
{
LOG_DURATION(ctx.time_parse);
l = object_t::parse(str);
}
std::cout << "input: \t" << l->show() << std::endl;
{
ctx.time_eval = 159;
LOG_DURATION(ctx.time_eval);
l = l->eval(env, ctx);
}
std::cout << "result: \t" << l->show() << std::endl;
} catch (const std::exception& e) {
std::cout << "exception: \t" << e.what() << std::endl;
} catch (...) {
std::cout << "exception" << std::endl;
}
std::cout << "eval_calls: \t" << ctx.eval_calls << std::endl;
std::cout << "time_parse: \t" << ctx.time_parse << " ms" << std::endl;
std::cout << "time_eval: \t" << ctx.time_eval << " ms" << std::endl;
std::cout << "stream: \t" << ctx.stream.str() << std::endl;
}
}
return 0;
}