2010-06-28 17:20:45 +00:00
|
|
|
#ifndef INTERPRETER_INTERPRETER_H_INCLUDED
|
|
|
|
#define INTERPRETER_INTERPRETER_H_INCLUDED
|
|
|
|
|
2010-06-28 18:46:15 +00:00
|
|
|
#include <map>
|
2015-10-09 10:14:22 +00:00
|
|
|
#include <stack>
|
2022-01-27 19:18:57 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <cassert>
|
|
|
|
#include <utility>
|
2010-06-28 18:46:15 +00:00
|
|
|
|
2010-06-28 17:20:45 +00:00
|
|
|
#include "runtime.hpp"
|
|
|
|
#include "types.hpp"
|
2022-01-27 19:18:57 +00:00
|
|
|
#include "opcodes.hpp"
|
2010-06-28 17:20:45 +00:00
|
|
|
|
|
|
|
namespace Interpreter
|
|
|
|
{
|
|
|
|
class Interpreter
|
|
|
|
{
|
2015-10-09 10:14:22 +00:00
|
|
|
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;
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 17:20:45 +00:00
|
|
|
// not implemented
|
|
|
|
Interpreter (const Interpreter&);
|
|
|
|
Interpreter& operator= (const Interpreter&);
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2010-06-28 18:46:15 +00:00
|
|
|
void execute (Type_Code code);
|
2011-05-18 14:01:19 +00:00
|
|
|
|
2015-10-09 10:14:22 +00:00
|
|
|
void begin();
|
|
|
|
|
|
|
|
void end();
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2010-06-28 17:20:45 +00:00
|
|
|
public:
|
2011-05-18 14:01:19 +00:00
|
|
|
|
|
|
|
Interpreter();
|
|
|
|
|
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)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename ...TArgs>
|
|
|
|
void installSegment2(int code, TArgs&& ...args)
|
|
|
|
{
|
|
|
|
installSegment(mSegment2, code, std::make_unique<T>(std::forward<TArgs>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename ...TArgs>
|
|
|
|
void installSegment3(int code, TArgs&& ...args)
|
|
|
|
{
|
|
|
|
installSegment(mSegment3, code, std::make_unique<T>(std::forward<TArgs>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename ...TArgs>
|
|
|
|
void installSegment5(int code, TArgs&& ...args)
|
|
|
|
{
|
|
|
|
installSegment(mSegment5, code, std::make_unique<T>(std::forward<TArgs>(args)...));
|
|
|
|
}
|
2011-05-18 14:01:19 +00:00
|
|
|
|
|
|
|
void run (const Type_Code *code, int codeSize, Context& context);
|
2010-06-28 17:20:45 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|