mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-23 03:47:34 -04:00
Replace StringUtils::format in components/interpreter
This commit is contained in:
parent
a0d081adb9
commit
58a232d6c7
@ -1,6 +1,7 @@
|
|||||||
#include "interpreter.hpp"
|
#include "interpreter.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <format>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -9,27 +10,36 @@
|
|||||||
|
|
||||||
namespace Interpreter
|
namespace Interpreter
|
||||||
{
|
{
|
||||||
[[noreturn]] static void abortUnknownCode(int segment, int opcode)
|
namespace
|
||||||
{
|
{
|
||||||
const std::string error = "unknown opcode " + std::to_string(opcode) + " in segment " + std::to_string(segment);
|
[[noreturn]] void abortUnknownCode(int segment, int opcode)
|
||||||
throw std::runtime_error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[noreturn]] static void abortUnknownSegment(Type_Code code)
|
|
||||||
{
|
|
||||||
const std::string error = "opcode outside of the allocated segment range: " + std::to_string(code);
|
|
||||||
throw std::runtime_error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
auto& getDispatcher(const T& segment, unsigned int seg, int opcode)
|
|
||||||
{
|
|
||||||
auto it = segment.find(opcode);
|
|
||||||
if (it == segment.end())
|
|
||||||
{
|
{
|
||||||
abortUnknownCode(seg, opcode);
|
const std::string error = std::format("unknown opcode {} in segment {}", opcode, segment);
|
||||||
|
throw std::runtime_error(error);
|
||||||
}
|
}
|
||||||
return it->second;
|
|
||||||
|
[[noreturn]] void abortUnknownSegment(Type_Code code)
|
||||||
|
{
|
||||||
|
const std::string error = std::format("opcode outside of the allocated segment range: {}", code);
|
||||||
|
throw std::runtime_error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
auto& getDispatcher(const T& segment, unsigned int seg, int opcode)
|
||||||
|
{
|
||||||
|
auto it = segment.find(opcode);
|
||||||
|
if (it == segment.end())
|
||||||
|
{
|
||||||
|
abortUnknownCode(seg, opcode);
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[[noreturn]] void Interpreter::abortDuplicateInstruction(std::string_view name, int code)
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(
|
||||||
|
std::format("Duplicated interpreter instruction code in segment {}: {:#x}", name, code));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interpreter::execute(Type_Code code)
|
void Interpreter::execute(Type_Code code)
|
||||||
|
@ -4,13 +4,9 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <stdexcept>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <components/misc/strings/format.hpp>
|
|
||||||
|
|
||||||
#include "opcodes.hpp"
|
#include "opcodes.hpp"
|
||||||
#include "program.hpp"
|
|
||||||
#include "runtime.hpp"
|
#include "runtime.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
|
||||||
@ -34,12 +30,13 @@ namespace Interpreter
|
|||||||
|
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
|
[[noreturn]] void abortDuplicateInstruction(std::string_view name, int code);
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void installSegment(auto& segment, std::string_view name, int code, Args&&... args)
|
void installSegment(auto& segment, std::string_view name, int code, Args&&... args)
|
||||||
{
|
{
|
||||||
if (segment.find(code) != segment.end())
|
if (segment.find(code) != segment.end())
|
||||||
throw std::invalid_argument(Misc::StringUtils::format(
|
abortDuplicateInstruction(name, code);
|
||||||
"Duplicated interpreter instruction code in segment %s: 0x%x", name, code));
|
|
||||||
segment.emplace(code, std::make_unique<T>(std::forward<Args>(args)...));
|
segment.emplace(code, std::make_unique<T>(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user