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 | |
| parent | c7c0b039041634de036a08f4a9a60d8782e79300 (diff) | |
[FIX] CompilerKit: Compiler infra fixes and test coverage improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | include/CompilerKit/Detail/Config.h | 3 | ||||
| -rw-r--r-- | src/CompilerKit/src/CodeGenerator+AssemblyFactory.cpp | 11 | ||||
| -rw-r--r-- | src/CompilerKit/src/Frontends/NectarCompiler+AMD64.cpp | 6 | ||||
| -rw-r--r-- | src/CompilerKit/src/Frontends/NectarCompiler+Chk.cpp | 15 | ||||
| -rw-r--r-- | src/CompilerKit/src/Frontends/NectarCompiler+PTX.cpp | 5 | ||||
| -rw-r--r-- | test/check/missing-syntax-1.nc | 10 | ||||
| -rw-r--r-- | test/check/missing-syntax-2.nc | 10 | ||||
| -rw-r--r-- | test/check/perfect-syntax-1.nc | 10 |
8 files changed, 57 insertions, 13 deletions
diff --git a/include/CompilerKit/Detail/Config.h b/include/CompilerKit/Detail/Config.h index 14d4fd0..3693754 100644 --- a/include/CompilerKit/Detail/Config.h +++ b/include/CompilerKit/Detail/Config.h @@ -67,7 +67,4 @@ inline bool install_signal(Int32 signal, void (*handler)(int)) noexcept { } // namespace CompilerKit -/// @brief This function is for internal uses only, do not call it without a wrapper! -CK_IMPORT_C bool NectarCheckFrontend(CompilerKit::STLString& input); - #endif // __COMPILERKIT_CONFIG_H__ 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; diff --git a/test/check/missing-syntax-1.nc b/test/check/missing-syntax-1.nc new file mode 100644 index 0000000..4f2e430 --- /dev/null +++ b/test/check/missing-syntax-1.nc @@ -0,0 +1,10 @@ +import cudaMalloc; + +const main() +{ + let ptr := 0; + let sz := 8; + cudaMalloc(ptr, sz); +} + + diff --git a/test/check/missing-syntax-2.nc b/test/check/missing-syntax-2.nc new file mode 100644 index 0000000..4f2e430 --- /dev/null +++ b/test/check/missing-syntax-2.nc @@ -0,0 +1,10 @@ +import cudaMalloc; + +const main() +{ + let ptr := 0; + let sz := 8; + cudaMalloc(ptr, sz); +} + + diff --git a/test/check/perfect-syntax-1.nc b/test/check/perfect-syntax-1.nc new file mode 100644 index 0000000..4f2e430 --- /dev/null +++ b/test/check/perfect-syntax-1.nc @@ -0,0 +1,10 @@ +import cudaMalloc; + +const main() +{ + let ptr := 0; + let sz := 8; + cudaMalloc(ptr, sz); +} + + |
