//MACRO IF Condition, Action, Id= !"", WReg= !"", Far{boolean}= no //-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // var nestStack= DVASM.getJSGlobal("__arch_condNestBlockStack"); if (nestStack == null) nestStack= []; // // Check parameters // Action= Action.toUpperCase(); if (! ["THEN", "CONTINUE", "BREAK", "GOTO"].includes(Action)) return DVASM.putError("Action for IF macro is [" + Action + "] - it must be [ THEN | CONTINUE | BREAK | GOTO ]"); if (Action === "GOTO" && Id === "") return DVASM.putError("Key-word parameter [Id] for IF macro is required when action is [GOTO]"); if (! ["GOTO", "CONTINUE", "BREAK"].includes(Action) && Id !== "") return DVASM.putError("Key-word parameter [Id] for IF macro not allowed when action is [" + Action + "]"); // // Handle IF condition, THEN // if (Action === "THEN") { var block= ["IF", Label, DVASM.getNewLabel(), DVASM.getNewLabel()]; var startLabel= DVASM.getNewLabel(); DVASM.formatLine(Label, "__CondGen", Condition + ", true, " + startLabel + ", " + block[2] + ", WReg= " + WReg + ", " + Far, ""); DVASM.formatLine("", "INDENTIN", "", ""); nestStack.push(block); DVASM.putJSGlobal("__arch_condNestBlockStack", nestStack); return; } // // Get WHILE/DO outer nest with or without Id // var targetBlock= null; if (["CONTINUE", "BREAK"].includes(Action)) { for (var i= nestStack.length-1; i >= 0; i--) { targetBlock= nestStack[i]; if (targetBlock[0] == "WHILE" || targetBlock[0] == "DO") { if (Id === "") break; if (targetBlock[1] === Id) break } targetBlock= null; } if (targetBlock == null) return DVASM.putError("Unable to find an outer nest block with opcode of [ WHILE ] or [ DO ]" + (Id === null ? "" : " with Id=" + Id)); var skipAction= DVASM.getNewLabel(); if (Action === "CONTINUE") { if (targetBlock[5].length > 0) { DVASM.formatLine(Label, "__CondGen", Condition + ", false, " + targetBlock[1] + ", " + skipAction + ", WReg= " + WReg + ", " + Far, ""); for (var i= 0; i < targetBlock[5].length; i++) DVASM.formatLine("", targetBlock[5][i].trim(), "", ""); DVASM.formatLine("", "JAL", targetBlock[2], ""); } else DVASM.formatLine(Label, "__CondGen", Condition + ", false, " + targetBlock[1] + ", " + skipAction + ", WReg= " + WReg + ", " + Far, ""); } else DVASM.formatLine(Label, "__CondGen", Condition + ", false, " + targetBlock[3] + ", " + skipAction + ", WReg= " + WReg + ", " + Far, ""); return; } // // Handle GOTO // DVASM.formatLine(Label, "__CondGen", Condition + ", false, " + Id + ", " + DVASM.getNewLabel() + ", WReg= " + WReg + ", " + Far, "");