Browse Source

Add ability to set computers memory to a new stack

Added the SetMemory function, which allows you to set the computer's
memory to an entirely new stack.
ApisNecros 1 year ago
parent
commit
9896b63595
1 changed files with 13 additions and 0 deletions
  1. 13 0
      IntComp/Computer.js

+ 13 - 0
IntComp/Computer.js

@@ -152,6 +152,19 @@ module.exports = class Computer {
     Reset() {
         this.stack = new Stack(this._initialMemory);
     }
+
+    /**
+     * Sets the computer's memory to a new stack
+     *
+     * Note: This resets the computer's initial memory, so `Reset` will use this value
+     *
+     * @param {number[]} stack The new memory stack for the computer
+     * @returns {void}
+     */
+    SetMemory(stack) {
+        this._initialMemory = DeepClone(stack);
+        this.stack = new Stack(stack);
+    }
 };
 
 /**