Add ret function
This commit is contained in:
@@ -89,6 +89,11 @@ seti %B $4;
|
|||||||
int $3;
|
int $3;
|
||||||
|
|
||||||
# Jump over the interrupt
|
# Jump over the interrupt
|
||||||
call program_exit;
|
call noop_function;
|
||||||
int $3;
|
int $3;
|
||||||
program_exit:
|
jmp the_real_exit;
|
||||||
|
|
||||||
|
noop_function:
|
||||||
|
ret;
|
||||||
|
|
||||||
|
the_real_exit:
|
||||||
@@ -66,6 +66,11 @@ namespace Interpret
|
|||||||
FunctionCallStatement(std::string const & label);
|
FunctionCallStatement(std::string const & label);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ReturnFromFunctionStatement : Statement
|
||||||
|
{
|
||||||
|
void Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers) override;
|
||||||
|
};
|
||||||
|
|
||||||
struct SetStatement : Statement
|
struct SetStatement : Statement
|
||||||
{
|
{
|
||||||
Value firstArgument;
|
Value firstArgument;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Token
|
|||||||
ShiftIntegerRight,
|
ShiftIntegerRight,
|
||||||
Jump,
|
Jump,
|
||||||
CallFunction,
|
CallFunction,
|
||||||
|
ReturnFromFunction,
|
||||||
LessThanInteger,
|
LessThanInteger,
|
||||||
GreaterThanInteger,
|
GreaterThanInteger,
|
||||||
EqualInteger,
|
EqualInteger,
|
||||||
|
|||||||
@@ -165,6 +165,11 @@ namespace Interpret
|
|||||||
return std::make_unique<FunctionCallStatement>(std::get<std::string>(labelToken.data));
|
return std::make_unique<FunctionCallStatement>(std::get<std::string>(labelToken.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Token::OperandType::ReturnFromFunction:
|
||||||
|
{
|
||||||
|
return std::make_unique<ReturnFromFunctionStatement>();
|
||||||
|
}
|
||||||
|
|
||||||
case Token::OperandType::LessThanInteger:
|
case Token::OperandType::LessThanInteger:
|
||||||
{
|
{
|
||||||
auto statement = std::make_unique<ControlFlowStatement>();
|
auto statement = std::make_unique<ControlFlowStatement>();
|
||||||
@@ -310,6 +315,7 @@ namespace Interpret
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
std::printf("WARNING: returning default argument length of 0 for operand type %i\n", static_cast<int>(type));
|
std::printf("WARNING: returning default argument length of 0 for operand type %i\n", static_cast<int>(type));
|
||||||
|
case Token::OperandType::ReturnFromFunction:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,17 @@ namespace Interpret
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReturnFromFunctionStatement::Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers)
|
||||||
|
{
|
||||||
|
if (state.stackPointer < sizeof(unsigned))
|
||||||
|
{
|
||||||
|
throw Execute::StackUnderflow();
|
||||||
|
}
|
||||||
|
|
||||||
|
state.nextStatement = *(reinterpret_cast<unsigned const *>(state.memory.data() + (state.stackPointer - 1u)));
|
||||||
|
state.stackPointer -= sizeof(unsigned);
|
||||||
|
}
|
||||||
|
|
||||||
void SetStatement::Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers)
|
void SetStatement::Execute(Execute::Flags & flags, Execute::State & state, Execute::Registers & registers)
|
||||||
{
|
{
|
||||||
firstArgument.GetValue(state, registers) = secondArgument.GetValue(state, registers);
|
firstArgument.GetValue(state, registers) = secondArgument.GetValue(state, registers);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Token
|
|||||||
{ "shli", OperandType::ShiftIntegerLeft },
|
{ "shli", OperandType::ShiftIntegerLeft },
|
||||||
{ "jmp", OperandType::Jump },
|
{ "jmp", OperandType::Jump },
|
||||||
{ "call", OperandType::CallFunction },
|
{ "call", OperandType::CallFunction },
|
||||||
|
{ "ret", OperandType::ReturnFromFunction },
|
||||||
{ "lti", OperandType::LessThanInteger },
|
{ "lti", OperandType::LessThanInteger },
|
||||||
{ "gti", OperandType::GreaterThanInteger },
|
{ "gti", OperandType::GreaterThanInteger },
|
||||||
{ "eqi", OperandType::EqualInteger },
|
{ "eqi", OperandType::EqualInteger },
|
||||||
|
|||||||
Reference in New Issue
Block a user