Memory added plus basic memory operations

This commit is contained in:
2019-11-23 14:53:56 +01:00
parent 99f616e1e4
commit 22bb974a05
17 changed files with 232 additions and 68 deletions

View File

@@ -210,6 +210,22 @@ namespace Interpret
return statement;
}
case Token::OperandType::PopInteger:
{
auto statement = std::make_unique<PopStatement>();
statement->firstArgument = GetRegisterArgument(operandIndex + 1u, tokens);
return statement;
}
case Token::OperandType::PushInteger:
{
auto statement = std::make_unique<PushStatement>();
statement->firstArgument = GetImmediateOrRegisterArgument(operandIndex + 1u, tokens);
return statement;
}
default:
{
auto statement = std::make_unique<NoArgumentStatement>();
@@ -221,6 +237,22 @@ namespace Interpret
}
}
std::tuple<std::string, int> ExtractDeclaration(unsigned const operatorIndex, std::vector<Token::Token> const & tokens)
{
if (tokens[operatorIndex + 1u].type != Token::TokenType::Label)
{
throw ExpectedLabel(tokens[operatorIndex + 1u]);
}
if (tokens[operatorIndex + 2u].type != Token::TokenType::ImmediateInteger)
{
throw ExpectedImmediate(tokens[operatorIndex + 2u]);
}
auto const label = std::get<std::string>(tokens[operatorIndex + 1u].data);
auto const value = std::get<int>(tokens[operatorIndex + 2u].data);
return std::make_tuple(label, value);
}
int GetRequiredNumberOfArguments(Token::OperandType const type)
{
switch (type)
@@ -237,10 +269,13 @@ namespace Interpret
case Token::OperandType::GreaterThanInteger:
case Token::OperandType::EqualInteger:
case Token::OperandType::SetInteger:
case Token::OperandType::Declaration:
return 2;
case Token::OperandType::Jump:
case Token::OperandType::Interrupt:
case Token::OperandType::PushInteger:
case Token::OperandType::PopInteger:
return 1;
default: