Added direct memory access
This commit is contained in:
@@ -16,4 +16,12 @@ namespace Execute
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
struct BadValueType : RuntimeError
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,21 @@ namespace Interpret
|
||||
ExpectedImmediate(Token::Token const & token);
|
||||
};
|
||||
|
||||
struct ExpectedImmediateOrMemory : public TokenError
|
||||
{
|
||||
ExpectedImmediateOrMemory(Token::Token const & token);
|
||||
};
|
||||
|
||||
struct ExpectedRegister : public TokenError
|
||||
{
|
||||
ExpectedRegister(Token::Token const & token);
|
||||
};
|
||||
|
||||
struct ExpectedRegisterOrMemory : public TokenError
|
||||
{
|
||||
ExpectedRegisterOrMemory(Token::Token const & token);
|
||||
};
|
||||
|
||||
struct ExpectedOperand : public TokenError
|
||||
{
|
||||
ExpectedOperand(Token::Token const & token);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <execute/registers.hpp>
|
||||
#include <execute/state.hpp>
|
||||
#include <token/token.hpp>
|
||||
|
||||
namespace Interpret
|
||||
@@ -7,19 +7,23 @@ namespace Interpret
|
||||
enum class ValueType
|
||||
{
|
||||
Register,
|
||||
ImmediateInteger
|
||||
ImmediateInteger,
|
||||
MemoryLocation
|
||||
};
|
||||
|
||||
enum class ValueDataType
|
||||
{
|
||||
Register,
|
||||
Immediate
|
||||
};
|
||||
|
||||
struct Value
|
||||
{
|
||||
ValueType type;
|
||||
union
|
||||
{
|
||||
int registerIndex;
|
||||
int integer;
|
||||
};
|
||||
ValueDataType dataType;
|
||||
int data;
|
||||
|
||||
int & GetValue(Execute::Registers & registers);
|
||||
int & GetValue(Execute::State & state, Execute::Registers & registers);
|
||||
|
||||
void CreateFromToken(Token::Token const & token);
|
||||
};
|
||||
|
||||
@@ -6,22 +6,43 @@
|
||||
|
||||
namespace Token
|
||||
{
|
||||
enum class TokenValueType
|
||||
{
|
||||
None = 0,
|
||||
Integer,
|
||||
Operand,
|
||||
Register,
|
||||
String
|
||||
};
|
||||
|
||||
struct Token
|
||||
{
|
||||
private:
|
||||
Token(TokenType type, bool validness, int const lineNumber, int const lineColumn);
|
||||
Token(TokenType type, std::string const & string, bool validness, int const lineNumber, int const lineColumn);
|
||||
Token(TokenType type, int value, bool validness, int const lineNumber, int const lineColumn);
|
||||
Token(TokenType type, RegisterType const registerType, bool validness, int const lineNumber, int const lineColumn);
|
||||
Token(TokenType type, OperandType const OperandType, bool validness, int const lineNumber, int const lineColumn);
|
||||
|
||||
public:
|
||||
int const lineNumber;
|
||||
int const lineColumn;
|
||||
TokenType type;
|
||||
TokenValueType const valueType;
|
||||
bool isValid;
|
||||
std::variant<OperandType, RegisterType, int, std::string> data;
|
||||
|
||||
Token(int const lineNumber, int const lineColumn);
|
||||
Token(int const lineNumber, int const lineColumn, OperandType operatorType, bool validness);
|
||||
Token(int const lineNumber, int const lineColumn, RegisterType registerType, bool validness);
|
||||
Token(int const lineNumber, int const lineColumn, int value, bool validness);
|
||||
Token(int const lineNumber, int const lineColumn, std::string const & value, bool validness);
|
||||
|
||||
Token(Token const & other);
|
||||
|
||||
static Token CreateUnknownToken(int const lineNumber, int const lineColumn);
|
||||
static Token CreateStatementEndToken(int const lineNumber, int const lineColumn);
|
||||
static Token CreateLabelToken(std::string const & string, bool isValid, int const lineNumber, int const lineColumn);
|
||||
static Token CreateImmediateValueToken(int const value, bool isValid, int const lineNumber, int const lineColumn);
|
||||
static Token CreateRegisterToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
|
||||
static Token CreateOperandToken(OperandType const operandType, int const lineNumber, int const lineColumn);
|
||||
static Token CreateMemoryToken(RegisterType const registerType, int const lineNumber, int const lineColumn);
|
||||
static Token CreateMemoryToken(int const value, bool isValid, int const lineNumber, int const lineColumn);
|
||||
|
||||
void DebugPrint() const;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Token
|
||||
ImmediateInteger,
|
||||
Register,
|
||||
StatementEnd,
|
||||
Label
|
||||
Label,
|
||||
Memory
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user