-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
99 lines (74 loc) · 2.43 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <csignal>
#include <cstring>
#include "frame.hpp"
void sigintHandle(int sig_num) {
Frame::Exit e(Frame::Exit::ERROR, "Interrupt", "the program has been killed.", main_entry_frame->feed.lineNumber());
e.genMsg(main_entry_frame->feed);
std::cout <<e.backtrace();
#ifdef _WIN32
std::cin.ignore();
#endif
exit(sig_num);
}
// trace on
// print out every single token
extern const char* ys_help_info;
extern const char* ys_version_info;
int main(int argc, char** argv) {
signal(SIGINT, sigintHandle);
// this entire file should prolly be reworked, works for now tho so idc
bool from_file = false;
for (int i = 1; i < argc; i++)
if (argv[i][0] != '-') {
from_file = true;
} else if (!strcmp(argv[i], "--tron") || !strcmp(argv[i], "-t")) {
CodeFeed::enable_token_trace = true;
} else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-V")) {
std::cout <<ys_version_info <<std::endl;
return 0;
} else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
std::cout <<ys_help_info <<std::endl;
return 0;
}
if (!from_file) {
main_entry_frame->feed.isStdin = true;
while (true) {
// reset feed so that errors don't recur
main_entry_frame->feed.reset();
// get next line
if (!main_entry_frame->feed.getLine("> "))
return 0;
Frame::Exit e = main_entry_frame->run(main_entry_frame);
if (e.reason == Frame::Exit::ERROR)
std::cout <<e.backtrace();
else if (!main_entry_frame->stack.empty())
std::cout << main_entry_frame->stack.back().depict();
std::cout <<std::endl;
}
}
// else -> run file
// run program
for (int i = 1; i < argc; i++)
if (**(argv + i) != '-') {
main_entry_frame->feed.loadFile(argv[1]);
Frame::Exit e = main_entry_frame->run(main_entry_frame);
if (e.reason == Frame::Exit::ERROR) {
std::cout <<"Entry Point: Global Line " <<e.line + 1 <<std::endl;
std::cout <<e.backtrace();
#ifdef _WIN32
std::cin.ignore();
#endif
}
}
}
const char* ys_version_info = "2.0.1 - compiled: " __DATE__ " " __TIME__;
const char* ys_help_info =
"usage: Usage: yoda [ option | file ] ...\n"
"Options:\n"
" -h,\t--help\t: display's this help message\n"
" -V,\t--version\t: display's version information \n"
" -t,\t--tron\t: prints every token as it's interpreted\n"
"\n"
"If this is your first time using this language, you should check the README on this project's github page.\n"
"<https://github.com/dvtate/ys-alpha>\n";