nicer fixed step interface

This commit is contained in:
2022-11-05 15:06:54 -07:00
parent b8f9152ff6
commit d96eafaa47
6 changed files with 59 additions and 60 deletions

View File

@@ -5,6 +5,14 @@ namespace intcode {
BadInstruction::BadInstruction(char const* what)
: std::runtime_error{what} {}
auto StepInput(Machine & m, ValueType input) -> void {
std::get<Input>(Step(m)).pos = input;
}
auto StepOutput(Machine & m) -> ValueType {
return std::get<Output>(Step(m)).val;
}
auto Step(Machine & m) -> std::variant<Input, Output, Halt> {
for (;;) {
auto instruction = m.Next();