This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
130 lines (89 loc) · 2.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <stack>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
// re-implemented getline()
#include "win_supp.h"
#include "string_stack.hpp"
// this is the class used in our stack
#include "calc_value.hpp"
// user defined variables
#include "user_variables.hpp"
// some useful functions
#include "utils.hpp"
int line = 0;
#include "core.hpp"
char* metaName;
extern char* progName;
void handle_sigint_file(int);
void handle_sigint_shell(int);
int main(int argc, char** argv){
metaName = *argv;
// having errors should be the default
bool showErrors = true;
// shell
if (argc == 1) {
line = 1; // required for alignment
// seed random
srand(time(NULL));
// set up a namespace for variables
UserVar first_node(NULL, " ", 0.0);
first_node.first = &first_node;
std::vector<UserVar> var_nodes;
var_nodes.reserve(2000); // overkill but it will prevent addresses from changing
var_nodes.push_back(first_node);
bool elseStatement = false;
std::vector<void*> freeable;
// the most important component to the language
std::stack<CalcValue> mainStack;
/*
shell_vars.nodes = & var_nodes;
shell_vars.elseStat = &elseStatement;
shell_vars.showErrors = &showErrors;
shell_vars.ms = &mainStack;
*/
// this handles Ctrl+C
signal(SIGINT, handle_sigint_shell);
// process commands as they come in
for (;;)
runShell(var_nodes, showErrors, mainStack, elseStatement, freeable);
// version info
} else if (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") == 0) {
printVersionInfo();
// help
} else if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
std::cout <<"Usage: yoda [ option | file ] ...\nOptions:"
" -h,\t--help\t: display's this help message (also --help)\n"
" -V,\t--version\t: display's version information (also --version)\n\n";
displayHelp();
// file
} else {
// seed random
srand (time(NULL));
// this handles Ctrl+C
signal(SIGINT, handle_sigint_file);
// start file
runFile(argv[1], showErrors);
// trash OS
#ifdef _WIN32
std::cin.ignore();
#endif
}
}
void handle_sigint_file(int){
printf("In file: %s On line: %d\n", progName, --line);
char* ln = fileutils::getLineFromFile(progName, line);
if (ln)
color_fprintf(stderr, 255, 0, 0, ln);
else
printf("\aERROR: getLineFromFile failed\n");
exit(EXIT_SUCCESS);
}
void handle_sigint_shell(int){
printf("\r");
//runShell(*shell_vars.nodes, *shell_vars.showErrors, *shell_vars.ms, *shell_vars.elseStat);
}