- deactivated the label type checks because the original code doesn't have them and they'd get in the way of testing.

This commit is contained in:
Christoph Oelckers 2020-05-12 16:33:32 +02:00
parent 3ab19a2f0d
commit 53e4b8bf19
6 changed files with 105 additions and 49 deletions

View file

@ -47,6 +47,9 @@ int line_number;
int labelcnt;
int errorcount, warningcount; // was named 'error' and 'warning' which is too generic for public variables and may clash with other code.
int g_currentSourceFile;
intptr_t parsing_actor;
int parsing_state;
//G_EXTERN char tempbuf[MAXSECTORS << 1], buf[1024]; todo - move to compile state. tempbuf gets used nearly everywhere as scratchpad memory.
extern char tempbuf[];
extern intptr_t* scriptptr;
@ -196,6 +199,17 @@ int getkeyword(const char* text)
//
//---------------------------------------------------------------------------
int findlabel(const char* text)
{
for (int j = 0; j < labelcnt; j++)
{
if (strcmp(label + (j << 6), text) == 0)
{
return labelcode[j];
}
}
return -1;
}
//---------------------------------------------------------------------------
//
@ -421,7 +435,18 @@ void transnum(void)
return;
}
*scriptptr = atol(textptr);
// Now it's getting nasty... With all of C's integer conversion functions we have to look for undefined behavior and truncation problems. This one's the least problematic approach
// that ignores octal conversion.
int64_t value;
char *outp;
bool ishex = (textptr[0] == 0 && tolower(textptr[1]) == 'x') || (textptr[0] == '-' && textptr[1] == 0 && tolower(textptr[2]) == 'x');
if (*textptr == '-') value = strtoll(textptr, &outp, ishex? 16 : 10);
else value = strtoull(textptr, &outp, ishex ? 16 : 10);
if (*outp != 0)
{
// conversion was not successful.
}
*scriptptr = int(value); // truncate the parsed value to 32 bit.
scriptptr++;
textptr += l;
}
@ -447,6 +472,7 @@ int parsecommand(int tw) // for now just run an externally parsed command.
uint8_t done, temp_ifelse_check;// , tw;
int temp_line_number;
int temp_current_file;
int lnum;
#if FOR_LATER // for now this should just parse a single instruction
if ((errorcount + warningcount) > 12 || (*textptr == '\0') || (*(textptr + 1) == '\0')) return 1;
@ -499,20 +525,14 @@ int parsecommand(int tw) // for now just run an externally parsed command.
return 0;
}
for (j = 0; j < labelcnt; j++)
{
if (strcmp(label + (j << 6), label + (labelcnt << 6)) == 0)
{
*scriptptr = labelcode[j];
break;
}
}
int lnum = findlabel(label + (labelcnt << 6));
if (j == labelcnt)
if (lnum < 0)
{
Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) State '%s' not found.\n", fn, line_number, label + (labelcnt << 6));
errorcount++;
}
*scriptptr = lnum;
scriptptr++;
return 0;

View file

@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_DUKE_NS
#if 0
enum
{
LABEL_ANY = -1,
@ -42,6 +43,7 @@ enum
LABEL_MOVE = 32,
LABEL_EVENT = 0x40,
};
#endif
#define LABEL_HASPARM2 1
#define LABEL_ISSTRING 2

View file

@ -160,7 +160,9 @@ G_EXTERN int16_t g_cyclers[MAXCYCLERS][6];
G_EXTERN int16_t g_mirrorSector[64];
G_EXTERN int16_t g_mirrorWall[64];
G_EXTERN int32_t *labelcode;
#if 0
G_EXTERN int32_t *labeltype;
#endif
G_EXTERN ClockTicks lockclock;
G_EXTERN ClockTicks ototalclock;

View file

@ -6520,7 +6520,9 @@ static void G_Cleanup(void)
if (label != (char *)&sprite[0]) Xfree(label);
if (labelcode != (int32_t *)&sector[0]) Xfree(labelcode);
#if 0
if (labeltype != (int32_t*)&wall[0]) Xfree(labeltype);
#endif
Xfree(apScript);
Xfree(bitptr);
@ -6544,7 +6546,9 @@ static void G_CompileScripts(void)
{
label = (char *)&sprite[0]; // V8: 16384*44/64 = 11264 V7: 4096*44/64 = 2816
labelcode = (int32_t *)&sector[0]; // V8: 4096*40/4 = 40960 V7: 1024*40/4 = 10240
#if 0
labeltype = (int32_t *)&wall[0]; // V8: 16384*32/4 = 131072 V7: 8192*32/4 = 65536
#endif
C_Compile(G_ConFile());
@ -6562,11 +6566,15 @@ static void G_CompileScripts(void)
Bmemcpy(newlabel, label, labelcnt*64);
Bmemcpy(newlabelcode, labelcode, labelcnt*sizeof(int32_t));
#if 0
Bmemcpy(newlabeltype, labeltype, labelcnt*sizeof(int32_t));
#endif
label = newlabel;
labelcode = newlabelcode;
#if 0
labeltype = newlabeltype;
#endif
}
Bmemset(sprite, 0, MAXSPRITES*sizeof(spritetype));

View file

@ -63,7 +63,8 @@ uint32_t g_scriptcrc;
char g_szBuf[1024];
static char g_szCurrentBlockName[256] = "(none)", g_szLastBlockName[256] = "NULL";
static int32_t g_checkingIfElse, g_processingState, g_lastKeyword = -1;
static int32_t g_checkingIfElse, g_lastKeyword = -1;
extern int parsing_state;
// The pointer to the start of the case table in a switch statement.
// First entry is 'default' code.
@ -75,7 +76,7 @@ static int32_t C_ParseCommand(int32_t loop);
static int32_t C_SetScriptSize(int32_t size);
static intptr_t apScriptGameEventEnd[MAXEVENTS];
static intptr_t g_parsingActorPtr;
extern intptr_t parsing_actor;
static intptr_t g_scriptEventOffset;
extern char *textptr;
@ -286,7 +287,7 @@ static int32_t C_SkipComments(void)
Printf("%s:%d: debug: EOF in comment!\n",g_scriptFileName,line_number);
C_ReportError(-1);
Printf("%s:%d: error: found `/*' with no `*/'.\n",g_scriptFileName,line_number);
g_parsingActorPtr = g_processingState = g_numBraces = 0;
parsing_actor = parsing_state = g_numBraces = 0;
g_errorCnt++;
continue;
}
@ -562,7 +563,7 @@ static void C_GetNextVarType(int32_t type)
Bstrcpy(tempbuf,LAST_LABEL);
id = hash_find(&h_labels,tempbuf);
if (EDUKE32_PREDICT_TRUE(id>=0 && labeltype[id] & LABEL_DEFINE))
if (EDUKE32_PREDICT_TRUE(id>=0 /*&& labeltype[id] & LABEL_DEFINE*/))
{
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug)
Printf("%s:%d: debug: label `%s' in place of gamevar.\n",g_scriptFileName,line_number,label+(id<<6));
@ -613,7 +614,8 @@ static FORCE_INLINE void C_GetManyVarsType(int32_t type, int num)
// LABEL_* (>0) if that type and matched
//
// *scriptptr will contain the value OR 0 if wrong type or error
static int32_t C_GetNextValue(int32_t type)
#define C_GetNextValue(a) C_GetNextValue_()
static int32_t C_GetNextValue_()
{
C_SkipComments();
@ -640,33 +642,37 @@ static int32_t C_GetNextValue(int32_t type)
if (i>=0)
{
if (EDUKE32_PREDICT_TRUE(labeltype[i] & type))
//if (EDUKE32_PREDICT_TRUE(labeltype[i] & type))
{
#if 0
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1)
{
char *gl = C_GetLabelType(labeltype[i]);
Printf("%s:%d: debug: %s label `%s'.\n",g_scriptFileName,line_number,gl,label+(i<<6));
Xfree(gl);
}
#endif
BITPTR_CLEAR(scriptptr-apScript);
*(scriptptr++) = labelcode[i];
textptr += l;
return labeltype[i];
return 0;// labeltype[i];
}
#if 0
BITPTR_CLEAR(scriptptr-apScript);
*(scriptptr++) = 0;
textptr += l;
char *el = C_GetLabelType(type);
char *gl = C_GetLabelType(labeltype[i]);
char *gl = C_GetLabelType(/*labeltype[i]*/0);
C_ReportError(-1);
Printf("%s:%d: warning: expected %s, found %s.\n",g_scriptFileName,line_number,el,gl);
g_warningCnt++;
Xfree(el);
Xfree(gl);
return -1; // valid label name, but wrong type
#endif
}
if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) == 0 && *textptr != '-'))
@ -931,6 +937,8 @@ static inline void C_FinishBitOr(int32_t value)
*scriptptr++ = value;
}
int parsecommand(int tw); // for now just run an externally parsed command.
static int32_t C_ParseCommand(int32_t loop)
{
int32_t i, j=0, k=0, tw;
@ -951,14 +959,14 @@ static int32_t C_ParseCommand(int32_t loop)
case -2:
return 1; //End
case concmd_state:
if (!g_parsingActorPtr && g_processingState == 0)
if (!parsing_actor && parsing_state == 0)
{
C_GetNextLabelName();
scriptptr--;
labelcode[labelcnt] = scriptptr-apScript;
labeltype[labelcnt] = LABEL_STATE;
//labeltype[labelcnt] = LABEL_STATE;
g_processingState = 1;
parsing_state = 1;
Bsprintf(g_szCurrentBlockName,"%s",label+(labelcnt<<6));
if (getkeyword(label + (labelcnt << 6)) >= 0)
@ -984,6 +992,7 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
}
/*
if (EDUKE32_PREDICT_FALSE((labeltype[j] & LABEL_STATE) != LABEL_STATE))
{
char *gl = (char *) C_GetLabelType(labeltype[j]);
@ -995,6 +1004,7 @@ static int32_t C_ParseCommand(int32_t loop)
BITPTR_CLEAR(scriptptr-apScript-1);
continue; // valid label name, but wrong type
}
*/
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1)
Printf("%s:%d: debug: state label `%s'.\n", g_scriptFileName, line_number, label+(j<<6));
@ -1007,7 +1017,7 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
case concmd_ends:
if (EDUKE32_PREDICT_FALSE(g_processingState == 0))
if (EDUKE32_PREDICT_FALSE(parsing_state == 0))
{
C_ReportError(-1);
Printf("%s:%d: error: found `ends' without open `state'.\n",g_scriptFileName,line_number);
@ -1026,7 +1036,7 @@ static int32_t C_ParseCommand(int32_t loop)
g_errorCnt++;
}
g_processingState = 0;
parsing_state = 0;
Bsprintf(g_szCurrentBlockName,"(none)");
}
continue;
@ -1113,7 +1123,7 @@ static int32_t C_ParseCommand(int32_t loop)
else
{
hash_add(&h_labels,label+(labelcnt<<6),labelcnt,0);
labeltype[labelcnt] = LABEL_DEFINE;
//labeltype[labelcnt] = LABEL_DEFINE;
labelcode[labelcnt++] = *(scriptptr-1);
//if (*(scriptptr-1) >= 0 && *(scriptptr-1) < MAXTILES && g_dynamicTileMapping)
// G_ProcessDynamicTileMapping(label+((labelcnt-1)<<6),*(scriptptr-1));
@ -1139,8 +1149,10 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
case concmd_move:
if (g_parsingActorPtr || g_processingState)
if (parsing_actor || parsing_state)
{
C_GetNextValue(LABEL_MOVE | LABEL_DEFINE);
#if 0
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(scriptptr-1) != 0) && (*(scriptptr-1) != 1)))
{
C_ReportError(-1);
@ -1149,6 +1161,7 @@ static int32_t C_ParseCommand(int32_t loop)
Printf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,line_number);
g_warningCnt++;
}
#endif
j = 0;
while (C_GetKeyword() == -1)
@ -1177,7 +1190,7 @@ static int32_t C_ParseCommand(int32_t loop)
else
{
hash_add(&h_labels,label+(labelcnt<<6),labelcnt,0);
labeltype[labelcnt] = LABEL_MOVE;
//labeltype[labelcnt] = LABEL_MOVE;
labelcode[labelcnt++] = scriptptr-apScript;
}
@ -1268,7 +1281,7 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
case concmd_ai:
if (g_parsingActorPtr || g_processingState)
if (parsing_actor || parsing_state)
{
C_GetNextValue(LABEL_AI);
}
@ -1292,7 +1305,7 @@ static int32_t C_ParseCommand(int32_t loop)
}
else
{
labeltype[labelcnt] = LABEL_AI;
//labeltype[labelcnt] = LABEL_AI;
hash_add(&h_labels,label+(labelcnt<<6),labelcnt,0);
labelcode[labelcnt++] = scriptptr-apScript;
}
@ -1304,6 +1317,8 @@ static int32_t C_ParseCommand(int32_t loop)
C_GetNextValue(LABEL_ACTION);
else if (j == 2)
{
C_GetNextValue(LABEL_MOVE | LABEL_DEFINE);
#if 0
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) &&
(*(scriptptr-1) != 0) && (*(scriptptr-1) != 1)))
{
@ -1313,6 +1328,7 @@ static int32_t C_ParseCommand(int32_t loop)
Printf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,line_number);
g_warningCnt++;
}
#endif
k = 0;
while (C_GetKeyword() == -1)
@ -1337,7 +1353,7 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
case concmd_action:
if (g_parsingActorPtr || g_processingState)
if (parsing_actor || parsing_state)
{
C_GetNextValue(LABEL_ACTION);
}
@ -1362,7 +1378,7 @@ static int32_t C_ParseCommand(int32_t loop)
}
else
{
labeltype[labelcnt] = LABEL_ACTION;
//labeltype[labelcnt] = LABEL_ACTION;
labelcode[labelcnt] = scriptptr-apScript;
hash_add(&h_labels,label+(labelcnt<<6),labelcnt,0);
labelcnt++;
@ -1383,7 +1399,7 @@ static int32_t C_ParseCommand(int32_t loop)
case concmd_actor:
case concmd_useractor:
if (EDUKE32_PREDICT_FALSE(g_processingState || g_parsingActorPtr))
if (EDUKE32_PREDICT_FALSE(parsing_state || parsing_actor))
{
C_ReportError(ERROR_FOUNDWITHIN);
g_errorCnt++;
@ -1391,7 +1407,7 @@ static int32_t C_ParseCommand(int32_t loop)
g_numBraces = 0;
scriptptr--;
g_parsingActorPtr = scriptptr - apScript;
parsing_actor = scriptptr - apScript;
if (tw == concmd_useractor)
{
@ -1411,8 +1427,8 @@ static int32_t C_ParseCommand(int32_t loop)
j = hash_find(&h_labels, g_szCurrentBlockName);
if (j != -1)
labeltype[j] |= LABEL_ACTOR;
//if (j != -1)
// labeltype[j] |= LABEL_ACTOR;
if (tw == concmd_useractor)
{
@ -1439,7 +1455,7 @@ static int32_t C_ParseCommand(int32_t loop)
continue;
}
g_tile[*scriptptr].execPtr = apScript + g_parsingActorPtr;
g_tile[*scriptptr].execPtr = apScript + parsing_actor;
if (tw == concmd_useractor)
{
@ -1452,8 +1468,8 @@ static int32_t C_ParseCommand(int32_t loop)
for (j=0; j<4; j++)
{
BITPTR_CLEAR(g_parsingActorPtr+j);
*((apScript+j)+g_parsingActorPtr) = 0;
BITPTR_CLEAR(parsing_actor+j);
*((apScript+j)+parsing_actor) = 0;
if (j == 3)
{
j = 0;
@ -1485,6 +1501,8 @@ static int32_t C_ParseCommand(int32_t loop)
case 2:
// XXX: LABEL_MOVE|LABEL_DEFINE, what is this shit? compatibility?
// yep, it sure is :(
C_GetNextValue(LABEL_MOVE | LABEL_DEFINE);
#if 0
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(scriptptr-1) != 0) && (*(scriptptr-1) != 1)))
{
C_ReportError(-1);
@ -1493,19 +1511,20 @@ static int32_t C_ParseCommand(int32_t loop)
Printf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,line_number);
g_warningCnt++;
}
#endif
break;
}
if (*(scriptptr-1) >= (intptr_t)&apScript[0] && *(scriptptr-1) < (intptr_t)&apScript[g_scriptSize])
BITPTR_SET(g_parsingActorPtr+j);
else BITPTR_CLEAR(g_parsingActorPtr+j);
*((apScript+j)+g_parsingActorPtr) = *(scriptptr-1);
BITPTR_SET(parsing_actor+j);
else BITPTR_CLEAR(parsing_actor+j);
*((apScript+j)+parsing_actor) = *(scriptptr-1);
}
}
g_checkingIfElse = 0;
continue;
case concmd_onevent:
if (EDUKE32_PREDICT_FALSE(g_processingState || g_parsingActorPtr))
if (EDUKE32_PREDICT_FALSE(parsing_state || parsing_actor))
{
C_ReportError(ERROR_FOUNDWITHIN);
g_errorCnt++;
@ -1513,7 +1532,7 @@ static int32_t C_ParseCommand(int32_t loop)
g_numBraces = 0;
scriptptr--;
g_scriptEventOffset = g_parsingActorPtr = scriptptr - apScript;
g_scriptEventOffset = parsing_actor = scriptptr - apScript;
C_SkipComments();
j = 0;
@ -1832,6 +1851,8 @@ ifvar:
C_GetNextValue(LABEL_ACTION);
break;
case concmd_ifmove:
C_GetNextValue(LABEL_MOVE | LABEL_DEFINE);
#if 0
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(scriptptr-1) != 0) && (*(scriptptr-1) != 1)))
{
C_ReportError(-1);
@ -1839,6 +1860,7 @@ ifvar:
Printf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,line_number);
g_warningCnt++;
}
#endif
break;
case concmd_ifpinventory:
C_GetNextValue(LABEL_DEFINE);
@ -1946,7 +1968,7 @@ ifvar:
}
case concmd_leftbrace:
if (EDUKE32_PREDICT_FALSE(!(g_processingState || g_parsingActorPtr || g_scriptEventOffset)))
if (EDUKE32_PREDICT_FALSE(!(parsing_state || parsing_actor || g_scriptEventOffset)))
{
g_errorCnt++;
C_ReportError(ERROR_SYNTAXERROR);
@ -2249,13 +2271,13 @@ ifvar:
g_errorCnt++;
}
g_scriptEventOffset = g_parsingActorPtr = 0;
g_scriptEventOffset = parsing_actor = 0;
g_currentEvent = -1;
Bsprintf(g_szCurrentBlockName,"(none)");
continue;
case concmd_enda:
if (EDUKE32_PREDICT_FALSE(!g_parsingActorPtr || g_scriptEventOffset))
if (EDUKE32_PREDICT_FALSE(!parsing_actor || g_scriptEventOffset))
{
C_ReportError(-1);
Printf("%s:%d: error: found `enda' without open `actor'.\n",g_scriptFileName,line_number);
@ -2267,7 +2289,7 @@ ifvar:
C_ReportError(g_numBraces > 0 ? ERROR_OPENBRACKET : ERROR_CLOSEBRACKET);
g_errorCnt++;
}
g_parsingActorPtr = 0;
parsing_actor = 0;
Bsprintf(g_szCurrentBlockName,"(none)");
continue;
@ -2534,8 +2556,8 @@ void C_ReportError(int32_t iError)
{
if (Bstrcmp(g_szCurrentBlockName,g_szLastBlockName))
{
if (g_scriptEventOffset || g_processingState || g_parsingActorPtr)
Printf("%s: In %s `%s':\n",g_scriptFileName,g_scriptEventOffset?"event":g_parsingActorPtr?"actor":"state",g_szCurrentBlockName);
if (g_scriptEventOffset || parsing_state || parsing_actor)
Printf("%s: In %s `%s':\n",g_scriptFileName,g_scriptEventOffset?"event":parsing_actor?"actor":"state",g_szCurrentBlockName);
else Printf("%s: At top level:\n",g_scriptFileName);
Bstrcpy(g_szLastBlockName,g_szCurrentBlockName);
}
@ -2551,7 +2573,7 @@ void C_ReportError(int32_t iError)
Printf("%s:%d: error: expected a keyword but found `%s'.\n",g_scriptFileName,line_number,tempbuf);
break;
case ERROR_FOUNDWITHIN:
Printf("%s:%d: error: found `%s' within %s.\n",g_scriptFileName,line_number,tempbuf,g_parsingActorPtr?"an actor":"a state");
Printf("%s:%d: error: found `%s' within %s.\n",g_scriptFileName,line_number,tempbuf,parsing_actor?"an actor":"a state");
break;
case ERROR_ISAKEYWORD:
Printf("%s:%d: error: symbol `%s' is a keyword.\n",g_scriptFileName,line_number,label+(labelcnt<<6));

View file

@ -425,6 +425,7 @@ static int osdcmd_printtimes(CCmdFuncPtr UNUSED(parm))
buf[0] = 0;
/*
for (int ii=0; ii<labelcnt; ii++)
{
if (labelcode[ii] == i && labeltype[ii] & LABEL_ACTOR)
@ -433,6 +434,7 @@ static int osdcmd_printtimes(CCmdFuncPtr UNUSED(parm))
break;
}
}
*/
if (!buf[0]) Bsprintf(buf, "%d", i);