This commit is contained in:
2025-04-27 10:34:53 -07:00
parent 70d35cf0e3
commit ba08245e02
25 changed files with 551 additions and 77 deletions

View File

@@ -1,6 +1,6 @@
#include "arctyx/compiler/Architecture.h"
ehs::Array<Architecture> Architecture::architectures;
ehs::Array<const Architecture *> 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<Instruction> &&)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<Instruction> &&)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;
}

View File

@@ -1 +0,0 @@
#include "arctyx/compiler/Combination.h"

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -1 +1,183 @@
#include "arctyx/compiler/Language.h"
#include "arctyx/compiler/Language.h"
ehs::Array<const Language *> 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<ehs::Char_8> &&)lang.separators),
interpretations((ehs::Array<Interpretation> &&)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<ehs::Char_8> &&)lang.separators;
interpretations = (ehs::Array<Interpretation> &&)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<ehs::Char_8> 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<Interpretation> 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;
}

71
src/compiler/Symbol.cpp Normal file
View File

@@ -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;
}

View File

@@ -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;
}