Memory added plus basic memory operations
This commit is contained in:
19
include/execute/error.hpp
Normal file
19
include/execute/error.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
namespace Execute
|
||||
{
|
||||
struct RuntimeError
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct StackUnderflow : RuntimeError
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct StackOverflow : RuntimeError
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
@@ -11,7 +11,9 @@ namespace Execute
|
||||
unsigned nextStatement;
|
||||
std::unordered_map<std::string, unsigned> const & labelStatementIndice;
|
||||
std::vector<InterruptFn> const interrupts;
|
||||
std::vector<std::uint8_t> memory;
|
||||
unsigned stackPointer;
|
||||
|
||||
State(std::unordered_map<std::string, unsigned> const & labelStatementIndice);
|
||||
State(std::unordered_map<std::string, unsigned> const & labelStatementIndice, unsigned const memorySize);
|
||||
};
|
||||
}
|
||||
@@ -17,6 +17,8 @@ namespace Execute
|
||||
|
||||
void Step();
|
||||
|
||||
VirtualMachine(Interpret::Code const & code, unsigned const memorySize);
|
||||
|
||||
public:
|
||||
void Run();
|
||||
void SingleStep();
|
||||
@@ -28,6 +30,6 @@ namespace Execute
|
||||
|
||||
bool IsTerminated() const;
|
||||
|
||||
VirtualMachine(Interpret::Code const & code);
|
||||
static VirtualMachine CreateFromCode(Interpret::Code const & code);
|
||||
};
|
||||
}
|
||||
@@ -11,5 +11,6 @@ namespace Interpret
|
||||
{
|
||||
std::vector<std::unique_ptr<Statement>> statements;
|
||||
std::unordered_map<std::string, unsigned> labelStatementIndice;
|
||||
std::unordered_map<std::string, int> declarations;
|
||||
};
|
||||
}
|
||||
@@ -7,5 +7,7 @@ namespace Interpret
|
||||
{
|
||||
std::unique_ptr<Statement> ExtractStatement(unsigned const operatorIndex, std::vector<Token::Token> const & tokens);
|
||||
|
||||
std::tuple<std::string, int> ExtractDeclaration(unsigned const operatorIndex, std::vector<Token::Token> const & tokens);
|
||||
|
||||
int GetRequiredNumberOfArguments(Token::OperandType const type);
|
||||
}
|
||||
@@ -69,4 +69,18 @@ namespace Interpret
|
||||
|
||||
void Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers) override;
|
||||
};
|
||||
|
||||
struct PushStatement : Statement
|
||||
{
|
||||
Value firstArgument;
|
||||
|
||||
void Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers) override;
|
||||
};
|
||||
|
||||
struct PopStatement : Statement
|
||||
{
|
||||
Value firstArgument;
|
||||
|
||||
void Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers) override;
|
||||
};
|
||||
}
|
||||
@@ -17,7 +17,10 @@ namespace Token
|
||||
GreaterThanInteger,
|
||||
EqualInteger,
|
||||
SetInteger,
|
||||
Interrupt
|
||||
Interrupt,
|
||||
Declaration,
|
||||
PushInteger,
|
||||
PopInteger
|
||||
};
|
||||
|
||||
OperandType GetOperandType(std::string const & op);
|
||||
|
||||
Reference in New Issue
Block a user