From 89612caf10640e427d4fe04bdd8abda4870b58c5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 28 Nov 2025 21:30:59 +0100 Subject: chore: CompilerKit: source code improvements and tweaks. Signed-off-by: Amlal El Mahrouss --- src/CompilerKit/AE.h | 9 +- src/CompilerKit/AST.h | 140 +++++++++++++++++++++ src/CompilerKit/Frontend.h | 138 -------------------- src/CompilerKit/StringKit.h | 48 +++---- src/CompilerKit/src/AST.cc | 75 +++++++++++ src/CompilerKit/src/AssemblyFactory.cc | 3 +- src/CompilerKit/src/Backend/Assembler32x0.cc | 2 +- src/CompilerKit/src/Backend/Assembler64x0.cc | 3 +- src/CompilerKit/src/Backend/AssemblerAMD64.cc | 3 +- src/CompilerKit/src/Backend/AssemblerARM64.cc | 3 +- src/CompilerKit/src/Backend/AssemblerPowerPC.cc | 3 +- src/CompilerKit/src/Frontend.cc | 61 --------- src/CompilerKit/src/Frontend/CCompiler64x0.cc | 2 +- src/CompilerKit/src/Frontend/CCompilerARM64.cc | 2 +- src/CompilerKit/src/Frontend/CCompilerPower64.cc | 2 +- .../src/Frontend/CPlusPlusCompilerAMD64.cc | 2 +- src/CompilerKit/src/Linker/DynamicLinker64PEF.cc | 4 +- src/CompilerKit/src/Macro/CPlusPlusPreprocessor.cc | 2 +- src/CompilerKit/src/StringKit.cc | 56 ++++----- src/CompilerKit/utils/AsmUtils.h | 2 +- src/CompilerKit/utils/CompilerUtils.h | 2 +- 21 files changed, 291 insertions(+), 271 deletions(-) create mode 100644 src/CompilerKit/AST.h delete mode 100644 src/CompilerKit/Frontend.h create mode 100644 src/CompilerKit/src/AST.cc delete mode 100644 src/CompilerKit/src/Frontend.cc (limited to 'src/CompilerKit') 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 -#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/AST.h b/src/CompilerKit/AST.h new file mode 100644 index 0000000..74db957 --- /dev/null +++ b/src/CompilerKit/AST.h @@ -0,0 +1,140 @@ +/* ======================================== + + Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license + +======================================== */ + +#pragma once + +#include + +#define CK_COMPILER_FRONTEND : public ::CompilerKit::CompilerFrontendInterface + +namespace CompilerKit { +inline static auto kInvalidFrontend = "(null)"; + +struct SyntaxLeafList; +struct SyntaxLeafList; +struct CompilerKeyword; + +/// =========================================================== /// +/// @note we want to do that to separate keywords. +/// =========================================================== /// + +enum KeywordKind { + kKeywordKindReserved = 0, + kKeywordKindNamespace = 100, + kKeywordKindFunctionStart, + kKeywordKindFunctionEnd, + kKeywordKindVariable, + kKeywordKindVariablePtr, + kKeywordKindType, + kKeywordKindTypePtr, + kKeywordKindExpressionBegin, + kKeywordKindExpressionEnd, + kKeywordKindArgSeparator, + kKeywordKindBodyStart, + kKeywordKindBodyEnd, + kKeywordKindClass, + kKeywordKindPtrAccess, + kKeywordKindAccess, + kKeywordKindIf, + kKeywordKindElse, + kKeywordKindElseIf, + kKeywordKindVariableAssign, + kKeywordKindVariableDec, + kKeywordKindVariableInc, + kKeywordKindConstant, + kKeywordKindTypedef, + kKeywordKindEndInstr, + kKeywordKindSpecifier, + kKeywordKindInvalid, + kKeywordKindReturn, + kKeywordKindCommentInline, + kKeywordKindCommentMultiLineStart, + kKeywordKindCommentMultiLineEnd, + kKeywordKindEq, + kKeywordKindNotEq, + kKeywordKindGreaterEq, + kKeywordKindLessEq, + kKeywordKindPtr, + kKeywordKindCount = kKeywordKindPtr - kKeywordKindNamespace + 1, +}; + +/// =========================================================== /// +/// \brief Compiler keyword information struct. +/// =========================================================== /// +struct CompilerKeyword { + CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {} + + STLString keyword_name{""}; + KeywordKind keyword_kind{kKeywordKindInvalid}; +}; + +struct SyntaxLeafList final { + struct SyntaxLeaf final { + Int32 fUserType{0U}; + CompilerKeyword fUserData{"", kKeywordKindInvalid}; + + STLString fUserValue{""}; + struct SyntaxLeaf* fNext{nullptr}; + }; + + std::vector fLeafList; + SizeType fNumLeafs{0}; + + SizeType SizeOf() { return fNumLeafs; } + std::vector& Get() { return fLeafList; } + SyntaxLeaf& At(SizeType index) { return fLeafList[index]; } +}; + +/// =========================================================== /// +/// find the perfect matching word in a haystack. +/// \param haystack base string +/// \param needle the string we search for. +/// \return if we found it or not. +/// =========================================================== /// +Bool find_word(STLString haystack, STLString needle) noexcept; + +/// =========================================================== /// +/// find a word within strict conditions and returns a range of it. +/// \param haystack +/// \param needle +/// \return position of needle. +/// =========================================================== /// +SizeType find_word_range(STLString haystack, STLString needle) noexcept; + +/// =========================================================== /// +/// @brief Compiler backend, implements a frontend, such as C, C++... +/// See Toolchain, for some examples. +/// =========================================================== /// +class CompilerFrontendInterface { + public: + explicit CompilerFrontendInterface() = default; + virtual ~CompilerFrontendInterface() = default; + + NECTI_COPY_DEFAULT(CompilerFrontendInterface); + + /// =========================================================== /// + // NOTE: cast this to your user defined ast. + /// =========================================================== /// + typedef VoidPtr AstType; + + /// =========================================================== /// + //! @brief Compile a syntax tree ouf of the text. + //! Also takes the source file name for metadata. + /// =========================================================== /// + + virtual CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) = 0; + + /// =========================================================== /// + //! @brief What language are we dealing with? + /// =========================================================== /// + virtual const char* Language(); + + /// =========================================================== /// + /// @brief Checks if language is a valid frontend. + /// =========================================================== /// + virtual bool IsValid(); +}; +} // namespace CompilerKit diff --git a/src/CompilerKit/Frontend.h b/src/CompilerKit/Frontend.h deleted file mode 100644 index df70048..0000000 --- a/src/CompilerKit/Frontend.h +++ /dev/null @@ -1,138 +0,0 @@ -/* ======================================== - - Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license - -======================================== */ - -#pragma once - -#include - -#define CK_COMPILER_FRONTEND : public ::CompilerKit::CompilerFrontendInterface - -namespace CompilerKit { -inline static auto kInvalidFrontend = "(null)"; - -struct SyntaxLeafList; -struct SyntaxLeafList; -struct CompilerKeyword; - -/// =========================================================== /// -/// @note we want to do that to separate keywords. -/// =========================================================== /// - -enum KeywordKind { - kKeywordKindNamespace, - kKeywordKindFunctionStart, - kKeywordKindFunctionEnd, - kKeywordKindVariable, - kKeywordKindVariablePtr, - kKeywordKindType, - kKeywordKindTypePtr, - kKeywordKindExpressionBegin, - kKeywordKindExpressionEnd, - kKeywordKindArgSeparator, - kKeywordKindBodyStart, - kKeywordKindBodyEnd, - kKeywordKindClass, - kKeywordKindPtrAccess, - kKeywordKindAccess, - kKeywordKindIf, - kKeywordKindElse, - kKeywordKindElseIf, - kKeywordKindVariableAssign, - kKeywordKindVariableDec, - kKeywordKindVariableInc, - kKeywordKindConstant, - kKeywordKindTypedef, - kKeywordKindEndInstr, - kKeywordKindSpecifier, - kKeywordKindInvalid, - kKeywordKindReturn, - kKeywordKindCommentInline, - kKeywordKindCommentMultiLineStart, - kKeywordKindCommentMultiLineEnd, - kKeywordKindEq, - kKeywordKindNotEq, - kKeywordKindGreaterEq, - kKeywordKindLessEq, - kKeywordKindPtr, -}; - -/// =========================================================== /// -/// \brief Compiler keyword information struct. -/// =========================================================== /// -struct CompilerKeyword { - CompilerKeyword(STLString name, KeywordKind kind) : keyword_name(name), keyword_kind(kind) {} - - STLString keyword_name{""}; - KeywordKind keyword_kind{kKeywordKindInvalid}; -}; - -struct SyntaxLeafList final { - struct SyntaxLeaf final { - Int32 fUserType{0U}; - CompilerKeyword fUserData{"", kKeywordKindInvalid}; - - STLString fUserValue{""}; - struct SyntaxLeaf* fNext{nullptr}; - }; - - std::vector fLeafList; - SizeType fNumLeafs{0}; - - SizeType SizeOf() { return fNumLeafs; } - std::vector& Get() { return fLeafList; } - SyntaxLeaf& At(SizeType index) { return fLeafList[index]; } -}; - -/// =========================================================== /// -/// find the perfect matching word in a haystack. -/// \param haystack base string -/// \param needle the string we search for. -/// \return if we found it or not. -/// =========================================================== /// -Bool find_word(STLString haystack, STLString needle) noexcept; - -/// =========================================================== /// -/// find a word within strict conditions and returns a range of it. -/// \param haystack -/// \param needle -/// \return position of needle. -/// =========================================================== /// -SizeType find_word_range(STLString haystack, STLString needle) noexcept; - -/// =========================================================== /// -/// @brief Compiler backend, implements a frontend, such as C, C++... -/// See Toolchain, for some examples. -/// =========================================================== /// -class CompilerFrontendInterface { - public: - explicit CompilerFrontendInterface() = default; - virtual ~CompilerFrontendInterface() = default; - - NECTI_COPY_DEFAULT(CompilerFrontendInterface); - - /// =========================================================== /// - // NOTE: cast this to your user defined ast. - /// =========================================================== /// - typedef VoidPtr AstType; - - /// =========================================================== /// - //! @brief Compile a syntax tree ouf of the text. - //! Also takes the source file name for metadata. - /// =========================================================== /// - - virtual CompilerKit::SyntaxLeafList::SyntaxLeaf Compile(std::string text, std::string file) = 0; - - /// =========================================================== /// - //! @brief What language are we dealing with? - /// =========================================================== /// - virtual const char* Language() { return kInvalidFrontend; } - - /// =========================================================== /// - /// @brief Checks if language is a valid frontend. - /// =========================================================== /// - virtual bool IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; } -}; -} // 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; -using BasicStringPtr = BasicString*; -using BasicStringRef = Ref; +using NEStringOr = ErrorOr; +using NEStringPtr = NEString*; +using NEStringRef = Ref; } // namespace CompilerKit #endif /* ifndef __NECTI_STRINGKIT__ */ diff --git a/src/CompilerKit/src/AST.cc b/src/CompilerKit/src/AST.cc new file mode 100644 index 0000000..5106a26 --- /dev/null +++ b/src/CompilerKit/src/AST.cc @@ -0,0 +1,75 @@ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license + +======================================== */ + +#include + +/** + * @file Frontend.cc + * @author Amlal El Mahrouss (amlal@nekernel.org) + * @brief AST of NeCTI + * @version 0.0.3 + * + * @copyright Copyright (c) 2025 Amlal El Mahrouss and NeKernel.org Contributors + * + */ + +namespace CompilerKit { +/// find the perfect matching word in a haystack. +/// \param haystack base string +/// \param needle the string we search for. +/// \return if we found it or not. +Bool find_word(STLString haystack, STLString needle) noexcept { + auto index = haystack.find(needle); + + // check for needle validity. + if (index == STLString::npos) return false; + + // declare lambda + auto not_part_of_word = [&](int index) { + if (std::isspace(haystack[index]) || std::ispunct(haystack[index])) return true; + + if (index <= 0 || index >= haystack.size()) return true; + + return false; + }; + + return not_part_of_word(index - 1) && not_part_of_word(index + needle.size()); +} + +/// find a word within strict conditions and returns a range of it. +/// \param haystack +/// \param needle +/// \return position of needle. +SizeType find_word_range(STLString haystack, STLString needle) noexcept { + auto index = haystack.find(needle); + + // check for needle validity. + if (index == STLString::npos) return false; + + if (!isalnum((haystack[index + needle.size() + 1])) && + !isdigit(haystack[index + needle.size() + 1]) && + !isalnum((haystack[index - needle.size() - 1])) && + !isdigit(haystack[index - needle.size() - 1])) { + return index; + } + + 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 -#include +#include #include #include #include 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 -#include +#include #include #include #include @@ -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 -#include +#include #include #include #include @@ -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 #include -#include +#include #include #include #include @@ -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 #include -#include +#include #include #include #include @@ -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.cc b/src/CompilerKit/src/Frontend.cc deleted file mode 100644 index baac34e..0000000 --- a/src/CompilerKit/src/Frontend.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* ======================================== - - Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license - -======================================== */ - -#include - -/** - * @file Frontend.cc - * @author Amlal El Mahrouss (amlal@nekernel.org) - * @brief Frontend API of NeCTI - * @version 0.0.2 - * - * @copyright Copyright (c) 2025 Amlal El Mahrouss and NeKernel.org Contributors - * - */ - -namespace CompilerKit { -/// find the perfect matching word in a haystack. -/// \param haystack base string -/// \param needle the string we search for. -/// \return if we found it or not. -Bool find_word(STLString haystack, STLString needle) noexcept { - auto index = haystack.find(needle); - - // check for needle validity. - if (index == STLString::npos) return false; - - // declare lambda - auto not_part_of_word = [&](int index) { - if (std::isspace(haystack[index]) || std::ispunct(haystack[index])) return true; - - if (index <= 0 || index >= haystack.size()) return true; - - return false; - }; - - return not_part_of_word(index - 1) && not_part_of_word(index + needle.size()); -} - -/// find a word within strict conditions and returns a range of it. -/// \param haystack -/// \param needle -/// \return position of needle. -SizeType find_word_range(STLString haystack, STLString needle) noexcept { - auto index = haystack.find(needle); - - // check for needle validity. - if (index == STLString::npos) return false; - - if (!isalnum((haystack[index + needle.size() + 1])) && - !isdigit(haystack[index + needle.size() + 1]) && - !isalnum((haystack[index - needle.size() - 1])) && - !isdigit(haystack[index - needle.size() - 1])) { - return index; - } - - return STLString::npos; -} -} // namespace CompilerKit \ No newline at end of file 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 +#include #include #include #include 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 +#include #include #include #include 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 +#include #include #include #include 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 +#include #include #include #include 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 -#include +#include #include #include #include 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 -#include +#include #include 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 #include -#include +#include #include #include #include -- cgit v1.2.3