mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 23:06:32 +00:00
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include "arch.hpp"
|
|
#include "vm.hpp"
|
|
|
|
using namespace sliger;
|
|
|
|
size_t VM::instruction_size(size_t i) const
|
|
{
|
|
switch (static_cast<Op>(this->program.at(i))) {
|
|
case Op::Nop:
|
|
case Op::PushNull:
|
|
return 1;
|
|
case Op::PushInt:
|
|
case Op::PushBool:
|
|
return 2;
|
|
case Op::PushString: {
|
|
auto string_length = this->program.at(i + 1);
|
|
return 2 + string_length;
|
|
}
|
|
case Op::PushPtr:
|
|
return 2;
|
|
case Op::Pop:
|
|
return 1;
|
|
case Op::ReserveStatic:
|
|
case Op::LoadStatic:
|
|
case Op::StoreStatic:
|
|
case Op::LoadLocal:
|
|
case Op::StoreLocal:
|
|
case Op::Call:
|
|
return 2;
|
|
case Op::Return:
|
|
case Op::Jump:
|
|
case Op::JumpIfTrue:
|
|
return 1;
|
|
case Op::Builtin:
|
|
return 2;
|
|
case Op::Duplicate:
|
|
case Op::Swap:
|
|
case Op::Add:
|
|
case Op::Subtract:
|
|
case Op::Multiply:
|
|
case Op::Divide:
|
|
case Op::Remainder:
|
|
case Op::Equal:
|
|
case Op::LessThan:
|
|
case Op::And:
|
|
case Op::Or:
|
|
case Op::Xor:
|
|
case Op::Not:
|
|
return 1;
|
|
case Op::SourceMap:
|
|
return 4;
|
|
}
|
|
return 1;
|
|
}
|