forked from goccy/gperl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgperl.cpp
More file actions
48 lines (46 loc) · 1.45 KB
/
Copy pathgperl.cpp
File metadata and controls
48 lines (46 loc) · 1.45 KB
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
#include <gperl.hpp>
using namespace std;
GPerlMemoryManager *mm;
GPerl::GPerl(int argc, char **argv)
{
if (argc < 2) exit(1);
const char *filename = argv[1];
char line[MAX_LINE_SIZE] = {0};
char script_[MAX_SCRIPT_SIZE] = {0};
char *tmp = script_;
char *script = script_;
FILE *fp = fopen(filename, "r");
while (fgets(line, MAX_LINE_SIZE, fp) != NULL) {
//DBG_PL("line = [%s]", line);
int line_size = strlen(line);
snprintf(tmp, line_size + 1, "%s\n", line);
tmp += line_size;
}
cwb = (char *)safe_malloc(MAX_CWB_SIZE);
memset(cwb, 0, MAX_CWB_SIZE);
mm = new GPerlMemoryManager();
GPerlTokenizer t;
std::vector<GPerlToken *> *tokens = t.tokenize(script);
t.annotateTokens(tokens);
DBG_PL("=============<TOKENIZE>============");
t.dump(tokens);
GPerlParser p(tokens, argc - 2, argv + 2);
DBG_PL("==============<PARSE>==============");
GPerlAST *ast = p.parse();
#ifdef USING_GRAPH_DEBUG
ast->show();//graph debug with graphviz
#endif
GPerlCompiler compiler;
DBG_PL("=============<COMPILE>=============");
GPerlVirtualMachineCode *codes = compiler.compile(ast);
DBG_PL("-----------<DUMP VMCODE>-----------");
compiler.dumpPureVMCode(codes);
DBG_PL("-----------------------------------");
GPerlVirtualMachine *vm = new GPerlVirtualMachine();
DBG_PL("=============<RUNTIME>=============");
vm->run(codes);//create threading code
vm->run(codes);//execute code
//fprintf(stderr, "%d\n", vm->run(codes));//execute code
fclose(fp);
mm->exit();
}