-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
84 lines (72 loc) · 2.21 KB
/
main.c
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
#include "passes/primorder.h"
#include "passes/collectnames.h"
#include "passes/to_cells.h"
#include "passes/typeinfer.h"
//Being used to test function name collection on single file
extern char* realpath(const char* path, char* resolved_path);
#define GENPRINT(tok) else if (in.data.tokenval == tok) { printf("%s", #tok); }
void display(lexid_tree in, nametable names) {
string toprint;
printf("%s", "\n on line: ");
printf("%d", (int) in.data.loc.lineno);
printf("%s", " col: ");
printf("%d", (int) in.data.loc.linepos);
printf(" ");
if (in.data.tokenval == INT) {
printf("%s", "integer: ");
printf("%d", in.data.attr.intval);
}
else if (in.data.tokenval == FLOAT) {
printf("%s", "float: ");
printf("%.20f", in.data.attr.floatval);
}
else if (in.data.tokenval == STRING) {
printf("%s", "STRING CONSTANT");
}
else if (in.data.tokenval == FILEREF) {
printf("FILE REF: %s", to_cstring(in.data.attr.stringval));
}
GENPRINT(DEF)
GENPRINT(LAMBDA)
GENPRINT(NAMESPACE)
GENPRINT(IMPORT)
GENPRINT(TYPE)
GENPRINT(SUBS)
GENPRINT(SUPS)
else if (in.data.tokenval == EXPR) {
printf("%s", "(");
size_t i = 0;
while (i < in.children.size) {
display(in.children.begin[i], names);
i++;
}
printf("%s", ")");
}
else {
toprint = char_dynarray_copy(nametable_get(names, in.data));
toprint = char_dynarray_add(toprint, (char) 0);
printf("%s", toprint.begin);
}
printf("%s", " ");
return;
}
int main(int argc, const char* argv[]) {
fileLoc* file;
if (argc < 2) {
file = load_stdin();
}
else {
file = load_file(realpath(argv[1], NULL));
}
collectnames_result program = collectnames(primorder(parse(lex(file))));
//Initialize the type universe so we can do things.
init_type_universe();
//Print out our parse tree
display(program.parse.AST, program.parse.names);
//Convert to a list of definitions
def_collection defs = to_cells(program);
finalize_type_universe();
printf("\n\n Inferring types \n\n");
defs = typeinfer(defs);
return 0;
}