After some refactoring, several CON error checks done at runtime stood out as things that could be determined at script compile time. They have been moved.

git-svn-id: https://svn.eduke32.com/eduke32@7271 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-12-15 01:38:43 +00:00
parent 3d4d640be3
commit 8f7e842beb
2 changed files with 13 additions and 54 deletions

View file

@ -3284,7 +3284,6 @@ DO_DEFSTATE:
case CON_MAIL:
case CON_MONEY:
case CON_PAPER:
case CON_QUOTE:
case CON_SAVE:
case CON_SAVENN:
case CON_SLEEPTIME:
@ -3294,6 +3293,16 @@ DO_DEFSTATE:
C_GetNextValue(LABEL_DEFINE);
continue;
case CON_QUOTE:
C_GetNextValue(LABEL_DEFINE);
if (EDUKE32_PREDICT_FALSE(((unsigned)g_scriptPtr[-1] >= MAXQUOTES) || apStrings[g_scriptPtr[-1]] == NULL))
{
g_errorCnt++;
C_ReportError(-1);
initprintf("%s:%d: error: invalid quote\n", g_scriptFileName, g_lineNumber);
}
continue;
case CON_ELSE:
{
if (EDUKE32_PREDICT_FALSE(!g_checkingIfElse))
@ -3303,7 +3312,7 @@ DO_DEFSTATE:
g_warningCnt++;
C_ReportError(-1);
initprintf("%s:%d: warning: found `else' with no `if'.\n", g_scriptFileName, g_lineNumber);
initprintf("%s:%d: warning: found `else' with no `if'\n", g_scriptFileName, g_lineNumber);
if (C_GetKeyword() == CON_LEFTBRACE)
{

View file

@ -1754,31 +1754,16 @@ next_instruction:
case CON_MODVAR_GLOBAL:
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("mod by zero!\n");
continue;
}
aGameVars[*insptr].global %= insptr[1];
insptr += 2;
continue;
case CON_MODVAR_ACTOR:
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("mod by zero!\n");
continue;
}
aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES-1)] %= insptr[1];
insptr += 2;
continue;
case CON_MODVAR_PLAYER:
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("mod by zero!\n");
continue;
}
aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS-1)] %= insptr[1];
insptr += 2;
continue;
@ -1928,23 +1913,14 @@ next_instruction:
case CON_DIVVAR_GLOBAL:
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("divide by zero!\n");
continue;
}
aGameVars[*insptr].global = tabledivide32(aGameVars[*insptr].global, insptr[1]);
insptr += 2;
continue;
/*
case CON_DIVVAR_PLAYER:
{
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("divide by zero!\n");
continue;
}
auto &v = aGameVars[*insptr].pValues[vm.playerNum & (MAXPLAYERS - 1)];
v = tabledivide32(v, insptr[1]);
@ -1955,17 +1931,13 @@ next_instruction:
case CON_DIVVAR_ACTOR:
{
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("divide by zero!\n");
continue;
}
auto &v = aGameVars[*insptr].pValues[vm.spriteNum & (MAXSPRITES - 1)];
v = tabledivide32(v, insptr[1]);
insptr += 2;
continue;
}
*/
case CON_DIVVARVAR:
insptr++;
@ -2194,11 +2166,6 @@ next_instruction:
case CON_DIVVAR:
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("divide by zero!\n");
continue;
}
Gv_DivVar(*insptr, insptr[1]);
insptr += 2;
continue;
@ -2235,12 +2202,6 @@ next_instruction:
case CON_MODVAR:
insptr++;
if (EDUKE32_PREDICT_FALSE(insptr[1] == 0))
{
CON_CRITICALERRPRINTF("mod by zero!\n");
continue;
}
Gv_ModVar(*insptr, insptr[1]);
insptr += 2;
continue;
@ -2815,11 +2776,6 @@ badindex:
int const strIndex = *insptr++;
int const XstrIndex = *insptr++;
if (EDUKE32_PREDICT_FALSE((apStrings[strIndex] == NULL || apXStrings[XstrIndex] == NULL)))
{
CON_ERRPRINTF("invalid source quote %d or destination quote %d\n", XstrIndex, strIndex);
continue;
}
Bstrcpy(apStrings[strIndex], apXStrings[XstrIndex]);
continue;
}
@ -6333,12 +6289,6 @@ badindex:
case CON_QUOTE:
insptr++;
if (EDUKE32_PREDICT_FALSE((unsigned)(*insptr) >= MAXQUOTES) || apStrings[*insptr] == NULL)
{
CON_ERRPRINTF("invalid quote %d\n", (int32_t)(*insptr));
continue;
}
if (EDUKE32_PREDICT_FALSE((unsigned)vm.playerNum >= MAXPLAYERS))
{
CON_ERRPRINTF("invalid player %d\n", vm.playerNum);