Perform typechecking

This commit is contained in:
Sofia 2026-04-13 01:22:14 +03:00
parent 85dbce112f
commit 5ed26f4139

View File

@ -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
try {
for (auto& tls : statements) {
std::cout << tls->formatted() << std::endl;
tls->codegen(builder, scope);
tls->codegen(builder, cg_scope);
}
}
catch (CompileError& error) {