From 5ed26f41392c043d4213827430561443f82cf984 Mon Sep 17 00:00:00 2001 From: Sofia Date: Mon, 13 Apr 2026 01:22:14 +0300 Subject: [PATCH] Perform typechecking --- src/main.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5534955..13a2866 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -95,13 +95,32 @@ std::optional 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) {