|
@@ -68,15 +68,15 @@ module.exports = class Computer {
|
|
|
this.outputComputer = null;
|
|
|
|
|
|
/**
|
|
|
- * An input value provided at runtime
|
|
|
+ * An array of input values provided at runtime
|
|
|
*
|
|
|
* This value will be passed to the first INPUT opcode made by the computer,
|
|
|
* and will then be cleared. If the program being ran tries to make another
|
|
|
* call to INPUT, and `options.inputFromConsole` is false, then an error
|
|
|
* will be thrown.
|
|
|
- * @type {number}
|
|
|
+ * @type {number[]}
|
|
|
*/
|
|
|
- this.runtimeInput = null;
|
|
|
+ this.runtimeInput = [];
|
|
|
|
|
|
/**
|
|
|
* An array of outputs from the computer
|
|
@@ -115,7 +115,7 @@ module.exports = class Computer {
|
|
|
* Runs opcodes on the stack until either the a HALT command is
|
|
|
* encountered, or an error is thrown. Stores the input to be used
|
|
|
* by the first INPUT opcode encountered.
|
|
|
- * @param {number} input The input value to initialize the comptuer with.
|
|
|
+ * @param {number[]} input An array of input values to initialize the comptuer with
|
|
|
* @returns {void}
|
|
|
*/
|
|
|
async RunWithInput(input) {
|
|
@@ -280,8 +280,10 @@ module.exports = class Computer {
|
|
|
// Get the input based on the input mode
|
|
|
switch (inputMode) {
|
|
|
case InputModes.INPUT_FROM_RUNTIME_STACK: {
|
|
|
- userInput = this.runtimeInput;
|
|
|
- this.runtimeInput = null;
|
|
|
+ userInput = this.runtimeInput.shift();
|
|
|
+ if (userInput === undefined) {
|
|
|
+ throw new Error("runtime Input array empty");
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
case InputModes.INPUT_FROM_CONSOLE: {
|