|
@@ -111,6 +111,26 @@ module.exports = class Stack {
|
|
|
this._stack[index] = value;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the pointer to a new address in memory
|
|
|
+ *
|
|
|
+ * If the address is out of the upper bounds of the current memory stack,
|
|
|
+ * the stack will be expanded, filling with 0's as needed.
|
|
|
+ *
|
|
|
+ * @param {number} newAddress The new pointer address
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
+ SetPointerAddress(newAddress) {
|
|
|
+ if (newAddress > this._stack.length) {
|
|
|
+ // Expand the stack if needed
|
|
|
+ const oldLength = this._stack.length;
|
|
|
+ this._stack[newAddress] = 0;
|
|
|
+ this._stack.fill(0, oldLength, newAddress);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.pointer = newAddress;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return the whole stack
|
|
|
*
|