1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

IF block perf/memory

This commit is contained in:
Asbelos 2022-04-17 10:10:22 +01:00
parent 45f690eb4d
commit 920fcbc095
2 changed files with 31 additions and 31 deletions

View File

@ -519,31 +519,21 @@ bool RMFT2::skipIfBlock() {
while (nest > 0) { while (nest > 0) {
SKIPOP; SKIPOP;
byte opcode = GET_OPCODE; byte opcode = GET_OPCODE;
switch(opcode) { // all other IF type commands increase the nesting level
case OPCODE_ENDEXRAIL: if (opcode>IF_TYPE_OPCODES) nest++;
kill(F("missing ENDIF"), nest); else switch(opcode) {
return false; case OPCODE_ENDEXRAIL:
case OPCODE_IF: kill(F("missing ENDIF"), nest);
case OPCODE_IFCLOSED: return false;
case OPCODE_IFGTE:
case OPCODE_IFLT: case OPCODE_ENDIF:
case OPCODE_IFNOT: nest--;
case OPCODE_IFRANDOM: break;
case OPCODE_IFRESERVE:
case OPCODE_IFTHROWN: case OPCODE_ELSE:
case OPCODE_IFTIMEOUT: // if nest==1 then this is the ELSE for the IF we are skipping
case OPCODE_IFRED: if (nest==1) nest=0; // cause loop exit and return after ELSE
case OPCODE_IFAMBER: break;
case OPCODE_IFGREEN:
nest++;
break;
case OPCODE_ENDIF:
nest--;
break;
case OPCODE_ELSE:
// if nest==1 then this is the ELSE for the IF we are skipping
if (nest==1) nest=0; // cause loop exit and return after ELSE
break;
default: default:
break; break;
} }
@ -574,7 +564,7 @@ void RMFT2::loop2() {
// skipIf will get set to indicate a failing IF condition // skipIf will get set to indicate a failing IF condition
bool skipIf=false; bool skipIf=false;
// if (diag) DIAG(F("RMFT2 %d %d"),opcode,operand); // if (diag) DIAG(F("RMFT2 %d %d"),opcode,operand);
// Attention: Returning from this switch leaves the program counter unchanged. // Attention: Returning from this switch leaves the program counter unchanged.
// This is used for unfinished waits for timers or sensors. // This is used for unfinished waits for timers or sensors.

View File

@ -35,10 +35,9 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
OPCODE_RESERVE,OPCODE_FREE, OPCODE_RESERVE,OPCODE_FREE,
OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART, OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART,
OPCODE_ATGTE,OPCODE_ATLT, OPCODE_ATGTE,OPCODE_ATLT,
OPCODE_ATTIMEOUT1,OPCODE_ATTIMEOUT2,OPCODE_IFTIMEOUT, OPCODE_ATTIMEOUT1,OPCODE_ATTIMEOUT2,
OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET, OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET,
OPCODE_IF,OPCODE_IFNOT,OPCODE_ENDIF,OPCODE_IFRANDOM,OPCODE_IFRESERVE, OPCODE_ENDIF,OPCODE_ELSE,
OPCODE_IFCLOSED, OPCODE_IFTHROWN,OPCODE_ELSE,
OPCODE_DELAY,OPCODE_DELAYMINS,OPCODE_DELAYMS,OPCODE_RANDWAIT, OPCODE_DELAY,OPCODE_DELAYMINS,OPCODE_DELAYMS,OPCODE_RANDWAIT,
OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF, OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF,
OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE, OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE,
@ -49,10 +48,21 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
OPCODE_PAUSE, OPCODE_RESUME,OPCODE_POWEROFF,OPCODE_POWERON, OPCODE_PAUSE, OPCODE_RESUME,OPCODE_POWEROFF,OPCODE_POWERON,
OPCODE_ONCLOSE, OPCODE_ONTHROW, OPCODE_SERVOTURNOUT, OPCODE_PINTURNOUT, OPCODE_ONCLOSE, OPCODE_ONTHROW, OPCODE_SERVOTURNOUT, OPCODE_PINTURNOUT,
OPCODE_PRINT,OPCODE_DCCACTIVATE, OPCODE_PRINT,OPCODE_DCCACTIVATE,
OPCODE_ONACTIVATE,OPCODE_ONDEACTIVATE,OPCODE_IFGTE,OPCODE_IFLT, OPCODE_ONACTIVATE,OPCODE_ONDEACTIVATE,
OPCODE_ROSTER,OPCODE_KILLALL, OPCODE_ROSTER,OPCODE_KILLALL,
OPCODE_ROUTE,OPCODE_AUTOMATION,OPCODE_SEQUENCE,
OPCODE_ENDTASK,OPCODE_ENDEXRAIL,
// OPcodes below this point are skip-nesting IF operations
// placed here so that they may be skipped as a group
// see skipIfBlock()
IF_TYPE_OPCODES, // do not move this...
OPCODE_IFRED,OPCODE_IFAMBER,OPCODE_IFGREEN, OPCODE_IFRED,OPCODE_IFAMBER,OPCODE_IFGREEN,
OPCODE_ROUTE,OPCODE_AUTOMATION,OPCODE_SEQUENCE,OPCODE_ENDTASK,OPCODE_ENDEXRAIL OPCODE_IFGTE,OPCODE_IFLT,
OPCODE_IFTIMEOUT,
OPCODE_IF,OPCODE_IFNOT,
OPCODE_IFRANDOM,OPCODE_IFRESERVE,
OPCODE_IFCLOSED, OPCODE_IFTHROWN
}; };