1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/components/interpreter/interpreter.hpp

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

77 lines
2.1 KiB
C++
Raw Normal View History

2010-06-28 17:20:45 +00:00
#ifndef INTERPRETER_INTERPRETER_H_INCLUDED
#define INTERPRETER_INTERPRETER_H_INCLUDED
2022-01-27 19:18:57 +00:00
#include <cassert>
2010-06-28 18:46:15 +00:00
#include <map>
2022-01-27 19:18:57 +00:00
#include <memory>
#include <stack>
#include <utility>
2010-06-28 18:46:15 +00:00
#include "components/interpreter/program.hpp"
2022-01-27 19:18:57 +00:00
#include "opcodes.hpp"
2010-06-28 17:20:45 +00:00
#include "runtime.hpp"
#include "types.hpp"
namespace Interpreter
{
struct Program;
2010-06-28 17:20:45 +00:00
class Interpreter
{
std::stack<Runtime> mCallstack;
bool mRunning = false;
2010-06-28 17:20:45 +00:00
Runtime mRuntime;
2022-01-27 19:18:57 +00:00
std::map<int, std::unique_ptr<Opcode1>> mSegment0;
std::map<int, std::unique_ptr<Opcode1>> mSegment2;
std::map<int, std::unique_ptr<Opcode1>> mSegment3;
std::map<int, std::unique_ptr<Opcode0>> mSegment5;
2022-09-22 18:26:05 +00:00
2010-06-28 18:46:15 +00:00
void execute(Type_Code code);
2022-09-22 18:26:05 +00:00
void begin();
2022-09-22 18:26:05 +00:00
void end();
2022-09-22 18:26:05 +00:00
2022-01-27 19:18:57 +00:00
template <typename TSeg, typename TOp>
void installSegment(TSeg& seg, int code, TOp&& op)
{
assert(seg.find(code) == seg.end());
seg.emplace(code, std::move(op));
}
2022-09-22 18:26:05 +00:00
2010-06-28 17:20:45 +00:00
public:
Interpreter() = default;
Interpreter(const Interpreter&) = delete;
Interpreter& operator=(const Interpreter&) = delete;
2022-09-22 18:26:05 +00:00
2022-01-27 19:18:57 +00:00
template <typename T, typename... TArgs>
void installSegment0(int code, TArgs&&... args)
{
installSegment(mSegment0, code, std::make_unique<T>(std::forward<TArgs>(args)...));
}
2022-09-22 18:26:05 +00:00
2022-01-27 19:18:57 +00:00
template <typename T, typename... TArgs>
void installSegment2(int code, TArgs&&... args)
{
installSegment(mSegment2, code, std::make_unique<T>(std::forward<TArgs>(args)...));
}
2022-09-22 18:26:05 +00:00
2022-01-27 19:18:57 +00:00
template <typename T, typename... TArgs>
void installSegment3(int code, TArgs&&... args)
{
installSegment(mSegment3, code, std::make_unique<T>(std::forward<TArgs>(args)...));
}
2022-09-22 18:26:05 +00:00
2022-01-27 19:18:57 +00:00
template <typename T, typename... TArgs>
void installSegment5(int code, TArgs&&... args)
{
installSegment(mSegment5, code, std::make_unique<T>(std::forward<TArgs>(args)...));
}
2022-09-22 18:26:05 +00:00
void run(const Program& program, Context& context);
2010-06-28 17:20:45 +00:00
};
}
#endif