1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/components/interpreter/controlopcodes.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.5 KiB
C++
Raw Normal View History

#ifndef INTERPRETER_CONTROLOPCODES_H_INCLUDED
#define INTERPRETER_CONTROLOPCODES_H_INCLUDED
2010-06-30 17:58:25 +00:00
#include <stdexcept>
#include "opcodes.hpp"
#include "runtime.hpp"
namespace Interpreter
{
class OpReturn : public Opcode0
{
public:
void execute(Runtime& runtime) override { runtime.setPC(-1); }
};
2013-03-09 14:39:49 +00:00
2010-06-30 17:58:25 +00:00
class OpSkipZero : public Opcode0
{
public:
void execute(Runtime& runtime) override
2010-06-30 17:58:25 +00:00
{
Type_Integer data = runtime[0].mInteger;
2010-06-30 17:58:25 +00:00
runtime.pop();
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
if (data == 0)
runtime.setPC(runtime.getPC() + 1);
2013-03-09 14:39:49 +00:00
}
};
2010-06-30 17:58:25 +00:00
class OpSkipNonZero : public Opcode0
{
public:
void execute(Runtime& runtime) override
2010-06-30 17:58:25 +00:00
{
Type_Integer data = runtime[0].mInteger;
2010-06-30 17:58:25 +00:00
runtime.pop();
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
if (data != 0)
runtime.setPC(runtime.getPC() + 1);
2013-03-09 14:39:49 +00:00
}
};
2010-06-30 17:58:25 +00:00
class OpJumpForward : public Opcode1
{
public:
void execute(Runtime& runtime, unsigned int arg0) override
2010-06-30 17:58:25 +00:00
{
if (arg0 == 0)
2013-03-09 14:39:49 +00:00
throw std::logic_error("infinite loop");
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
runtime.setPC(runtime.getPC() + arg0 - 1);
2013-03-09 14:39:49 +00:00
}
};
2010-06-30 17:58:25 +00:00
class OpJumpBackward : public Opcode1
{
public:
void execute(Runtime& runtime, unsigned int arg0) override
2010-06-30 17:58:25 +00:00
{
if (arg0 == 0)
2013-03-09 14:39:49 +00:00
throw std::logic_error("infinite loop");
2022-09-22 18:26:05 +00:00
2010-06-30 17:58:25 +00:00
runtime.setPC(runtime.getPC() - arg0 - 1);
2013-03-09 14:39:49 +00:00
}
};
}
#endif