- fixing the ifelse check, consolidating the tail code for 'if' instructions.

This commit is contained in:
Christoph Oelckers 2020-05-13 09:17:59 +02:00
parent 2f9d62a40a
commit 3a95664b0b

View file

@ -1324,24 +1324,7 @@ int parsecommand(int tw) // for now just run an externally parsed command.
return 0; return 0;
} }
appendscriptvalue(i); // the ID of the DEF (offset into array...) appendscriptvalue(i); // the ID of the DEF (offset into array...)
goto if_common;
tempscrptr = scriptptr;
scriptptr++; //Leave a spot for the fail location
// eat comments
do
{
j = keyword();
if (j == 20 || j == 39)
parsecommand();
} while (j == 20 || j == 39);
parsecommand();
*tempscrptr = (intptr_t)scriptptr;
checking_ifelse++;
return 0;
case concmd_ifvarl: case concmd_ifvarl:
case concmd_ifvarg: case concmd_ifvarg:
@ -1368,23 +1351,7 @@ int parsecommand(int tw) // for now just run an externally parsed command.
appendscriptvalue(i); // the ID of the DEF (offset into array...) appendscriptvalue(i); // the ID of the DEF (offset into array...)
transnum(); // the number to check against... transnum(); // the number to check against...
goto if_common;
tempscrptr = scriptptr;
scriptptr++; //Leave a spot for the fail location
do
{
j = keyword();
if (j == 20 || j == 39)
parsecommand();
} while (j == 20 || j == 39);
parsecommand();
*tempscrptr = (intptr_t)scriptptr;
checking_ifelse++;
return 0;
case concmd_addlogvar: case concmd_addlogvar:
// syntax: addlogvar <var> // syntax: addlogvar <var>
@ -1427,6 +1394,17 @@ int parsecommand(int tw) // for now just run an externally parsed command.
appendscriptvalue(line_number); appendscriptvalue(line_number);
return 0; return 0;
#endif #endif
case concmd_ifp:
j = 0;
do
{
transnum();
popscriptvalue();
j |= *scriptptr;
} while (keyword() == -1);
appendscriptvalue(j);
goto if_common;
case concmd_ifpinventory: case concmd_ifpinventory:
transnum(); transnum();
case concmd_ifrnd: case concmd_ifrnd:
@ -1462,7 +1440,6 @@ int parsecommand(int tw) // for now just run an externally parsed command.
case concmd_ifsquished: case concmd_ifsquished:
case concmd_ifdead: case concmd_ifdead:
case concmd_ifcanshoottarget: case concmd_ifcanshoottarget:
case concmd_ifp:
case concmd_ifhitspace: case concmd_ifhitspace:
case concmd_ifoutside: case concmd_ifoutside:
case concmd_ifmultiplayer: case concmd_ifmultiplayer:
@ -1488,19 +1465,7 @@ int parsecommand(int tw) // for now just run an externally parsed command.
// case concmd_iffindnewspot: // RRDH // case concmd_iffindnewspot: // RRDH
// case concmd_ifpupwind: // case concmd_ifpupwind:
if_common: // this code is identical for all 'if...'instructions.
if (tw == concmd_ifp)
{
j = 0;
do
{
transnum();
popscriptvalue();
j |= *scriptptr;
} while (keyword() == -1);
appendscriptvalue(j);
}
tempscrptr = scriptpos(); tempscrptr = scriptpos();
reservescriptspace(1); //Leave a spot for the fail location reservescriptspace(1); //Leave a spot for the fail location
@ -1508,8 +1473,10 @@ int parsecommand(int tw) // for now just run an externally parsed command.
parsecommand(); parsecommand();
setscriptvalue(tempscrptr, scriptpos()); setscriptvalue(tempscrptr, scriptpos());
checking_ifelse++; if (keyword() == concmd_else) // only increment checking_ifelse if there actually is an else. Otherwise this would break the entire checking logic and render it non-functional
checking_ifelse++;
return 0; return 0;
case concmd_leftbrace: case concmd_leftbrace:
num_squigilly_brackets++; num_squigilly_brackets++;
#if 0 #if 0