|
@@ -169,10 +169,10 @@ function insertOutput(outputParameter) {
|
|
|
* @param {string} testingParameter The parameter to test. Could be an immediate value or an address
|
|
|
* @param {string} jumpDestination The address to jump to if the test passes
|
|
|
*/
|
|
|
-function insertTestJump(opcode, testingParameter, jumpDestination) {
|
|
|
+function insertTestJump(opcode, testingParameter, jumpDestination, offset) {
|
|
|
tape[tapePointer++] = getParameterMode(jumpDestination) + getParameterMode(testingParameter) + opcode;
|
|
|
tape[tapePointer++] = testingParameter;
|
|
|
- tape[tapePointer++] = jumpDestination;
|
|
|
+ tape[tapePointer++] = validateJumpDestination(jumpDestination, offset);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -246,6 +246,33 @@ function isLabelStart(parameter) {
|
|
|
return /^\w+:$/.test(parameter);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Confirm that a label exists
|
|
|
+ *
|
|
|
+ * @param {string} labelName The possible label name to check
|
|
|
+ *
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+function validateLabel(labelName) {
|
|
|
+ return labelDictionary.hasOwnProperty(labelName);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Get the address to jump to
|
|
|
+ *
|
|
|
+ * @param {string} jumpDestination The destination to jump to. Could be either a memory address or
|
|
|
+ * @param {number} [offset] An offset for the jump destination. Only used if the jump destination is a label
|
|
|
+ *
|
|
|
+ * @returns {string|number} The address to jump to
|
|
|
+ */
|
|
|
+function validateJumpDestination(jumpDestination, offset = 0) {
|
|
|
+ if (isAddress(jumpDestination)) { return jumpDestination; }
|
|
|
+ if (validateLabel(jumpDestination)) {
|
|
|
+ return labelDictionary[jumpDestination] + offset
|
|
|
+ }
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Get the memory address a value represents
|
|
|
*
|