Perform typechecking
This commit is contained in:
parent
85dbce112f
commit
5ed26f4139
23
src/main.cpp
23
src/main.cpp
@ -95,13 +95,32 @@ std::optional<CompileOutput> compile(std::string_view in_filename) {
|
|||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
codegen::Scope scope{};
|
// Perform static analysis
|
||||||
|
|
||||||
|
typecheck::State typecheck_state{};
|
||||||
|
typecheck::Scope typecheck_scope{};
|
||||||
|
for (auto& tls : statements) {
|
||||||
|
std::cout << tls->formatted() << std::endl;
|
||||||
|
tls->typecheck(typecheck_state, typecheck_scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typecheck_state.errors.size() > 0) {
|
||||||
|
std::cerr << "Errors while typechecking:" << std::endl;
|
||||||
|
for (auto& error : typecheck_state.errors) {
|
||||||
|
std::cerr << " " << error.what() << std::endl;
|
||||||
|
std::cerr << " at " << error.m_meta.start.line + 1 << ":" << error.m_meta.start.col + 1;
|
||||||
|
std::cerr << " to " << error.m_meta.end.line + 1 << ":" << error.m_meta.end.col + 1 << std::endl;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
codegen::Scope cg_scope{};
|
||||||
|
|
||||||
// Compile parsed output
|
// Compile parsed output
|
||||||
try {
|
try {
|
||||||
for (auto& tls : statements) {
|
for (auto& tls : statements) {
|
||||||
std::cout << tls->formatted() << std::endl;
|
std::cout << tls->formatted() << std::endl;
|
||||||
tls->codegen(builder, scope);
|
tls->codegen(builder, cg_scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CompileError& error) {
|
catch (CompileError& error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user