slige/runtime/actions.hpp

46 lines
1.3 KiB
C++

#include "rpc_server.hpp"
#include <memory>
namespace sliger::rpc::action {
struct Action {
virtual auto perform_action(
std::unique_ptr<sliger::rpc::BufferedWriter> writer) -> void = 0;
virtual ~Action() = default;
};
class RunDebug : public Action {
public:
RunDebug(std::vector<uint32_t> instructions)
: instructions(instructions)
{
}
auto perform_action(
std::unique_ptr<sliger::rpc::BufferedWriter> writer) -> void;
private:
std::vector<uint32_t> instructions;
};
static auto action_from_json(
std::unique_ptr<json::Value> value) -> std::unique_ptr<Action>
{
auto& obj = value->as<sliger::json::Object>();
auto type = obj.fields.at("type")->as<sliger::json::String>();
if (type.value == "run-debug") {
sliger::json::ArrayValues values = std::move(
obj.fields.at("program")->as<sliger::json::Array>().values);
auto instructions = std::vector<uint32_t>();
for (auto& v : values) {
std::unique_ptr<json::Value> moved = std::move(v);
auto value = moved->as<sliger::json::Number>().value;
instructions.push_back((uint32_t)value);
}
auto action = RunDebug(instructions);
return std::make_unique<RunDebug>(action);
}
throw "todo";
};
}