rearrange

This commit is contained in:
Eric Mertens
2022-11-04 09:38:01 -07:00
parent fd39209ff0
commit e98a71dad6
15 changed files with 115 additions and 78 deletions

View 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

View File

@@ -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

View 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

View 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