-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (37 loc) · 828 Bytes
/
main.cpp
File metadata and controls
47 lines (37 loc) · 828 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
#include "lua4dec.hpp"
int main(int argc, char** argv)
{
Vector<Byte> buffer;
if(argc < 2)
{
printf("Please provide a compiled lua script as argument.\n");
return 1;
}
else if(argc == 2)
{
#ifndef NDEBUG
printf("Reading file: %s\n", argv[1]);
#endif
buffer = read_file(argv[1]);
}
else if(argc > 3)
{
// pipe it here
return 2;
}
auto* iter = buffer.data();
auto chunk = read_chunk(iter);
#ifndef NDEBUG
debug_chunk(chunk);
#endif
auto* ast = new Ast();
auto state = State();
auto result = parse_function(state, ast, chunk.main);
if(result == Status::OK)
{
print_ast(ast);
if(argc == 3)
write_file(argv[2], ast);
}
return static_cast<unsigned>(result);
}