diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-24 07:20:55 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-24 07:20:55 +0100 |
| commit | e091fdcea9adc6521271c08574915fe617f3dd2d (patch) | |
| tree | b8c6eaa29156de21588b1c7044d55b4573a9f945 /src | |
| parent | c7c0b039041634de036a08f4a9a60d8782e79300 (diff) | |
[FIX] CompilerKit: Compiler infra fixes and test coverage improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src')
4 files changed, 27 insertions, 10 deletions
diff --git a/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp b/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp index 516c4d5..0d0cff7 100644 --- a/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp +++ b/src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp @@ -30,14 +30,15 @@ Int32 AssemblyFactory::Compile(STLString sourceFile, const Int32& arch) { try { std::filesystem::copy(sourceFile, compiledUnit); + auto ret = this->fMounted->CompileToFormat(compiledUnit, arch); + + std::filesystem::remove(compiledUnit); + return ret; } catch (...) { + std::filesystem::remove(compiledUnit); } - auto ret = this->fMounted->CompileToFormat(compiledUnit, arch); - - std::filesystem::remove(compiledUnit); - - return ret; + return NECTAR_INVALID_ARCH; } ///! @brief mount assembly backend. diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp index 36606a4..8146a88 100644 --- a/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp +++ b/src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp @@ -124,6 +124,10 @@ struct CompilerContext { UInt32 fInstructionCounter{0}; }; +/// @brief This function is for internal uses only, do not call it without a wrapper! +CK_IMPORT_C bool NectarCheckLine(CompilerKit::STLString& input); + + /// \brief Global compiler context (replaces kState) static CompilerContext kContext; @@ -281,7 +285,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile( CompilerKit::SyntaxLeafList::SyntaxLeaf syntax_tree; CompilerKit::STLString syntax_rem_buffer; - if (!NectarCheckFrontend(text)) return syntax_tree; + if (!NectarCheckLine(text)) return syntax_tree; std::size_t index{}; std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list; diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp index 82685ea..c636f3a 100644 --- a/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp +++ b/src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp @@ -18,11 +18,11 @@ using namespace CompilerKit; -static bool kInIfBody = false; +static bool kInIfBody = false; static bool kInElseBody = false; static bool kInTraitBody = false; -CK_IMPORT_C bool NectarCheckFrontend(CompilerKit::STLString& input) { +CK_IMPORT_C bool NectarCheckLine(CompilerKit::STLString& input) { if (input.empty()) return false; if (input.ends_with(":")) { @@ -49,7 +49,16 @@ CK_IMPORT_C bool NectarCheckFrontend(CompilerKit::STLString& input) { } } - if (input.find("(") != CompilerKit::STLString::npos) { + if (input.find(":=") != CompilerKit::STLString::npos) { + if (input.find(";") == CompilerKit::STLString::npos) { + Detail::print_error("An assignment call must always end with ';'", "check"); + return false; + } + } + + if (input.find("(") != CompilerKit::STLString::npos && + input.find("const") == CompilerKit::STLString::npos && + input.find("let") == CompilerKit::STLString::npos) { if (input.find(";") == CompilerKit::STLString::npos) { Detail::print_error("A function call must always end with ';'", "check"); return false; diff --git a/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp b/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp index 3fb8503..8b2b3bb 100644 --- a/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp +++ b/src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp @@ -122,6 +122,9 @@ struct CompilerContext { UInt32 fInstructionCounter{0}; }; +/// @brief This function is for internal uses only, do not call it without a wrapper! +CK_IMPORT_C bool NectarCheckLine(CompilerKit::STLString& input); + /// \brief Global compiler context (replaces kState) static CompilerContext kContext; @@ -288,7 +291,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarPTX::Compile( CompilerKit::SyntaxLeafList::SyntaxLeaf syntax_tree; CompilerKit::STLString syntax_rem_buffer; - if (!NectarCheckFrontend(text)) return syntax_tree; + if (!NectarCheckLine(text)) return syntax_tree; std::size_t index{}; std::vector<std::pair<CompilerKit::SyntaxKeyword, std::size_t>> keywords_list; |
