#ifndef INTERPRETER_INTERPRETER_H_INCLUDED #define INTERPRETER_INTERPRETER_H_INCLUDED #include #include #include #include #include #include #include "opcodes.hpp" #include "program.hpp" #include "runtime.hpp" #include "types.hpp" namespace Interpreter { struct Program; class Interpreter { std::stack mCallstack; bool mRunning = false; Runtime mRuntime; std::map> mSegment0; std::map> mSegment2; std::map> mSegment3; std::map> mSegment5; void execute(Type_Code code); void begin(); void end(); template void installSegment(auto& segment, std::string_view name, int code, Args&&... args) { if (segment.find(code) != segment.end()) throw std::invalid_argument(Misc::StringUtils::format( "Duplicated interpreter instruction code in segment %s: 0x%x", name, code)); segment.emplace(code, std::make_unique(std::forward(args)...)); } public: Interpreter() = default; Interpreter(const Interpreter&) = delete; Interpreter& operator=(const Interpreter&) = delete; template void installSegment0(int code, TArgs&&... args) { installSegment(mSegment0, "0", code, std::forward(args)...); } template void installSegment2(int code, TArgs&&... args) { installSegment(mSegment2, "2", code, std::forward(args)...); } template void installSegment3(int code, TArgs&&... args) { installSegment(mSegment3, "3", code, std::forward(args)...); } template void installSegment5(int code, TArgs&&... args) { installSegment(mSegment5, "5", code, std::forward(args)...); } void run(const Program& program, Context& context); }; } #endif