Implement 8-bit wraparound for multiplies as well and handle empty memory in ircbotRun()

This commit is contained in:
Juhani Krekelä 2018-05-26 22:51:19 +03:00
parent 46f7854d13
commit cd00c3cded
1 changed files with 8 additions and 6 deletions

14
gir.js
View File

@ -705,8 +705,8 @@ function runVM(state, maxCycles = null) {
memory.set(index, 0); memory.set(index, 0);
} }
let old = memory.get(index); let old = memory.get(index);
memory.set(index, old + let value = old + multiplier * change;
multiplier * change); memory.set(index, value & 0xff);
} }
ip++; ip++;
@ -972,10 +972,12 @@ function ircbotRun(program, input, maxCycles = 400000) {
// Find min and max of the existant array indinces, since // Find min and max of the existant array indinces, since
// there is no good way to easily get them and we need them // there is no good way to easily get them and we need them
// for the output // for the output
let min = Array.from(result.state.memory.keys()).reduce( // Default to both being set to tapeHead, because that way
(x, y) => Math.min(x, y)); // even if there are no indices we can get values that
let max = Array.from(result.state.memory.keys()).reduce( // the rest of the code can work with
(x, y) => Math.max(x, y)); let memoryIndices = Array.from(result.state.memory.keys());
let min = memoryIndices.reduce(Math.min, tapeHead);
let max = memoryIndices.reduce(Math.max, tapeHead);
// Get 15 cells of context on each side of tape head // Get 15 cells of context on each side of tape head
// Exception is if max or min comes up before that, in which // Exception is if max or min comes up before that, in which