From ba08245e02d6ddb965e18ff6e71fc974a34c383d Mon Sep 17 00:00:00 2001 From: Arron Nelson Date: Sun, 27 Apr 2025 10:34:53 -0700 Subject: [PATCH] Backup. --- CMakeLists.txt | 26 ++- Main.bin | Bin 56 -> 4473 bytes include/arctyx/Arctyx.h | 3 +- include/arctyx/compiler/Architecture.h | 6 +- include/arctyx/compiler/Combination.h | 15 -- include/arctyx/compiler/Compiler.h | 22 ++- include/arctyx/compiler/Instruction.h | 10 +- include/arctyx/compiler/Interpretation.h | 27 +++ include/arctyx/compiler/Keyword.h | 2 +- include/arctyx/compiler/Language.h | 46 ++++- include/arctyx/compiler/Symbol.h | 44 +++++ include/arctyx/compiler/Token.h | 11 +- include/arctyx/linker/formats/ELF.h | 2 +- include/arctyx/linker/formats/ELF_Program.h | 2 +- include/arctyx/linker/formats/ELF_Section.h | 2 +- include/arctyx/linker/formats/ELF_Sym.h | 2 +- src/Arctyx.cpp | 12 ++ src/compiler/Architecture.cpp | 28 ++- src/compiler/Combination.cpp | 1 - src/compiler/Instruction.cpp | 25 ++- src/compiler/Interpretation.cpp | 45 +++++ src/compiler/Language.cpp | 184 +++++++++++++++++++- src/compiler/Symbol.cpp | 71 ++++++++ src/compiler/Token.cpp | 25 ++- src/main.cpp | 17 +- 25 files changed, 551 insertions(+), 77 deletions(-) delete mode 100644 include/arctyx/compiler/Combination.h create mode 100644 include/arctyx/compiler/Interpretation.h create mode 100644 include/arctyx/compiler/Symbol.h delete mode 100644 src/compiler/Combination.cpp create mode 100644 src/compiler/Interpretation.cpp create mode 100644 src/compiler/Symbol.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 30b61ac..b3adb80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,12 @@ add_library(Arctyx SHARED src/compiler/Language.cpp include/arctyx/compiler/Language.h src/compiler/Token.cpp include/arctyx/compiler/Token.h src/Arctyx.cpp include/arctyx/Arctyx.h - src/compiler/Combination.cpp - include/arctyx/compiler/Combination.h + src/compiler/Interpretation.cpp + include/arctyx/compiler/Interpretation.h src/compiler/Keyword.cpp include/arctyx/compiler/Keyword.h + include/arctyx/compiler/Symbol.h + src/compiler/Symbol.cpp ) add_executable(ArctyxTools @@ -53,11 +55,21 @@ target_include_directories(Arctyx PUBLIC "${PROJECT_SOURCE_DIR}/include") if (IS_OS_LINUX) add_compile_definitions(LWE_WS_XCB) + + target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/lib") + target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/bin") + target_include_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/include") + + target_link_libraries(Arctyx PUBLIC xcb xcb-cursor xcb-xfixes xcb-xinput z asound EHS_Dyn) +elseif (IS_OS_WINDOWS) + target_compile_definitions(Arctyx PRIVATE EHS_LIB_EXPORT) + target_compile_definitions(ArctyxTools PRIVATE EHS_LIB_IMPORT) + + target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/EHS/lib") + target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/EHS/bin") + target_include_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/EHS/include") + + target_link_libraries(Arctyx PUBLIC EHS_Dyn) endif() -target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/lib") -target_link_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/bin") -target_include_directories(Arctyx PUBLIC "${USER_HOME_DIRECTORY}/.local/include") - -target_link_libraries(Arctyx PUBLIC xcb xcb-cursor xcb-xfixes xcb-xinput z asound EHS_Dyn) target_link_libraries(ArctyxTools PRIVATE Arctyx) \ No newline at end of file diff --git a/Main.bin b/Main.bin index 78776ff614a8c288cc4f8ea9d1e61ec5f71ae4b6..21351728c6982fa6af22ae65b782b87a7b7774b2 100644 GIT binary patch literal 4473 zcmeHLF%E)25FAj9cGwtgj4z2{7xkFd{lAO3$8JFG7W<~;od$$@^ent8@DluN>G?Z;gWFu=d#Z3h o4n+5E>01yJ67l>_2yr&{JMH;%YLhFS7>Pa?J<{9 literal 56 zcmeY`et?mIfx+YWaWK_uDhlQu;sa9rtRBY?*ns$k|AFk(oSb|eh4TEOoD@Ya0GwJ5 A -class Arctyx +class EHS_LIB_IO Arctyx { private: static void Initialize(); diff --git a/include/arctyx/compiler/Architecture.h b/include/arctyx/compiler/Architecture.h index 6af7f8e..e6f4cfd 100644 --- a/include/arctyx/compiler/Architecture.h +++ b/include/arctyx/compiler/Architecture.h @@ -4,14 +4,16 @@ #include "Instruction.h" -class Architecture +class EHS_LIB_IO Architecture { private: + friend class Arctyx; + ehs::UInt_64 id; ehs::Str_8 name; ehs::Array instructions; - static ehs::Array architectures; + static ehs::Array architectures; public: Architecture(); diff --git a/include/arctyx/compiler/Combination.h b/include/arctyx/compiler/Combination.h deleted file mode 100644 index b6cb593..0000000 --- a/include/arctyx/compiler/Combination.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -#include "Token.h" - -class Combination -{ -private: - ehs::Array tokens; - - -public: - -}; diff --git a/include/arctyx/compiler/Compiler.h b/include/arctyx/compiler/Compiler.h index 7b9637e..34e2593 100644 --- a/include/arctyx/compiler/Compiler.h +++ b/include/arctyx/compiler/Compiler.h @@ -1 +1,21 @@ -#pragma once \ No newline at end of file +#pragma once + +#include +#include + +#include "Architecture.h" +#include "Language.h" +#include "Symbol.h" + +class Compiler +{ +private: + const Architecture *architecture; + const Language *language; + ehs::Array symbols; + +public: + Compiler(); + + Compiler(const Architecture *arch, const Language *lang); +}; \ No newline at end of file diff --git a/include/arctyx/compiler/Instruction.h b/include/arctyx/compiler/Instruction.h index 9f442c7..85014db 100644 --- a/include/arctyx/compiler/Instruction.h +++ b/include/arctyx/compiler/Instruction.h @@ -1,10 +1,16 @@ #pragma once + #include #include -class Instruction +class Architecture; + +class EHS_LIB_IO Instruction { private: + friend class Architecture; + + Architecture *arch; ehs::UInt_64 id; ehs::Str_8 name; ehs::UInt_8 size; @@ -33,6 +39,8 @@ public: Instruction &operator=(const Instruction &ins); + const Architecture *GetArchitecture() const; + ehs::UInt_64 GetId() const; ehs::Str_8 GetName() const; diff --git a/include/arctyx/compiler/Interpretation.h b/include/arctyx/compiler/Interpretation.h new file mode 100644 index 0000000..868d464 --- /dev/null +++ b/include/arctyx/compiler/Interpretation.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "Instruction.h" +#include "Token.h" + +class EHS_LIB_IO Interpretation : public Token +{ +private: + Instruction result; + +public: + Interpretation() = default; + + Interpretation(const TokenT &type, ehs::Str_8 value, Instruction result); + + Interpretation(Interpretation &&other) noexcept; + + Interpretation(const Interpretation &other); + + Interpretation &operator=(Interpretation &&other) noexcept; + + Interpretation &operator=(const Interpretation &other); + + Instruction GetResult() const; +}; diff --git a/include/arctyx/compiler/Keyword.h b/include/arctyx/compiler/Keyword.h index edc2ddd..778ad19 100644 --- a/include/arctyx/compiler/Keyword.h +++ b/include/arctyx/compiler/Keyword.h @@ -3,7 +3,7 @@ #include "Instruction.h" -class Keyword +class EHS_LIB_IO Keyword { private: ehs::Str_8 identifier; diff --git a/include/arctyx/compiler/Language.h b/include/arctyx/compiler/Language.h index 85e2abc..c32aa0e 100644 --- a/include/arctyx/compiler/Language.h +++ b/include/arctyx/compiler/Language.h @@ -3,22 +3,28 @@ #include #include #include +#include -#include "Combination.h" +#include "Interpretation.h" -class Language +class EHS_LIB_IO Language { private: + friend class Arctyx; + ehs::UInt_64 id; ehs::Str_8 name; - ehs::Array keywords; + ehs::Version version; + ehs::Char_8 eol; ehs::Array separators; - ehs::Array interpretations; + ehs::Array interpretations; + + static ehs::Array languages; public: Language(); - Language(ehs::Str_8 name); + Language(ehs::Str_8 name, const ehs::Version &version); Language(Language &&lang) noexcept; @@ -32,4 +38,34 @@ public: ehs::Str_8 GetName() const; + ehs::Version GetVersion() const; + + void SetEOL(const ehs::Char_8 &newEOL); + + ehs::Char_8 GetEOL() const; + + ehs::Array GetSeparators() const; + + bool HasSeparator(const ehs::Char_8 &separator) const; + + bool AddSeparator(const ehs::Char_8 &separator); + + ehs::Array GetInterpretations() const; + + bool HasInterpretation(const TokenT &type, const ehs::Str_8 &name) const; + + const Interpretation *GetInterpretation(const TokenT &type, const ehs::Str_8 &name) const; + + bool AddInterpretation(Interpretation interpretation); + + static bool Has(const ehs::UInt_64 &id); + + static bool Has(const ehs::Str_8 &name); + + static const Language *Get(const ehs::UInt_64 &id); + + static const Language *Get(const ehs::Str_8 &name); + + static bool Add(Language lang); + }; diff --git a/include/arctyx/compiler/Symbol.h b/include/arctyx/compiler/Symbol.h new file mode 100644 index 0000000..94cb657 --- /dev/null +++ b/include/arctyx/compiler/Symbol.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include + +enum class SymbolType +{ + UNKNOWN, + VARIABLE, + FUNCTION, + CLASS, + MEMBER, + METHOD +}; + +class Symbol +{ +private: + SymbolType type; + ehs::UInt_64 id; + ehs::Str_8 name; + ehs::UInt_64 address; + +public: + Symbol(); + + Symbol(const SymbolType &type, ehs::Str_8 name, const ehs::UInt_64 &address); + + Symbol(Symbol &&other) noexcept; + + Symbol(const Symbol &other); + + Symbol &operator=(Symbol &&other) noexcept; + + Symbol &operator=(const Symbol &other); + + SymbolType GetType() const; + + ehs::Str_8 GetName() const; + + ehs::UInt_64 GetId() const; + + ehs::UInt_64 GetAddress() const; +}; \ No newline at end of file diff --git a/include/arctyx/compiler/Token.h b/include/arctyx/compiler/Token.h index f18f7d7..6526c62 100644 --- a/include/arctyx/compiler/Token.h +++ b/include/arctyx/compiler/Token.h @@ -2,8 +2,9 @@ #include -enum class TokenType : ehs::UInt_8 +enum class TokenT : ehs::UInt_8 { + UNKNOWN, VALUE, KEYWORD, IDENTIFIER, @@ -11,16 +12,16 @@ enum class TokenType : ehs::UInt_8 COMPOUND_OPERATOR }; -class Token +class EHS_LIB_IO Token { private: - TokenType type; + TokenT type; ehs::Str_8 value; public: Token(); - Token(TokenType type, ehs::Str_8 value); + Token(const TokenT &type, ehs::Str_8 value); Token(Token &&token) noexcept; @@ -30,7 +31,7 @@ public: Token &operator=(const Token &token); - TokenType GetType() const; + TokenT GetType() const; ehs::Str_8 GetValue() const; }; diff --git a/include/arctyx/linker/formats/ELF.h b/include/arctyx/linker/formats/ELF.h index 3108f4a..83c61dc 100644 --- a/include/arctyx/linker/formats/ELF.h +++ b/include/arctyx/linker/formats/ELF.h @@ -17,7 +17,7 @@ #define ELF_64_BIT_HEADER_SIZE 64 #define ELF_32_BIT_HEADER_SIZE 52 -class ELF +class EHS_LIB_IO ELF { private: ehs::UInt_8 bitDepth; diff --git a/include/arctyx/linker/formats/ELF_Program.h b/include/arctyx/linker/formats/ELF_Program.h index 8216ee1..d50ab7e 100644 --- a/include/arctyx/linker/formats/ELF_Program.h +++ b/include/arctyx/linker/formats/ELF_Program.h @@ -14,7 +14,7 @@ class ELF; -class ELF_Program +class EHS_LIB_IO ELF_Program { private: friend class ELF; diff --git a/include/arctyx/linker/formats/ELF_Section.h b/include/arctyx/linker/formats/ELF_Section.h index 11ca686..cfdb3d2 100644 --- a/include/arctyx/linker/formats/ELF_Section.h +++ b/include/arctyx/linker/formats/ELF_Section.h @@ -17,7 +17,7 @@ #define SECH_SIZE 64 -class ELF_Section +class EHS_LIB_IO ELF_Section { private: friend class ELF; diff --git a/include/arctyx/linker/formats/ELF_Sym.h b/include/arctyx/linker/formats/ELF_Sym.h index 41be2fe..4be3ce9 100644 --- a/include/arctyx/linker/formats/ELF_Sym.h +++ b/include/arctyx/linker/formats/ELF_Sym.h @@ -74,7 +74,7 @@ #define SYMH_SIZE 24 -class ELF_Sym +class EHS_LIB_IO ELF_Sym { private: ehs::UInt_32 nameOffset; diff --git a/src/Arctyx.cpp b/src/Arctyx.cpp index 7884ff6..d51037a 100644 --- a/src/Arctyx.cpp +++ b/src/Arctyx.cpp @@ -1,7 +1,10 @@ #include "arctyx/Arctyx.h" #include +#include +#include "arctyx/compiler/Architecture.h" +#include "arctyx/compiler/Language.h" #include "arctyx/compiler/Token.h" void Arctyx::Initialize() @@ -10,4 +13,13 @@ void Arctyx::Initialize() void Arctyx::Uninitialize() { + for (ehs::Size i = 0; Architecture::architectures.Size(); ++i) + delete Architecture::architectures[i]; + + Architecture::architectures.Clear(); + + for (ehs::UInt_64 i = 0; i < Language::languages.Size(); ++i) + delete Language::languages[i]; + + Language::languages.Clear(); } diff --git a/src/compiler/Architecture.cpp b/src/compiler/Architecture.cpp index 82f3982..192c33f 100644 --- a/src/compiler/Architecture.cpp +++ b/src/compiler/Architecture.cpp @@ -1,6 +1,6 @@ #include "arctyx/compiler/Architecture.h" -ehs::Array Architecture::architectures; +ehs::Array Architecture::architectures; Architecture::Architecture() : id(0) @@ -13,13 +13,17 @@ Architecture::Architecture(ehs::Str_8 name) } Architecture::Architecture(Architecture &&arch) noexcept - : id(arch.id), name((ehs::Str_8 &&)arch.name) + : id(arch.id), name((ehs::Str_8 &&)arch.name), instructions((ehs::Array &&)arch.instructions) { + for (ehs::Size i = 0; i < instructions.Size(); ++i) + instructions[i].arch = this; } Architecture::Architecture(const Architecture &arc) - : id(arc.id), name(arc.name) + : id(arc.id), name(arc.name), instructions(arc.instructions) { + for (ehs::Size i = 0; i < instructions.Size(); ++i) + instructions[i].arch = this; } Architecture & Architecture::operator=(Architecture &&arc) noexcept @@ -29,6 +33,10 @@ Architecture & Architecture::operator=(Architecture &&arc) noexcept id = arc.id; name = (ehs::Str_8 &&)arc.name; + instructions = (ehs::Array &&)arc.instructions; + + for (ehs::Size i = 0; i < instructions.Size(); ++i) + instructions[i].arch = this; arc.id = 0; @@ -42,6 +50,10 @@ Architecture & Architecture::operator=(const Architecture &arc) id = arc.id; name = arc.name; + instructions = arc.instructions; + + for (ehs::Size i = 0; i < instructions.Size(); ++i) + instructions[i].arch = this; return *this; } @@ -89,6 +101,8 @@ bool Architecture::AddInstruction(Instruction ins) if (HasInstruction(ins.GetId())) return false; + ins.arch = this; + instructions.Push((Instruction &&)ins); return true; @@ -97,7 +111,7 @@ bool Architecture::AddInstruction(Instruction ins) bool Architecture::Has(const ehs::UInt_64 &id) { for (ehs::UInt_64 i = 0; i < architectures.Size(); ++i) - if (architectures[i].GetId() == id) + if (architectures[i]->GetId() == id) return true; return false; @@ -111,8 +125,8 @@ bool Architecture::Has(const ehs::Str_8 &name) const Architecture *Architecture::Get(const ehs::UInt_64 &id) { for (ehs::UInt_64 i = 0; i < architectures.Size(); ++i) - if (architectures[i].GetId() == id) - return &architectures[i]; + if (architectures[i]->GetId() == id) + return architectures[i]; return nullptr; } @@ -127,7 +141,7 @@ bool Architecture::Add(Architecture arc) if (Has(arc.GetId())) return false; - architectures.Push((Architecture &&)arc); + architectures.Push(new Architecture((Architecture &&)arc)); return true; } diff --git a/src/compiler/Combination.cpp b/src/compiler/Combination.cpp deleted file mode 100644 index 6eb5fdc..0000000 --- a/src/compiler/Combination.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "arctyx/compiler/Combination.h" diff --git a/src/compiler/Instruction.cpp b/src/compiler/Instruction.cpp index 562f0be..8922d8c 100644 --- a/src/compiler/Instruction.cpp +++ b/src/compiler/Instruction.cpp @@ -6,49 +6,50 @@ Instruction::~Instruction() } Instruction::Instruction() - : id(0), size(0), code(nullptr) + : arch(nullptr), id(0), size(0), code(nullptr) { } Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_8 &size, ehs::Byte *code) - : id(name.Hash_64()), name((ehs::Str_8 &&)name), size(size), code(code) + : arch(nullptr), id(name.Hash_64()), name((ehs::Str_8 &&)name), size(size), code(code) { } Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_64 &code) - : id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) + : arch(nullptr), id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) { *(ehs::UInt_64 *)this->code = code; } Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_32 &code) - : id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) + : arch(nullptr), id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) { *(ehs::UInt_32 *)this->code = code; } Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_16 &code) - : id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) + : arch(nullptr), id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) { *(ehs::UInt_16 *)this->code = code; } Instruction::Instruction(ehs::Str_8 name, const ehs::UInt_8 &code) - : id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) + : arch(nullptr), id(name.Hash_64()), name((ehs::Str_8 &&)name), size(sizeof(code)), code(new ehs::Byte[size]) { *this->code = code; } Instruction::Instruction(Instruction &&ins) noexcept - : id(ins.id), name((ehs::Str_8 &&)ins.name), size(ins.size), code(ins.code) + : arch(ins.arch), id(ins.id), name((ehs::Str_8 &&)ins.name), size(ins.size), code(ins.code) { + ins.arch = nullptr; ins.id = 0; ins.size = 0; ins.code = nullptr; } Instruction::Instruction(const Instruction &ins) - : id(ins.id), name(ins.name), size(ins.size), code(new ehs::Byte[size]) + : arch(nullptr), id(ins.id), name(ins.name), size(ins.size), code(new ehs::Byte[size]) { ehs::Util::Copy(code, ins.code, size); } @@ -58,11 +59,13 @@ Instruction &Instruction::operator=(Instruction &&ins) noexcept if (this == &ins) return *this; + arch = ins.arch; id = ins.id; name = (ehs::Str_8 &&)ins.name; size = ins.size; code = ins.code; + ins.arch = nullptr; ins.id = 0; ins.size = 0; ins.code = nullptr; @@ -75,6 +78,7 @@ Instruction &Instruction::operator=(const Instruction &ins) if (this == &ins) return *this; + arch = nullptr; id = ins.id; name = ins.name; size = ins.size; @@ -85,6 +89,11 @@ Instruction &Instruction::operator=(const Instruction &ins) return *this; } +const Architecture* Instruction::GetArchitecture() const +{ + return arch; +} + ehs::UInt_64 Instruction::GetId() const { return id; diff --git a/src/compiler/Interpretation.cpp b/src/compiler/Interpretation.cpp new file mode 100644 index 0000000..5384257 --- /dev/null +++ b/src/compiler/Interpretation.cpp @@ -0,0 +1,45 @@ +#include "arctyx/compiler/Interpretation.h" + +Interpretation::Interpretation(const TokenT& type, ehs::Str_8 value, Instruction result) + : Token(type, (ehs::Str_8 &&)value), result((Instruction &&)result) +{ +} + +Interpretation::Interpretation(Interpretation&& other) noexcept + : Token((Token &&)other), result((Instruction &&)other.result) +{ +} + +Interpretation::Interpretation(const Interpretation& other) + : Token(other), result(other.result) +{ +} + +Interpretation& Interpretation::operator=(Interpretation&& other) noexcept +{ + if (this == &other) + return *this; + + Token::operator=((Token &&)other); + + result = (Instruction &&)other.result; + + return *this; +} + +Interpretation& Interpretation::operator=(const Interpretation& other) +{ + if (this == &other) + return *this; + + Token::operator=(other); + + result = other.result; + + return *this; +} + +Instruction Interpretation::GetResult() const +{ + return result; +} diff --git a/src/compiler/Language.cpp b/src/compiler/Language.cpp index 5f41894..5c11906 100644 --- a/src/compiler/Language.cpp +++ b/src/compiler/Language.cpp @@ -1 +1,183 @@ -#include "arctyx/compiler/Language.h" \ No newline at end of file +#include "arctyx/compiler/Language.h" + +ehs::Array Language::languages; + +Language::Language() + : id(0), eol('\n') +{ +} + +Language::Language(ehs::Str_8 name, const ehs::Version& version) + : id(name.Hash_64()), name((ehs::Str_8 &&)name), version(version), eol('\n') +{ +} + +Language::Language(Language&& lang) noexcept + : id(lang.id), name((ehs::Str_8 &&)lang.name), version(lang.version), eol(lang.eol), + separators((ehs::Array &&)lang.separators), + interpretations((ehs::Array &&)lang.interpretations) +{ + lang.id = 0; + lang.version = {}; + lang.eol = '\n'; +} + +Language::Language(const Language& lang) + : id(lang.id), name(lang.name), version(lang.version), eol(lang.eol), separators(lang.separators), + interpretations(lang.interpretations) +{ +} + +Language& Language::operator=(Language&& lang) noexcept +{ + if (this == &lang) + return *this; + + id = lang.id; + name = (ehs::Str_8 &&)lang.name; + version = lang.version; + eol = lang.eol; + separators = (ehs::Array &&)lang.separators; + interpretations = (ehs::Array &&)lang.interpretations; + + lang.id = 0; + lang.version = {}; + lang.eol = '\n'; + + return *this; +} + +Language& Language::operator=(const Language& lang) +{ + if (this == &lang) + return *this; + + id = lang.id; + name = lang.name; + version = lang.version; + eol = lang.eol; + separators = lang.separators; + interpretations = lang.interpretations; + + return *this; +} + +ehs::UInt_64 Language::GetId() const +{ + return id; +} + +ehs::Str_8 Language::GetName() const +{ + return name; +} + +ehs::Version Language::GetVersion() const +{ + return version; +} + +void Language::SetEOL(const ehs::Char_8& newEOL) +{ + eol = newEOL; +} + +ehs::Char_8 Language::GetEOL() const +{ + return eol; +} + +ehs::Array Language::GetSeparators() const +{ + return separators; +} + +bool Language::HasSeparator(const ehs::Char_8& separator) const +{ + for (ehs::Size i = 0; i < separators.Size(); ++i) + if (separators[i] == separator) + return true; + + return false; +} + +bool Language::AddSeparator(const ehs::Char_8& separator) +{ + if (HasSeparator(separator)) + return false; + + separators.Push(separator); + + return true; +} + +ehs::Array Language::GetInterpretations() const +{ + return interpretations; +} + +bool Language::HasInterpretation(const TokenT &type, const ehs::Str_8& name) const +{ + for (ehs::Size i = 0; i < interpretations.Size(); ++i) + if (interpretations[i].GetType() == type && interpretations[i].GetValue() == name) + return true; + + return false; +} + +const Interpretation *Language::GetInterpretation(const TokenT &type, const ehs::Str_8& name) const +{ + for (ehs::Size i = 0; i < interpretations.Size(); ++i) + if (interpretations[i].GetType() == type && interpretations[i].GetValue() == name) + return &interpretations[i]; + + return nullptr; +} + +bool Language::AddInterpretation(Interpretation interpretation) +{ + if (HasInterpretation(interpretation.GetType(), interpretation.GetValue())) + return false; + + interpretations.Push((Interpretation &&)interpretation); + + return true; +} + +bool Language::Has(const ehs::UInt_64& id) +{ + for (ehs::UInt_64 i = 0; i < languages.Size(); ++i) + if (languages[i]->GetId() == id) + return true; + + return false; +} + +bool Language::Has(const ehs::Str_8& name) +{ + return Has(name.Hash_64()); +} + +const Language* Language::Get(const ehs::UInt_64& id) +{ + for (ehs::UInt_64 i = 0; i < languages.Size(); ++i) + if (languages[i]->GetId() == id) + return languages[i]; + + return nullptr; +} + +const Language* Language::Get(const ehs::Str_8& name) +{ + return Get(name.Hash_64()); +} + +bool Language::Add(Language lang) +{ + if (Has(lang.GetId())) + return false; + + languages.Push(new Language((Language &&)lang)); + + return true; +} diff --git a/src/compiler/Symbol.cpp b/src/compiler/Symbol.cpp new file mode 100644 index 0000000..46bd314 --- /dev/null +++ b/src/compiler/Symbol.cpp @@ -0,0 +1,71 @@ +#include "arctyx/compiler/Symbol.h" + +Symbol::Symbol() + : type(SymbolType::UNKNOWN), id(0), address(0) +{ +} + +Symbol::Symbol(const SymbolType& type, ehs::Str_8 name, const ehs::UInt_64& address) + : type(type), id(name.Hash_64()), name((ehs::Str_8 &&)name), address(address) +{ +} + +Symbol::Symbol(Symbol&& other) noexcept + : type(other.type), id(other.id), name((ehs::Str_8 &&)other.name), address(other.address) +{ +} + +Symbol::Symbol(const Symbol &other) + : type(other.type), id(other.id), name(other.name), address(other.address) +{ +} + +Symbol &Symbol::operator=(Symbol &&other) noexcept +{ + if (this == &other) + return *this; + + type = other.type; + name = (ehs::Str_8 &&)other.name; + id = other.id; + address = other.address; + + other.type = SymbolType::UNKNOWN; + other.id = 0; + other.address = 0; + + return *this; +} + +Symbol &Symbol::operator=(const Symbol& other) +{ + if (this == &other) + return *this; + + type = other.type; + name = other.name; + id = other.id; + address = other.address; + + return *this; +} + +SymbolType Symbol::GetType() const +{ + return type; +} + +ehs::Str_8 Symbol::GetName() const +{ + return name; +} + +ehs::UInt_64 Symbol::GetId() const +{ + return id; +} + +ehs::UInt_64 Symbol::GetAddress() const +{ + return address; +} diff --git a/src/compiler/Token.cpp b/src/compiler/Token.cpp index c148512..374322c 100644 --- a/src/compiler/Token.cpp +++ b/src/compiler/Token.cpp @@ -1,37 +1,56 @@ #include "arctyx/compiler/Token.h" Token::Token() + : type(TokenT::UNKNOWN) { } -Token::Token(TokenType type, ehs::Str_8 value) +Token::Token(const TokenT &type, ehs::Str_8 value) + : type(type), value((ehs::Str_8 &&)value) { } Token::Token(Token &&token) noexcept + : type(token.type), value((ehs::Str_8 &&)token.value) { + token.type = TokenT::UNKNOWN; } Token::Token(const Token &token) + : type(token.type), value(token.value) { } Token & Token::operator=(Token &&token) noexcept { + if (this == &token) + return *this; + + type = token.type; + value = (ehs::Str_8 &&)token.value; + + token.type = TokenT::UNKNOWN; + return *this; } Token & Token::operator=(const Token &token) { + if (this == &token) + return *this; + + type = token.type; + value = token.value; + return *this; } -TokenType Token::GetType() const +TokenT Token::GetType() const { return type; } ehs::Str_8 Token::GetValue() const { - return {}; + return value; } diff --git a/src/main.cpp b/src/main.cpp index a8c9cbf..ea3ad77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,19 +5,6 @@ #include #include -struct Foo -{ - bool a; - ehs::UInt_64 b; - ehs::UInt_16 c; -}; - -struct Bar -{ - Foo a; - ehs::Char_8 b[128]; -}; - int main() { ehs::Initialize("Arctyx", "Alpha", {1, 0, 0}); @@ -26,8 +13,8 @@ int main() ehs::Vector args = ehs::Console::GetArgs_8(); if (args.Size() <= 1) { - ehs::Console::Write_8(ehs::GetAppName_8() + " " + ehs::GetAppVersionId_8() + " v" + ehs::Str_8::FromNum(ehs::GetVersion().major) + "." + - ehs::Str_8::FromNum(ehs::GetVersion().minor) + "." + ehs::Str_8::FromNum(ehs::GetVersion().patch)); + ehs::Console::Write_8(ehs::GetAppName_8() + " " + ehs::GetAppVersionId_8() + " v" + ehs::Str_8::FromNum(ehs::GetAppVersion().major) + "." + + ehs::Str_8::FromNum(ehs::GetAppVersion().minor) + "." + ehs::Str_8::FromNum(ehs::GetAppVersion().patch)); return 0; }