rearrange
This commit is contained in:
26
lib/include/intcode/Interpreter.hpp
Normal file
26
lib/include/intcode/Interpreter.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef INTCODE_INTERPRETER_HPP_
|
||||
#define INTCODE_INTERPRETER_HPP_
|
||||
|
||||
#include "Machine.hpp"
|
||||
|
||||
namespace intcode {
|
||||
|
||||
struct Input {
|
||||
ValueType &pos;
|
||||
};
|
||||
|
||||
struct Output {
|
||||
ValueType val;
|
||||
};
|
||||
|
||||
struct Halt {};
|
||||
|
||||
auto Step(Machine & m) -> std::variant<Input, Output, Halt>;
|
||||
|
||||
struct BadInstruction : public std::runtime_error {
|
||||
explicit BadInstruction(char const* what);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
@@ -1,30 +1,13 @@
|
||||
#ifndef INTCODE_HPP_
|
||||
#define INTCODE_HPP_
|
||||
#ifndef INTCODE_MACHINE_HPP_
|
||||
#define INTCODE_MACHINE_HPP_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
#include <unordered_map>
|
||||
#include <stdexcept>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
||||
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
namespace intcode {
|
||||
|
||||
using ValueType = std::int64_t;
|
||||
|
||||
struct Input {
|
||||
ValueType &pos;
|
||||
};
|
||||
|
||||
struct Output {
|
||||
ValueType val;
|
||||
};
|
||||
|
||||
struct Halt {};
|
||||
using ValueType = std::int64_t;
|
||||
|
||||
class Machine {
|
||||
std::vector<ValueType> rom_;
|
||||
@@ -51,14 +34,6 @@ public:
|
||||
auto Rebase(std::size_t offset) -> void;
|
||||
};
|
||||
|
||||
auto Step(Machine & m) -> std::variant<Input, Output, Halt>;
|
||||
} // namespace
|
||||
|
||||
struct BadInstruction : public std::runtime_error {
|
||||
explicit BadInstruction(char const* what);
|
||||
};
|
||||
|
||||
auto ParseStream(std::istream &in) -> std::vector<ValueType>;
|
||||
|
||||
}
|
||||
|
||||
#endif // INTCODE_HPP_
|
||||
#endif
|
15
lib/include/intcode/Parser.hpp
Normal file
15
lib/include/intcode/Parser.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef INTCODE_PARSER_HPP_
|
||||
#define INTCODE_PARSER_HPP_
|
||||
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
#include "Machine.hpp"
|
||||
|
||||
namespace intcode {
|
||||
|
||||
auto ParseStream(std::istream &in) -> std::vector<ValueType>;
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
11
lib/include/intcode/intcode.hpp
Normal file
11
lib/include/intcode/intcode.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef INTCODE_HPP_
|
||||
#define INTCODE_INTCODE_HPP_
|
||||
|
||||
#include <intcode/Machine.hpp>
|
||||
#include <intcode/Parser.hpp>
|
||||
#include <intcode/Interpreter.hpp>
|
||||
|
||||
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
||||
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user