Repository navigation
Expand file tree
/
Copy pathncc.cpp
More file actions
185 lines (154 loc) · 6.1 KB
/
Copy pathncc.cpp
File metadata and controls
185 lines (154 loc) · 6.1 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "libnc.h"
#include "token.h"
#include "lexer.h"
#include "parser.h"
#include "ast_printer.h"
#include "symbol_table.h"
#include "intern.h"
#include "type.h"
#include "type_check.h"
#include "token.cpp"
#include "lexer.cpp"
#include "parser.cpp"
#include "ast_printer.cpp"
#include "symbol_table.cpp"
#include "intern.cpp"
#include "type.cpp"
#include "type_check.cpp"
void DisplayTokens(TokenArray Arr, Str8 Source);
void TestTokens(TokenArray Arr);
#if defined(NC_DEBUG)
void
AppRegisterLogEndpoints(void)
{
LogEndpointParams LogConsoleParams = {
"CONSOLE"_s8,
LOG_ENDPOINT_FUNC_NAME(Console),
LOG_ENDPOINT_FLUSH_FUNC_NAME(Console),
NULL,
0,
LOG_LEVEL_KIND_NORMAL,
};
LogRegisterEndpoint(LogConsoleParams);
}
void
AppUnregisterLogEndpoints(void)
{}
#endif
void
MainThreadBaseEntryPoint(int ArgC, char** ArgV)
{
ThreadSetName("[MAIN]"_s8);
TempArena Scratch = GetScratch(NULL, 0);
Str8List CLIStrings = StrListFromCLIArgs(Scratch.MemPool, ArgC, ArgV);
CommandLine CLI = CommandLineFromStrList(Scratch.MemPool, CLIStrings);
LogInit();
#if defined(NC_DEBUG)
AppRegisterLogEndpoints();
#endif
EntryPoint(&CLI);
#if defined(NC_DEBUG)
AppUnregisterLogEndpoints();
#endif
ReleaseScratch(Scratch);
}
void
EntryPoint(CommandLine* CLI)
{
Arena* MainMemPool = ArenaAlloc();
#if defined(NC_OS_WIN)
// Str8 Path = "H:/C++/nc_comp/test_programs/generated_larger_program.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base-simple-add.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base-proc-C-fact.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base0-abs.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base1-assign-const.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base5-fact.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base6-fwd.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base7-if.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-base8-max.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-baseb-read-err1.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-basec-while1.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-baseg-static.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-repeat.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-baseh-ref-before-assign.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-logop.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/test-logopx.nc"_s8;
// Str8 Path = "H:/C++/nc_comp/test_programs/benchmark_1mb.nc"_s8;
Str8 Path = "H:/C++/nc_comp/test_programs/vec_test.nc"_s8;
#else
Str8 Path = "/mnt/h/C++/nc_comp/test_programs/generated_larger_program.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base-simple-add.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base-proc-C-fact.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base0-abs.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base1-assign-const.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base5-fact.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base6-fwd.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base7-if.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-base8-max.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-baseb-read-err1.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-basec-while1.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-baseg-static.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-baseh-ref-before-assign.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-logop.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/test-logopx.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/benchmark_1mb.nc"_s8;
// Str8 Path = "/mnt/h/C++/nc_comp/test_programs/vec_test.nc"_s8;
#endif
Arena* LexerMemPool = ArenaAlloc();
Arena* ParserMemPool = ArenaAlloc();
NamePool* Names = NamePoolInit();
SymTabInit(Names);
BuiltinTypesInit();
TypeTableInit(Names);
LexerInternKeywords(Names);
ParserInternNames(Names);
Str8 Source = ReadFileContentsEx(
MainMemPool,
Path,
NC_SIMD_ALIGN256
);
if (Source.Size) {
TokenArray Arr = {};
PerfCounter LexStart = TimeGetTimestamp();
Arr = LexString(LexerMemPool, Source, Names);
PerfCounter LexStop = TimeGetTimestamp();
f64 LexTimeMSecs = TimeElapsedMSec(LexStart, LexStop);
SymTabPrepare();
AST* Tree = NULL;
PerfCounter ParseStart = TimeGetTimestamp();
Tree = ParseTokens(ParserMemPool, &Arr, Source);
PerfCounter ParseStop = TimeGetTimestamp();
f64 ParseTimeMSecs = TimeElapsedMSec(ParseStart, ParseStop);
PerfCounter TypeCheckStart = TimeGetTimestamp();
CheckAST(Tree, &Arr);
PerfCounter TypeCheckStop = TimeGetTimestamp();
f64 TypeCheckTimeMSecs = TimeElapsedMSec(TypeCheckStart, TypeCheckStop);
f64 TotalTimeMSecs = LexTimeMSecs + ParseTimeMSecs + TypeCheckTimeMSecs;
PrintAST(Tree, &Arr, Source);
PrintOut(
"\n\n"
"+--------------+-------------+\n"
"| lexer | %lf ms |\n"
"+--------------+-------------+\n"
"| parser | %lf ms |\n"
"+--------------+-------------+\n"
"| type checker | %lf ms |\n"
"+==============+=============+\n"
"| total | %lf ms |\n"
"+--------------+-------------+\n",
LexTimeMSecs,
ParseTimeMSecs,
TypeCheckTimeMSecs,
TotalTimeMSecs
);
} else {
PrintErr(
"could not open file \"%.*s\" for reading",
PRINT_STR(Path)
);
}
SymTabReset();
ArenaRelease(ParserMemPool);
ArenaRelease(LexerMemPool);
ArenaRelease(MainMemPool);
}