diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-28 21:30:59 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-28 21:30:59 +0100 |
| commit | 89612caf10640e427d4fe04bdd8abda4870b58c5 (patch) | |
| tree | 566e17dabb3abd8352dfa212a928ac2c6427518d /src/CompilerKit | |
| parent | d4fb3e16ab67e79e7b92e17a53e8e2615c0f7086 (diff) | |
chore: CompilerKit: source code improvements and tweaks.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/CompilerKit')
19 files changed, 98 insertions, 78 deletions
diff --git a/src/CompilerKit/AE.h b/src/CompilerKit/AE.h index 7b6d9b4..438bb36 100644 --- a/src/CompilerKit/AE.h +++ b/src/CompilerKit/AE.h @@ -12,14 +12,15 @@ #include <CompilerKit/Defines.h> -#define kAEVer (0x0121) +#define kAEIdentVersion (0x0122) #define kAEMag0 'A' #define kAEMag1 'E' +#define kAEMag2 'F' -#define kAESymbolLen (255) +#define kAESymbolLen (256) #define kAEPad (8) -#define kAEMagLen (2) +#define kAEMagLen (3) #define kAENullType (0x00) /// @author Amlal El Mahrouss @@ -35,7 +36,7 @@ namespace CompilerKit { // This object format, is reloctable. typedef struct AEHeader final { Char fMagic[kAEMagLen] = {}; - UInt16 fVersion{kAEVer}; + UInt16 fVersion{kAEIdentVersion}; Char fArch{}; Char fSubArch{}; SizeType fCount{}; diff --git a/src/CompilerKit/Frontend.h b/src/CompilerKit/AST.h index df70048..74db957 100644 --- a/src/CompilerKit/Frontend.h +++ b/src/CompilerKit/AST.h @@ -22,7 +22,8 @@ struct CompilerKeyword; /// =========================================================== /// enum KeywordKind { - kKeywordKindNamespace, + kKeywordKindReserved = 0, + kKeywordKindNamespace = 100, kKeywordKindFunctionStart, kKeywordKindFunctionEnd, kKeywordKindVariable, @@ -57,6 +58,7 @@ enum KeywordKind { kKeywordKindGreaterEq, kKeywordKindLessEq, kKeywordKindPtr, + kKeywordKindCount = kKeywordKindPtr - kKeywordKindNamespace + 1, }; /// =========================================================== /// @@ -128,11 +130,11 @@ class CompilerFrontendInterface { /// =========================================================== /// //! @brief What language are we dealing with? /// =========================================================== /// - virtual const char* Language() { return kInvalidFrontend; } + virtual const char* Language(); /// =========================================================== /// /// @brief Checks if language is a valid frontend. /// =========================================================== /// - virtual bool IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; } + virtual bool IsValid(); }; } // namespace CompilerKit diff --git a/src/CompilerKit/StringKit.h b/src/CompilerKit/StringKit.h index eb7ccc3..f93b135 100644 --- a/src/CompilerKit/StringKit.h +++ b/src/CompilerKit/StringKit.h @@ -20,24 +20,24 @@ /// =========================================================== /// namespace CompilerKit { -class StringBuilder; -class BasicString; +class NEStringBuilder; +class NEString; /** - * @brief BasicString class, contains a C string and manages it. + * @brief NEString class, contains a C string and manages it. * @note No need to manage it it's getting deleted by default. */ -class BasicString final { +class NEString final { public: - explicit BasicString() = delete; + explicit NEString() = delete; - explicit BasicString(SizeType Sz) noexcept : m_Sz(Sz) { + explicit NEString(SizeType Sz) noexcept : m_Sz(Sz) { m_Data = new Char[Sz]; assert(m_Data); } - ~BasicString() noexcept { + ~NEString() noexcept { if (m_Data) { memset(m_Data, 0, m_Sz); delete[] m_Data; @@ -46,7 +46,7 @@ class BasicString final { } } - NECTI_COPY_DEFAULT(BasicString); + NECTI_COPY_DEFAULT(NEString); Char* Data(); const Char* CData() const; @@ -55,12 +55,12 @@ class BasicString final { bool operator==(const Char* rhs) const; bool operator!=(const Char* rhs) const; - bool operator==(const BasicString& rhs) const; - bool operator!=(const BasicString& rhs) const; + bool operator==(const NEString& rhs) const; + bool operator!=(const NEString& rhs) const; - BasicString& operator+=(const Char* rhs); - BasicString& operator+=(const Char rhs); - BasicString& operator+=(const BasicString& rhs); + NEString& operator+=(const Char* rhs); + NEString& operator+=(const Char rhs); + NEString& operator+=(const NEString& rhs); explicit operator bool() { return m_Data && m_Data[0] != 0; } @@ -71,24 +71,24 @@ class BasicString final { SizeType m_Sz{0}; SizeType m_Cur{0}; - friend class StringBuilder; + friend class NEStringBuilder; }; /** - * @brief StringBuilder class + * @brief NEStringBuilder class * @note These results shall call be delete[] after they're used. */ -struct StringBuilder final { - static BasicString Construct(const Char* data); - static BasicString FromInt(const char* fmt, int n); - static BasicString FromBool(const char* fmt, bool n); - static BasicString Format(const char* fmt, const char* from); - static Bool Equals(const char* lhs, const char* rhs); +struct NEStringBuilder final { + static NEString Construct(const Char* data); + static NEString FromInt(const char* fmt, int n); + static NEString FromBool(const char* fmt, bool n); + static NEString Format(const char* fmt, const char* from); + static Bool Equals(const char* lhs, const char* rhs); }; -using BasicStringOr = ErrorOr<BasicString>; -using BasicStringPtr = BasicString*; -using BasicStringRef = Ref<BasicString>; +using NEStringOr = ErrorOr<NEString>; +using NEStringPtr = NEString*; +using NEStringRef = Ref<NEString>; } // namespace CompilerKit #endif /* ifndef __NECTI_STRINGKIT__ */ diff --git a/src/CompilerKit/src/Frontend.cc b/src/CompilerKit/src/AST.cc index baac34e..5106a26 100644 --- a/src/CompilerKit/src/Frontend.cc +++ b/src/CompilerKit/src/AST.cc @@ -4,13 +4,13 @@ ======================================== */ -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> /** * @file Frontend.cc * @author Amlal El Mahrouss (amlal@nekernel.org) - * @brief Frontend API of NeCTI - * @version 0.0.2 + * @brief AST of NeCTI + * @version 0.0.3 * * @copyright Copyright (c) 2025 Amlal El Mahrouss and NeKernel.org Contributors * @@ -58,4 +58,18 @@ SizeType find_word_range(STLString haystack, STLString needle) noexcept { return STLString::npos; } + +/// =========================================================== /// +//! @brief What language are we dealing with? +/// =========================================================== /// +const char* CompilerFrontendInterface::Language() { + return kInvalidFrontend; +} + +/// =========================================================== /// +/// @brief Checks if language is a valid frontend. +/// =========================================================== /// +bool CompilerFrontendInterface::IsValid() { + return strcmp(this->Language(), kInvalidFrontend) > 0; +} } // namespace CompilerKit
\ No newline at end of file diff --git a/src/CompilerKit/src/AssemblyFactory.cc b/src/CompilerKit/src/AssemblyFactory.cc index 5c606e9..185c522 100644 --- a/src/CompilerKit/src/AssemblyFactory.cc +++ b/src/CompilerKit/src/AssemblyFactory.cc @@ -11,8 +11,7 @@ * @file AssemblyFactory.cc * @author Amlal El Mahrouss (amlal@nekernel.org) * @brief Assembly API of NeCTI - * @version 0.0.2 - * + * @version 0.0.3 * @copyright Copyright (c) 2024-2025 Amlal El Mahrouss * */ diff --git a/src/CompilerKit/src/Backend/Assembler32x0.cc b/src/CompilerKit/src/Backend/Assembler32x0.cc index 6ffaa6e..51e4265 100644 --- a/src/CompilerKit/src/Backend/Assembler32x0.cc +++ b/src/CompilerKit/src/Backend/Assembler32x0.cc @@ -22,7 +22,7 @@ #endif #include <CompilerKit/AE.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/PEF.h> #include <CompilerKit/impl/32x0.h> #include <CompilerKit/utils/CompilerUtils.h> diff --git a/src/CompilerKit/src/Backend/Assembler64x0.cc b/src/CompilerKit/src/Backend/Assembler64x0.cc index f9052d2..75f0a81 100644 --- a/src/CompilerKit/src/Backend/Assembler64x0.cc +++ b/src/CompilerKit/src/Backend/Assembler64x0.cc @@ -22,7 +22,7 @@ #endif #include <CompilerKit/AE.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/PEF.h> #include <CompilerKit/impl/64x0.h> #include <CompilerKit/utils/CompilerUtils.h> @@ -130,6 +130,7 @@ NECTI_MODULE(AssemblerMain64x0) { hdr.fMagic[0] = kAEMag0; hdr.fMagic[1] = kAEMag1; + hdr.fMagic[2] = kAEMag2; hdr.fSize = sizeof(CompilerKit::AEHeader); hdr.fArch = kOutputArch; diff --git a/src/CompilerKit/src/Backend/AssemblerAMD64.cc b/src/CompilerKit/src/Backend/AssemblerAMD64.cc index 8c7e21c..7523d05 100644 --- a/src/CompilerKit/src/Backend/AssemblerAMD64.cc +++ b/src/CompilerKit/src/Backend/AssemblerAMD64.cc @@ -29,7 +29,7 @@ #define kAssemblerPragmaSym '%' #include <CompilerKit/AE.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/PEF.h> #include <CompilerKit/impl/X64.h> #include <algorithm> @@ -186,6 +186,7 @@ NECTI_MODULE(AssemblerMainAMD64) { hdr.fMagic[0] = kAEMag0; hdr.fMagic[1] = kAEMag1; + hdr.fMagic[2] = kAEMag2; hdr.fSize = sizeof(CompilerKit::AEHeader); hdr.fArch = kOutputArch; diff --git a/src/CompilerKit/src/Backend/AssemblerARM64.cc b/src/CompilerKit/src/Backend/AssemblerARM64.cc index 4961e61..e50b8ec 100644 --- a/src/CompilerKit/src/Backend/AssemblerARM64.cc +++ b/src/CompilerKit/src/Backend/AssemblerARM64.cc @@ -21,7 +21,7 @@ #include <CompilerKit/AE.h> #include <CompilerKit/ErrorID.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/PEF.h> #include <CompilerKit/Version.h> #include <CompilerKit/impl/Aarch64.h> @@ -135,6 +135,7 @@ NECTI_MODULE(AssemblerMainARM64) { hdr.fMagic[0] = kAEMag0; hdr.fMagic[1] = kAEMag1; + hdr.fMagic[2] = kAEMag2; hdr.fSize = sizeof(CompilerKit::AEHeader); hdr.fArch = kOutputArch; diff --git a/src/CompilerKit/src/Backend/AssemblerPowerPC.cc b/src/CompilerKit/src/Backend/AssemblerPowerPC.cc index b4f14ea..7074123 100644 --- a/src/CompilerKit/src/Backend/AssemblerPowerPC.cc +++ b/src/CompilerKit/src/Backend/AssemblerPowerPC.cc @@ -21,7 +21,7 @@ #include <CompilerKit/AE.h> #include <CompilerKit/ErrorID.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/PEF.h> #include <CompilerKit/Version.h> #include <CompilerKit/impl/PowerPC.h> @@ -135,6 +135,7 @@ NECTI_MODULE(AssemblerMainPower64) { hdr.fMagic[0] = kAEMag0; hdr.fMagic[1] = kAEMag1; + hdr.fMagic[2] = kAEMag2; hdr.fSize = sizeof(CompilerKit::AEHeader); hdr.fArch = kOutputArch; diff --git a/src/CompilerKit/src/Frontend/CCompiler64x0.cc b/src/CompilerKit/src/Frontend/CCompiler64x0.cc index bed4ddd..ecc2c34 100644 --- a/src/CompilerKit/src/Frontend/CCompiler64x0.cc +++ b/src/CompilerKit/src/Frontend/CCompiler64x0.cc @@ -10,7 +10,7 @@ /// BUGS: 0 /// TODO: none -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/UUID.h> #include <CompilerKit/impl/64x0.h> #include <CompilerKit/utils/CompilerUtils.h> diff --git a/src/CompilerKit/src/Frontend/CCompilerARM64.cc b/src/CompilerKit/src/Frontend/CCompilerARM64.cc index ea39a31..665c02d 100644 --- a/src/CompilerKit/src/Frontend/CCompilerARM64.cc +++ b/src/CompilerKit/src/Frontend/CCompilerARM64.cc @@ -10,7 +10,7 @@ /// BUGS: 0 /// TODO: none -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/UUID.h> #include <CompilerKit/impl/Aarch64.h> #include <CompilerKit/utils/CompilerUtils.h> diff --git a/src/CompilerKit/src/Frontend/CCompilerPower64.cc b/src/CompilerKit/src/Frontend/CCompilerPower64.cc index ccc5cf8..8a1a943 100644 --- a/src/CompilerKit/src/Frontend/CCompilerPower64.cc +++ b/src/CompilerKit/src/Frontend/CCompilerPower64.cc @@ -7,7 +7,7 @@ * ======================================================== */ -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/UUID.h> #include <CompilerKit/impl/PowerPC.h> #include <CompilerKit/utils/CompilerUtils.h> diff --git a/src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc b/src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc index d715a3a..c0f366d 100644 --- a/src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc +++ b/src/CompilerKit/src/Frontend/CPlusPlusCompilerAMD64.cc @@ -31,7 +31,7 @@ #define kRed "\e[0;31m" #define kWhite "\e[0;97m" -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/PEF.h> #include <CompilerKit/UUID.h> #include <CompilerKit/impl/X64.h> diff --git a/src/CompilerKit/src/Linker/DynamicLinker64PEF.cc b/src/CompilerKit/src/Linker/DynamicLinker64PEF.cc index 176a608..4236ceb 100644 --- a/src/CompilerKit/src/Linker/DynamicLinker64PEF.cc +++ b/src/CompilerKit/src/Linker/DynamicLinker64PEF.cc @@ -240,8 +240,8 @@ NECTI_MODULE(DynamicLinker64PEF) { reader_protocol.file_pointer_ >> hdr; if (hdr.fMagic[0] == kAEMag0 && hdr.fMagic[1] == kAEMag1 && - hdr.fSize == sizeof(CompilerKit::AEHeader)) { - if (hdr.fArch != kArch) { + hdr.fSize == sizeof(CompilerKit::AEHeader) && hdr.fMagic[2] == kAEMag2) { + if (hdr.fArch != kArch && hdr.fVersion == kAEIdentVersion) { if (kVerbose) kConsoleOut << "is this a FAT binary? : "; if (!kFatBinaryEnable) { diff --git a/src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc b/src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc index ed53782..980f0e0 100644 --- a/src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc +++ b/src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc @@ -10,7 +10,7 @@ /// BUGS: 0 #include <CompilerKit/ErrorID.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <algorithm> #include <filesystem> #include <fstream> diff --git a/src/CompilerKit/src/StringKit.cc b/src/CompilerKit/src/StringKit.cc index d612947..45e50a9 100644 --- a/src/CompilerKit/src/StringKit.cc +++ b/src/CompilerKit/src/StringKit.cc @@ -11,7 +11,7 @@ * @file StringKit.cc * @author Amlal (amlal@nekernel.org) * @brief C++ string manipulation API. - * @version 0.2 + * @version 0.0.2 * @date 2024-01-23 * * @copyright Copyright (c) Amlal El Mahrouss @@ -22,58 +22,58 @@ namespace CompilerKit { -Char* BasicString::Data() { +Char* NEString::Data() { return m_Data; } -const Char* BasicString::CData() const { +const Char* NEString::CData() const { return m_Data; } -SizeType BasicString::Length() const { +SizeType NEString::Length() const { return strlen(m_Data); } -bool BasicString::operator==(const BasicString& rhs) const { +bool NEString::operator==(const NEString& rhs) const { const SizeType len = Length(); if (rhs.Length() != len) return false; return memcmp(m_Data, rhs.m_Data, len) == 0; } -bool BasicString::operator==(const Char* rhs) const { +bool NEString::operator==(const Char* rhs) const { const SizeType rhs_len = string_length(rhs); const SizeType len = Length(); if (rhs_len != len) return false; return memcmp(m_Data, rhs, len) == 0; } -bool BasicString::operator!=(const BasicString& rhs) const { +bool NEString::operator!=(const NEString& rhs) const { return !(*this == rhs); } -bool BasicString::operator!=(const Char* rhs) const { +bool NEString::operator!=(const Char* rhs) const { return !(*this == rhs); } -BasicString StringBuilder::Construct(const Char* data) { - if (!data || *data == 0) return BasicString(0); +NEString NEStringBuilder::Construct(const Char* data) { + if (!data || *data == 0) return NEString(0); - BasicString view(strlen(data)); + NEString view(strlen(data)); view += data; return view; } -BasicString StringBuilder::FromInt(const char* fmt, int i) { - if (!fmt) return BasicString(0); +NEString NEStringBuilder::FromInt(const char* fmt, int i) { + if (!fmt) return NEString(0); Char result[sizeof(int64_t)] = {0}; - if (!to_str(result, sizeof(int64_t), i)) return BasicString(0); + if (!to_str(result, sizeof(int64_t), i)) return NEString(0); const SizeType fmt_len = string_length(fmt); const SizeType res_len = string_length(result); - BasicString output(fmt_len + res_len); + NEString output(fmt_len + res_len); bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { @@ -88,14 +88,14 @@ BasicString StringBuilder::FromInt(const char* fmt, int i) { return output; } -BasicString StringBuilder::FromBool(const char* fmt, bool val) { - if (!fmt) return BasicString(0); +NEString NEStringBuilder::FromBool(const char* fmt, bool val) { + if (!fmt) return NEString(0); const Char* boolean_expr = val ? "true" : "false"; const SizeType fmt_len = string_length(fmt); const SizeType res_len = string_length(boolean_expr); - BasicString output(fmt_len + res_len); + NEString output(fmt_len + res_len); bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { @@ -110,7 +110,7 @@ BasicString StringBuilder::FromBool(const char* fmt, bool val) { return output; } -bool StringBuilder::Equals(const char* lhs, const char* rhs) { +bool NEStringBuilder::Equals(const char* lhs, const char* rhs) { const SizeType lhs_len = string_length(lhs); const SizeType rhs_len = string_length(rhs); @@ -118,13 +118,13 @@ bool StringBuilder::Equals(const char* lhs, const char* rhs) { return memcmp(lhs, rhs, lhs_len) == 0; } -BasicString StringBuilder::Format(const char* fmt, const char* fmtRight) { - if (!fmt || !fmtRight) return BasicString(0); +NEString NEStringBuilder::Format(const char* fmt, const char* fmtRight) { + if (!fmt || !fmtRight) return NEString(0); const SizeType fmt_len = string_length(fmt); const SizeType rhs_len = string_length(fmtRight); - BasicString output(fmt_len + rhs_len); + NEString output(fmt_len + rhs_len); bool inserted = false; for (SizeType idx = 0; idx < fmt_len; ++idx) { @@ -139,10 +139,10 @@ BasicString StringBuilder::Format(const char* fmt, const char* fmtRight) { return output; } -BasicString& BasicString::operator+=(const Char* rhs) { +NEString& NEString::operator+=(const Char* rhs) { const SizeType rhs_len = strlen(rhs); if (this->m_Cur + rhs_len >= this->m_Sz) { - throw std::runtime_error("out_of_bounds: BasicString"); + throw std::runtime_error("out_of_bounds: NEString"); } memcpy(this->m_Data + this->m_Cur, rhs, rhs_len); @@ -153,9 +153,9 @@ BasicString& BasicString::operator+=(const Char* rhs) { return *this; } -BasicString& BasicString::operator+=(const BasicString& rhs) { +NEString& NEString::operator+=(const NEString& rhs) { if (this->m_Cur + rhs.m_Cur >= this->m_Sz) { - throw std::runtime_error("out_of_bounds: BasicString"); + throw std::runtime_error("out_of_bounds: NEString"); } memcpy(this->m_Data + this->m_Cur, rhs.CData(), rhs.m_Cur); @@ -165,9 +165,9 @@ BasicString& BasicString::operator+=(const BasicString& rhs) { return *this; } -BasicString& BasicString::operator+=(const Char ch) { +NEString& NEString::operator+=(const Char ch) { if (this->m_Cur + 1 >= this->m_Sz) { - throw std::runtime_error("out_of_bounds.."); + throw std::runtime_error("out_of_bounds."); } this->m_Data[this->m_Cur++] = ch; diff --git a/src/CompilerKit/utils/AsmUtils.h b/src/CompilerKit/utils/AsmUtils.h index 897fcbe..83086e3 100644 --- a/src/CompilerKit/utils/AsmUtils.h +++ b/src/CompilerKit/utils/AsmUtils.h @@ -7,7 +7,7 @@ #pragma once #include <CompilerKit/Compiler.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/utils/CompilerUtils.h> using namespace CompilerKit; diff --git a/src/CompilerKit/utils/CompilerUtils.h b/src/CompilerKit/utils/CompilerUtils.h index 1b086ee..607418d 100644 --- a/src/CompilerKit/utils/CompilerUtils.h +++ b/src/CompilerKit/utils/CompilerUtils.h @@ -8,7 +8,7 @@ #include <CompilerKit/Compiler.h> #include <CompilerKit/ErrorID.h> -#include <CompilerKit/Frontend.h> +#include <CompilerKit/AST.h> #include <CompilerKit/Version.h> #include <ThirdParty/Dialogs.h> #include <iostream> |
