Huge update, backup commit.

This commit is contained in:
2025-07-27 23:50:41 -07:00
parent a0cd2e00b8
commit c4011152b6
21 changed files with 775 additions and 200 deletions

View File

@@ -5,6 +5,7 @@
#include "Architecture.h"
#include "Language.h"
#include "Stack.h"
#include "Symbol.h"
class Compiler
@@ -12,12 +13,14 @@ class Compiler
private:
const Architecture *architecture;
const Language *language;
ehs::UInt_64 entryPointId;
ehs::Str_8 entryPointName;
ehs::Array<Symbol> symbols;
public:
Compiler();
Compiler(const ehs::Str_8 &arch, const ehs::Str_8 &lang);
Compiler(const ehs::Str_8 &arch, const ehs::Str_8 &lang, ehs::Str_8 entryPoint);
Compiler(Compiler &&other) noexcept;
@@ -27,18 +30,42 @@ public:
Compiler &operator=(const Compiler &other);
ehs::Array<ehs::Byte> Compile(const ehs::Str_8 &code) const;
bool HasSymbol(const ehs::UInt_64 &id) const;
bool HasSymbol(const ehs::Str_8 &name) const;
bool AddSymbol(Symbol symbol);
Symbol *GetSymbol(const ehs::UInt_64 &id) const;
Symbol *GetSymbol(const ehs::Str_8 &name) const;
ehs::Vector<ehs::Byte> Compile(const ehs::Str_8 &code);
private:
static bool IsEOL(const ehs::Array<ehs::Char_8> &eols, const ehs::Char_8 *c);
static bool IsNumber(const ehs::Char_8 *c);
static bool IsSeparator(const ehs::Array<ehs::Char_8> &separators, const ehs::Char_8 *c);
static bool IsOperator(const ehs::Char_8 *c);
static bool IsAlphabet(const ehs::Char_8 *c);
static bool IsAlphaNumeric(const ehs::Char_8 *c);
static bool IsPrimitive(const ehs::Array<Primitive> &primitives, const ehs::Str_8 &value);
static bool IsKeyword(const ehs::Array<ehs::Str_8> &keywords, const ehs::Str_8 &value);
static const Operator *IsOperator(const ehs::Array<Operator> &operators, const ehs::Str_8 &value);
static bool IsEncapsulator(const ehs::Char_8 *c);
ehs::Vector<Token> Parse(const ehs::Str_8 &code) const;
static bool IsEOL(const ehs::Array<ehs::Char_8> &eols, const ehs::Char_8 *c);
static void ParseNumber(ehs::Vector<Token> &tokens, const ehs::Array<ehs::Char_8> &eols, ehs::Char_8 **start, ehs::Char_8 **i);
static void ParseOperator(ehs::Vector<Token> &tokens, const ehs::Array<ehs::Char_8> &eols, ehs::Char_8 **start, ehs::Char_8 **i);
static void ParseText(ehs::Vector<Token> &tokens, const ehs::Array<ehs::Char_8> &eols,
const ehs::Array<Primitive> &primitives, const ehs::Array<ehs::Str_8> &keywords, ehs::Char_8 **start,
ehs::Char_8 **i);
ehs::Vector<Token> ParseIntoTokens(const ehs::Str_8 &code) const;
};

View File

@@ -9,6 +9,9 @@
#include "Operator.h"
#include "Primitive.h"
typedef ehs::Vector<Token> (*CompileIntoTokensCb)(Compiler *compiler, const Language *lang, const ehs::Str_8 &code);
typedef ehs::Vector<ehs::Byte> (*CompileIntoMachineCodeCb)(Compiler *compiler, const Language *lang, const ehs::Vector<Token> &tokens);
class EHS_LIB_IO Language
{
private:
@@ -18,11 +21,12 @@ private:
ehs::Str_8 name;
ehs::Version version;
ehs::Array<ehs::Char_8> eols;
ehs::Array<ehs::Char_8> separators;
ehs::Array<Primitive> primitives;
ehs::Array<ehs::Str_8> keywords;
ehs::Array<Operator> operators;
ehs::Array<Interpretation> interpretations;
CompileIntoTokensCb compileIntoTokensCb;
CompileIntoMachineCodeCb compileIntoMachineCodeCb;
static ehs::Array<const Language *> languages;
@@ -51,12 +55,6 @@ public:
bool AddEOL(const ehs::Char_8 &eol);
ehs::Array<ehs::Char_8> GetSeparators() const;
bool HasSeparator(const ehs::Char_8 &separator) const;
bool AddSeparator(const ehs::Char_8 &separator);
ehs::Array<Primitive> GetPrimitives() const;
bool HasPrimitive(const ehs::UInt_64 &id) const;
@@ -91,6 +89,14 @@ public:
bool AddInterpretation(Interpretation interpretation);
void SetCompileIntoTokensCb(CompileIntoTokensCb cb);
ehs::Vector<Token> CompileIntoTokens(Compiler *compiler, const ehs::Str_8 &code) const;
void SetCompileIntoMachineCodeCb(CompileIntoMachineCodeCb cb);
ehs::Vector<ehs::Byte> CompileIntoMachineCode(Compiler *compiler, const ehs::Vector<Token> &tokens) const;
static bool Has(const ehs::UInt_64 &id);
static bool Has(const ehs::Str_8 &name);

View File

@@ -8,7 +8,7 @@ private:
ehs::UInt_64 id;
ehs::Str_8 name;
ehs::UInt_32 byteDepth;
ehs::UInt_64 code;;
ehs::UInt_64 code;
public:
Register();

View File

@@ -0,0 +1,41 @@
#pragma once
#include <ehs/Array.h>
#include <ehs/Vector.h>
#include "arctyx/compiler/StackParam.h"
#include "arctyx/compiler/StackItem.h"
class Stack
{
private:
ehs::Array<StackParam> inputs;
ehs::Array<StackParam> outputs;
ehs::UInt_64 offset;
ehs::Vector<StackItem> items;
public:
Stack();
Stack(const ehs::UInt_64 &offset);
Stack(Stack &&other) noexcept;
Stack(const Stack &other);
Stack &operator=(Stack &&other) noexcept;
Stack &operator=(const Stack &other);
ehs::UInt_64 GetOffset() const;
bool HasItem(const ehs::UInt_64 &id) const;
bool HasItem(const ehs::Str_8 &name) const;
bool AddItem(StackItem item);
StackItem *GetItem(const ehs::UInt_64 &id) const;
StackItem *GetItem(const ehs::Str_8 &name) const;
};

View File

@@ -0,0 +1,33 @@
#pragma once
#include <ehs/Str.h>
class StackItem
{
private:
ehs::UInt_64 id;
ehs::Str_8 name;
ehs::UInt_64 address;
ehs::UInt_64 size;
public:
StackItem();
StackItem(ehs::Str_8 name, const ehs::UInt_64 &address, const ehs::UInt_64 &size);
StackItem(StackItem &&other) noexcept;
StackItem(const StackItem &other);
StackItem &operator=(StackItem &&other) noexcept;
StackItem &operator=(const StackItem &other);
ehs::Str_8 GetName() const;
ehs::UInt_64 GetId() const;
ehs::UInt_64 GetAddress() const;
ehs::UInt_64 GetSize() const;
};

View File

@@ -0,0 +1,11 @@
#pragma once
#include "arctyx/compiler/Register.h"
class StackParam
{
private:
bool pointer;
const Register *reg;
};

View File

@@ -20,11 +20,12 @@ private:
ehs::UInt_64 id;
ehs::Str_8 name;
ehs::UInt_64 address;
ehs::UInt_64 size;
public:
Symbol();
Symbol(const SymbolType &type, ehs::Str_8 name, const ehs::UInt_64 &address);
Symbol(const SymbolType &type, ehs::Str_8 name, const ehs::UInt_64 &address, const ehs::UInt_64 &size);
Symbol(Symbol &&other) noexcept;
@@ -41,4 +42,6 @@ public:
ehs::UInt_64 GetId() const;
ehs::UInt_64 GetAddress() const;
ehs::UInt_64 GetSize() const;
};

View File

@@ -6,6 +6,7 @@ enum class TokenT : ehs::UInt_8
{
UNKNOWN,
SEPARATOR,
BOOLEAN,
NUMBER,
STRING,
CHARACTER,
@@ -14,6 +15,7 @@ enum class TokenT : ehs::UInt_8
IDENTIFIER,
UNARY_OPERATOR,
COMPOUND_OPERATOR,
ENCAPSULATOR,
EOL
};
@@ -36,6 +38,8 @@ public:
Token &operator=(const Token &token);
void SetType(const TokenT &newType);
TokenT GetType() const;
ehs::Str_8 GetValue() const;