1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-04 08:15:33 +00:00
openmw/components/interpreter/interpreter.hpp

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

75 lines
2 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
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
{
class Interpreter
{
std::stack<Runtime> mCallstack;
bool mRunning;
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 17:20:45 +00:00
// not implemented
Interpreter(const Interpreter&);
Interpreter& operator=(const Interpreter&);
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();
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 Type_Code* code, int codeSize, Context& context);
2010-06-28 17:20:45 +00:00
};
}
#endif