summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-18 01:57:41 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-18 01:57:41 +0100
commit228479a454d325340326f4fd23e13d780884fd2a (patch)
treeee35d5eecde396e674d1a0e11c5372352a49fac4 /include
parent80de28e3472613e8f6aa8b2730d56b5307f4fb9a (diff)
chore & feat: New DLLLoader API and AST API improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/CompilerKit/AST.h25
-rw-r--r--include/CompilerKit/CodeGenerator.h5
-rw-r--r--include/CompilerKit/Utilities/DLL.h25
3 files changed, 33 insertions, 22 deletions
diff --git a/include/CompilerKit/AST.h b/include/CompilerKit/AST.h
index aee3ff1..a1819b1 100644
--- a/include/CompilerKit/AST.h
+++ b/include/CompilerKit/AST.h
@@ -70,7 +70,7 @@ enum KeywordKind {
/// \brief Compiler keyword information struct.
/// =========================================================== ///
struct SyntaxKeyword {
- SyntaxKeyword(STLString name, KeywordKind kind) : fKeywordName(name), fKeywordKind(kind) {}
+ SyntaxKeyword(const STLString& name, KeywordKind kind) : fKeywordName(name), fKeywordKind(kind) {}
STLString fKeywordName{""};
KeywordKind fKeywordKind{kKeywordKindInvalid};
@@ -78,10 +78,15 @@ struct SyntaxKeyword {
struct SyntaxLeafList final {
struct SyntaxLeaf final {
- Int32 fUserType{0U};
+ // \brief User data type.
+ Int32 fUserType{0U};
+ // \brief User data buffer.
SyntaxKeyword fUserData{"", kKeywordKindInvalid};
- STLString fUserValue{""};
+ // \brief User data value
+ STLString fUserValue{""};
+
+ // \brief Next user data on list.
struct SyntaxLeaf* fNext{nullptr};
};
@@ -90,8 +95,14 @@ struct SyntaxLeafList final {
ArrayType fLeafList;
SizeType fNumLeafs{0};
- SizeType NumLeafs() { return fNumLeafs; }
- ArrayType& Get() { return fLeafList; }
+ public:
+ const SizeType& NumLeafs() { return fNumLeafs; }
+ const SizeType& NumLeafs() const { return fNumLeafs; }
+ const ArrayType& Get() const { return fLeafList; }
+ ArrayType& Get() { return fLeafList; }
+ // \brief You can't get a reference of a leaf in a const context.
+ const SyntaxLeaf& At(const SizeType& index) const = delete;
+ // \breif Grab leaf from index.
SyntaxLeaf& At(const SizeType& index) { return fLeafList[index]; }
};
@@ -131,7 +142,7 @@ class ICompilerFrontend {
//! @brief Compile a syntax tree ouf of the text.
//! Also takes the source file name for metadata.
/// =========================================================== ///
- virtual SyntaxLeafList::SyntaxLeaf Compile(STLString text, STLString file) = 0;
+ virtual SyntaxLeafList::SyntaxLeaf Compile(STLString text, STLString file) { return {}; }
/// =========================================================== ///
//! @brief What language are we dealing with?
@@ -145,4 +156,4 @@ class ICompilerFrontend {
};
} // namespace CompilerKit
-#include <CompilerKit/AST.inl> \ No newline at end of file
+#include <CompilerKit/AST.inl>
diff --git a/include/CompilerKit/CodeGenerator.h b/include/CompilerKit/CodeGenerator.h
index f2875bf..8bee7b5 100644
--- a/include/CompilerKit/CodeGenerator.h
+++ b/include/CompilerKit/CodeGenerator.h
@@ -44,9 +44,8 @@ class AssemblyFactory final {
kArchCount = kArchUnknown - kArchAMD64,
};
- Int32 Compile(STLString sourceFile, const Int32& arch) noexcept;
-
- void Mount(WeakRef<IAssembly> mountPtr) noexcept;
+ Int32 Compile(STLString sourceFile, const Int32& arch);
+ void Mount(WeakRef<IAssembly> mountPtr);
WeakRef<IAssembly> Unmount() noexcept;
private:
diff --git a/include/CompilerKit/Utilities/DLL.h b/include/CompilerKit/Utilities/DLL.h
index 6f14c13..ea6789d 100644
--- a/include/CompilerKit/Utilities/DLL.h
+++ b/include/CompilerKit/Utilities/DLL.h
@@ -13,22 +13,23 @@
namespace CompilerKit {
class DLLLoader final {
public:
- typedef Int32 (*EntryT)(Int32 argc, Char const* argv[]);
- using DLL = VoidPtr;
- using Mutex = std::mutex;
+ using EntryT = Int32 (*)(Int32 argc, Char const* argv[]);
+ using HandleT = VoidPtr;
+ using MutexT = std::mutex;
+
EntryT fEntrypoint{nullptr};
private:
- DLL mDLL{nullptr};
- Mutex mMutex;
+ HandleT mDLL{nullptr};
+ MutexT mMutex;
public:
- explicit operator bool() { return this->mDLL && this->fEntrypoint; }
+ explicit operator bool() { return this->mDLL; }
- DLLLoader& operator()(const Char* path, const Char* fEntrypoint) {
- if (!path || !fEntrypoint) return *this;
+ DLLLoader& operator()(const Char* path, const Char* entrypoint) {
+ if (!path || !entrypoint) return *this;
- std::lock_guard<Mutex> lock(this->mMutex);
+ std::lock_guard<MutexT> lock(this->mMutex);
if (this->mDLL) {
this->Destroy();
@@ -40,7 +41,7 @@ class DLLLoader final {
return *this;
}
- this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, fEntrypoint));
+ this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, entrypoint));
if (!this->fEntrypoint) {
this->Destroy();
@@ -52,7 +53,7 @@ class DLLLoader final {
NECTI_COPY_DELETE(DLLLoader)
- explicit DLLLoader() = default;
+ DLLLoader() = default;
~DLLLoader() { this->Destroy(); }
private:
@@ -65,4 +66,4 @@ class DLLLoader final {
this->fEntrypoint = nullptr;
}
};
-} // namespace CompilerKit \ No newline at end of file
+} // namespace CompilerKit