소스 검색

Add isOutput param to Get function

When getting a value off the stack, if that value is going to be the
memory address of the output for another function, then we never want it
in immediate mode. In this case, only the value at the next pointer, or
that value + the Relative Base Offset should be returned.
ApisNecros 1 년 전
부모
커밋
b2e7168be8
1개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. 8 3
      IntComp/Stack.js

+ 8 - 3
IntComp/Stack.js

@@ -40,16 +40,21 @@ module.exports = class Stack {
     /**
      * Get the value from the stack by the pointer's current position
      *
+     * When `isOutput` is set to `true`, then a value retrieved in Immediate Mode,
+     * or the result of a Relative Mode offset is returned.
+     *
      * @param {number} [parameterMode=0] The Parameter Mode to use to retrieve the value
+     * @param {boolean} [isOutput=false] Is the parameter going to be an output position
      * @returns {number} The value at the current pointer position on the stack
      */
-    Get(parameterMode = ComputerParameterMode.POSITION_MODE) {
+    Get(parameterMode = ComputerParameterMode.POSITION_MODE, isOutput = false) {
         let value = this._stack[this.pointer];
-        if (parameterMode == ComputerParameterMode.POSITION_MODE) {
+        if (!isOutput && parameterMode == ComputerParameterMode.POSITION_MODE) {
             value = this._stack[value];
         }
         else if (parameterMode == ComputerParameterMode.RELATIVE_MODE) {
-            value = this._stack[value + this.relativeBaseOffset];
+            const newPointer = value + this.relativeBaseOffset;
+            value = isOutput ? newPointer : this._stack[newPointer];
         }
 
         return value ?? 0;