Minor CON compiler cleanup

git-svn-id: https://svn.eduke32.com/eduke32@7232 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:14:20 +00:00
parent 5998256125
commit 4bc7963f48

View file

@ -1387,6 +1387,7 @@ const tokenmap_t iter_tokens [] =
#endif #endif
char *bitptr; // pointer to bitmap of which bytecode positions contain pointers char *bitptr; // pointer to bitmap of which bytecode positions contain pointers
#define BITPTR_SET(x) (bitptr[(x)>>3] |= (1<<((x)&7))) #define BITPTR_SET(x) (bitptr[(x)>>3] |= (1<<((x)&7)))
#define BITPTR_CLEAR(x) (bitptr[(x)>>3] &= ~(1<<((x)&7))) #define BITPTR_CLEAR(x) (bitptr[(x)>>3] &= ~(1<<((x)&7)))
#define BITPTR_IS_POINTER(x) (bitptr[(x)>>3] & (1<<((x) &7))) #define BITPTR_IS_POINTER(x) (bitptr[(x)>>3] & (1<<((x) &7)))
@ -1654,6 +1655,25 @@ static void C_GetNextLabelName(void)
initprintf("%s:%d: debug: label `%s'.\n",g_scriptFileName,g_lineNumber,LAST_LABEL); initprintf("%s:%d: debug: label `%s'.\n",g_scriptFileName,g_lineNumber,LAST_LABEL);
} }
static inline void scriptWriteValue(int32_t const value)
{
BITPTR_CLEAR(g_scriptPtr-apScript);
*g_scriptPtr++ = value;
}
// addresses passed to these functions must be within the block of memory pointed to by apScript
static inline void scriptWriteAtOffset(int32_t const value, intptr_t * const addr)
{
BITPTR_CLEAR(addr-apScript);
*(addr) = value;
}
static inline void scriptWritePointer(intptr_t const value, intptr_t * const addr)
{
BITPTR_SET(addr-apScript);
*(addr) = value;
}
static int32_t C_GetNextGameArrayName(void) static int32_t C_GetNextGameArrayName(void)
{ {
C_GetNextLabelName(); C_GetNextLabelName();
@ -1665,8 +1685,7 @@ static int32_t C_GetNextGameArrayName(void)
return -1; return -1;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(i);
*g_scriptPtr++ = i;
return i; return i;
} }
@ -1717,13 +1736,10 @@ static int32_t C_GetNextKeyword(void) //Returns its code #
if (EDUKE32_PREDICT_TRUE((i = hash_find(&h_keywords,tempbuf)) >= 0)) if (EDUKE32_PREDICT_TRUE((i = hash_find(&h_keywords,tempbuf)) >= 0))
{ {
if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP) if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP)
*g_scriptPtr = i + (IFELSE_MAGIC<<12); scriptWriteValue(i + (IFELSE_MAGIC<<12));
else *g_scriptPtr = i + (g_lineNumber<<12); else scriptWriteValue(i + (g_lineNumber<<12));
BITPTR_CLEAR(g_scriptPtr-apScript);
textptr += l; textptr += l;
g_scriptPtr++;
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug) if (!(g_errorCnt || g_warningCnt) && g_scriptDebug)
initprintf("%s:%d: debug: keyword `%s'.\n", g_scriptFileName, g_lineNumber, tempbuf); initprintf("%s:%d: debug: keyword `%s'.\n", g_scriptFileName, g_lineNumber, tempbuf);
return i; return i;
@ -1799,21 +1815,15 @@ static void C_GetNextVarType(int32_t type)
if (!type && !g_labelsOnly && (isdigit(*textptr) || ((*textptr == '-') && (isdigit(*(textptr+1)))))) if (!type && !g_labelsOnly && (isdigit(*textptr) || ((*textptr == '-') && (isdigit(*(textptr+1))))))
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(GV_FLAG_CONSTANT);
*g_scriptPtr++ = GV_FLAG_CONSTANT;
if (tolower(textptr[1])=='x') // hex constants if (tolower(textptr[1])=='x') // hex constants
*g_scriptPtr = parse_hex_constant(textptr+2); scriptWriteValue(parse_hex_constant(textptr+2));
else else
*g_scriptPtr = parse_decimal_number(); scriptWriteValue(parse_decimal_number());
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug) if (!(g_errorCnt || g_warningCnt) && g_scriptDebug)
initprintf("%s:%d: debug: constant %ld in place of gamevar.\n", initprintf("%s:%d: debug: constant %ld in place of gamevar.\n", g_scriptFileName, g_lineNumber, (long)*(g_scriptPtr-1));
g_scriptFileName,g_lineNumber,(long)*g_scriptPtr);
BITPTR_CLEAR(g_scriptPtr-apScript);
g_scriptPtr++;
#if 1 #if 1
while (!ispecial(*textptr) && *textptr != ']') textptr++; while (!ispecial(*textptr) && *textptr != ']') textptr++;
#else #else
@ -1872,8 +1882,7 @@ static void C_GetNextVarType(int32_t type)
flags |= GV_FLAG_STRUCT; flags |= GV_FLAG_STRUCT;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(id|flags);
*g_scriptPtr++=(id|flags);
if ((flags & GV_FLAG_STRUCT) && id - g_structVarIDs == STRUCT_USERDEF) if ((flags & GV_FLAG_STRUCT) && id - g_structVarIDs == STRUCT_USERDEF)
{ {
@ -1886,15 +1895,13 @@ static void C_GetNextVarType(int32_t type)
textptr++; textptr++;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0); // help out the VM by inserting a dummy index
*g_scriptPtr++ = 0; // help out the VM by inserting a dummy index
} }
else else
{ {
if (*textptr == ']') if (*textptr == ']')
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(g_thisActorVarID);
*g_scriptPtr++ = g_thisActorVarID;
} }
else else
C_GetNextVarType(0); C_GetNextVarType(0);
@ -1967,14 +1974,13 @@ static void C_GetNextVarType(int32_t type)
return; return;
} }
BITPTR_CLEAR(g_scriptPtr-apScript);
switch (id - g_structVarIDs) switch (id - g_structVarIDs)
{ {
case STRUCT_SPRITE: case STRUCT_SPRITE:
{ {
auto const &label = ActorLabels[labelNum]; auto const &label = ActorLabels[labelNum];
*g_scriptPtr++ = label.lId;
scriptWriteValue(label.lId);
Bassert((*varptr & (MAXGAMEVARS-1)) == g_structVarIDs + STRUCT_SPRITE); Bassert((*varptr & (MAXGAMEVARS-1)) == g_structVarIDs + STRUCT_SPRITE);
@ -1993,42 +1999,42 @@ static void C_GetNextVarType(int32_t type)
break; break;
case STRUCT_SECTOR: case STRUCT_SECTOR:
*g_scriptPtr++=SectorLabels[labelNum].lId; scriptWriteValue(SectorLabels[labelNum].lId);
break; break;
case STRUCT_WALL: case STRUCT_WALL:
*g_scriptPtr++=WallLabels[labelNum].lId; scriptWriteValue(WallLabels[labelNum].lId);
break; break;
case STRUCT_PLAYER: case STRUCT_PLAYER:
*g_scriptPtr++=PlayerLabels[labelNum].lId; scriptWriteValue(PlayerLabels[labelNum].lId);
if (PlayerLabels[labelNum].flags & LABEL_HASPARM2) if (PlayerLabels[labelNum].flags & LABEL_HASPARM2)
C_GetNextVarType(0); C_GetNextVarType(0);
break; break;
case STRUCT_ACTORVAR: case STRUCT_ACTORVAR:
case STRUCT_PLAYERVAR: case STRUCT_PLAYERVAR:
*g_scriptPtr++=labelNum; scriptWriteValue(labelNum);
break; break;
case STRUCT_TSPR: case STRUCT_TSPR:
*g_scriptPtr++=TsprLabels[labelNum].lId; scriptWriteValue(TsprLabels[labelNum].lId);
break; break;
case STRUCT_PROJECTILE: case STRUCT_PROJECTILE:
case STRUCT_THISPROJECTILE: case STRUCT_THISPROJECTILE:
*g_scriptPtr++=ProjectileLabels[labelNum].lId; scriptWriteValue(ProjectileLabels[labelNum].lId);
break; break;
case STRUCT_USERDEF: case STRUCT_USERDEF:
*g_scriptPtr++=UserdefsLabels[labelNum].lId; scriptWriteValue(UserdefsLabels[labelNum].lId);
if (UserdefsLabels[labelNum].flags & LABEL_HASPARM2) if (UserdefsLabels[labelNum].flags & LABEL_HASPARM2)
C_GetNextVarType(0); C_GetNextVarType(0);
break; break;
case STRUCT_INPUT: case STRUCT_INPUT:
*g_scriptPtr++=InputLabels[labelNum].lId; scriptWriteValue(InputLabels[labelNum].lId);
break; break;
case STRUCT_TILEDATA: case STRUCT_TILEDATA:
*g_scriptPtr++=TileDataLabels[labelNum].lId; scriptWriteValue(TileDataLabels[labelNum].lId);
break; break;
case STRUCT_PALDATA: case STRUCT_PALDATA:
*g_scriptPtr++=PalDataLabels[labelNum].lId; scriptWriteValue(PalDataLabels[labelNum].lId);
break; break;
} }
} }
@ -2048,10 +2054,9 @@ static void C_GetNextVarType(int32_t type)
{ {
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug) if (!(g_errorCnt || g_warningCnt) && g_scriptDebug)
initprintf("%s:%d: debug: label `%s' in place of gamevar.\n",g_scriptFileName,g_lineNumber,label+(id<<6)); initprintf("%s:%d: debug: label `%s' in place of gamevar.\n",g_scriptFileName,g_lineNumber,label+(id<<6));
BITPTR_CLEAR(g_scriptPtr-apScript);
*g_scriptPtr++ = GV_FLAG_CONSTANT; scriptWriteValue(GV_FLAG_CONSTANT);
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(labelcode[id]);
*g_scriptPtr++ = labelcode[id];
return; return;
} }
} }
@ -2077,8 +2082,7 @@ static void C_GetNextVarType(int32_t type)
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1) if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1)
initprintf("%s:%d: debug: gamevar `%s'.\n",g_scriptFileName,g_lineNumber,LAST_LABEL); initprintf("%s:%d: debug: gamevar `%s'.\n",g_scriptFileName,g_lineNumber,LAST_LABEL);
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(id|flags);
*g_scriptPtr++=(id|flags);
} }
#define C_GetNextVar() C_GetNextVarType(0) #define C_GetNextVar() C_GetNextVarType(0)
@ -2134,15 +2138,13 @@ static int32_t C_GetNextValue(int32_t type)
Bfree(gl); Bfree(gl);
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(labelcode[i]);
*(g_scriptPtr++) = labelcode[i];
textptr += l; textptr += l;
return labeltype[i]; return labeltype[i];
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*(g_scriptPtr++) = 0;
textptr += l; textptr += l;
char *el = C_GetLabelType(type); char *el = C_GetLabelType(type);
char *gl = C_GetLabelType(labeltype[i]); char *gl = C_GetLabelType(labeltype[i]);
@ -2158,9 +2160,7 @@ static int32_t C_GetNextValue(int32_t type)
{ {
C_ReportError(ERROR_PARAMUNDEFINED); C_ReportError(ERROR_PARAMUNDEFINED);
g_errorCnt++; g_errorCnt++;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*g_scriptPtr = 0;
g_scriptPtr++;
textptr+=l; textptr+=l;
if (!l) textptr++; if (!l) textptr++;
return -1; // error! return -1; // error!
@ -2187,18 +2187,13 @@ static int32_t C_GetNextValue(int32_t type)
} }
while (i > 0); while (i > 0);
BITPTR_CLEAR(g_scriptPtr-apScript);
if (textptr[0] == '0' && tolower(textptr[1])=='x') if (textptr[0] == '0' && tolower(textptr[1])=='x')
*g_scriptPtr = parse_hex_constant(textptr+2); scriptWriteValue(parse_hex_constant(textptr+2));
else else
*g_scriptPtr = parse_decimal_number(); scriptWriteValue(parse_decimal_number());
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1) if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1)
initprintf("%s:%d: debug: constant %ld.\n", initprintf("%s:%d: debug: constant %ld.\n", g_scriptFileName, g_lineNumber, (long)*(g_scriptPtr-1));
g_scriptFileName,g_lineNumber,(long)*g_scriptPtr);
g_scriptPtr++;
textptr += l; textptr += l;
@ -2220,8 +2215,7 @@ static int32_t C_GetStructureIndexes(int32_t const labelsonly, hashtable_t const
if (*textptr == ']') if (*textptr == ']')
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(g_thisActorVarID);
*g_scriptPtr++ = g_thisActorVarID;
} }
else else
{ {
@ -2905,8 +2899,7 @@ static inline void C_BitOrNextValue(int32_t *valptr)
static inline void C_FinishBitOr(int32_t value) static inline void C_FinishBitOr(int32_t value)
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(value);
*g_scriptPtr++ = value;
} }
static void C_FillEventBreakStackWithJump(intptr_t *breakPtr, intptr_t destination) static void C_FillEventBreakStackWithJump(intptr_t *breakPtr, intptr_t destination)
@ -2915,8 +2908,7 @@ static void C_FillEventBreakStackWithJump(intptr_t *breakPtr, intptr_t destinati
{ {
breakPtr = apScript + (intptr_t)breakPtr; breakPtr = apScript + (intptr_t)breakPtr;
intptr_t const tempPtr = *breakPtr; intptr_t const tempPtr = *breakPtr;
BITPTR_CLEAR(breakPtr-apScript); scriptWriteAtOffset(destination, breakPtr);
*breakPtr = destination;
breakPtr = (intptr_t *)tempPtr; breakPtr = (intptr_t *)tempPtr;
} }
} }
@ -3002,19 +2994,15 @@ DO_DEFSTATE:
initprintf("%s:%d: warning: expected state, found %s.\n", g_scriptFileName, g_lineNumber, gl); initprintf("%s:%d: warning: expected state, found %s.\n", g_scriptFileName, g_lineNumber, gl);
g_warningCnt++; g_warningCnt++;
Bfree(gl); Bfree(gl);
*(g_scriptPtr-1) = CON_NULLOP; // get rid of the state, leaving a nullop to satisfy if conditions scriptWriteAtOffset(CON_NULLOP, g_scriptPtr-1); // get rid of the state, leaving a nullop to satisfy if conditions
BITPTR_CLEAR(g_scriptPtr-apScript-1);
continue; // valid label name, but wrong type continue; // valid label name, but wrong type
} }
if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1) if (!(g_errorCnt || g_warningCnt) && g_scriptDebug > 1)
initprintf("%s:%d: debug: state label `%s'.\n", g_scriptFileName, g_lineNumber, label+(j<<6)); initprintf("%s:%d: debug: state label `%s'.\n", g_scriptFileName, g_lineNumber, label+(j<<6));
*g_scriptPtr = (intptr_t) (apScript+labelcode[j]);
// 'state' type labels are always script addresses, as far as I can see // 'state' type labels are always script addresses, as far as I can see
BITPTR_SET(g_scriptPtr-apScript); scriptWritePointer((intptr_t)(apScript+labelcode[j]), g_scriptPtr++);
g_scriptPtr++;
continue; continue;
case CON_ENDS: case CON_ENDS:
@ -3053,8 +3041,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(ProjectileLabels[labelNum].lId);
*g_scriptPtr++=ProjectileLabels[labelNum].lId;
switch (tw) switch (tw)
{ {
@ -3230,8 +3217,7 @@ DO_DEFSTATE:
while (j>-1) while (j>-1)
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*g_scriptPtr++ = 0;
j--; j--;
} }
continue; continue;
@ -3242,8 +3228,7 @@ DO_DEFSTATE:
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)))
{ {
C_ReportError(-1); C_ReportError(-1);
BITPTR_CLEAR(g_scriptPtr-apScript-1); scriptWriteAtOffset(0, g_scriptPtr-1);
*(g_scriptPtr-1) = 0;
initprintf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,g_lineNumber); initprintf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,g_lineNumber);
g_warningCnt++; g_warningCnt++;
} }
@ -3293,9 +3278,7 @@ DO_DEFSTATE:
for (k=j; k>=0; k--) for (k=j; k>=0; k--)
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*g_scriptPtr = 0;
g_scriptPtr++;
} }
} }
continue; continue;
@ -3419,8 +3402,7 @@ DO_DEFSTATE:
(*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)))
{ {
C_ReportError(-1); C_ReportError(-1);
BITPTR_CLEAR(g_scriptPtr-apScript-1); scriptWriteAtOffset(0, g_scriptPtr-1);
*(g_scriptPtr-1) = 0;
initprintf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,g_lineNumber); initprintf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,g_lineNumber);
g_warningCnt++; g_warningCnt++;
} }
@ -3440,9 +3422,7 @@ DO_DEFSTATE:
for (k=j; k<3; k++) for (k=j; k<3; k++)
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*g_scriptPtr = 0;
g_scriptPtr++;
} }
} }
continue; continue;
@ -3493,8 +3473,7 @@ DO_DEFSTATE:
} }
for (k=j; k>=0; k--) for (k=j; k>=0; k--)
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*(g_scriptPtr++) = 0;
} }
} }
continue; continue;
@ -3576,8 +3555,7 @@ DO_DEFSTATE:
for (j=0; j<4; j++) for (j=0; j<4; j++)
{ {
BITPTR_CLEAR(g_parsingActorPtr+j); scriptWriteAtOffset(0, apScript+g_parsingActorPtr+j);
*((apScript+j)+g_parsingActorPtr) = 0;
if (j == 3) if (j == 3)
{ {
j = 0; j = 0;
@ -3593,8 +3571,7 @@ DO_DEFSTATE:
{ {
for (i=4-j; i; i--) for (i=4-j; i; i--)
{ {
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0);
*(g_scriptPtr++) = 0;
} }
break; break;
} }
@ -3612,17 +3589,17 @@ DO_DEFSTATE:
if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)))
{ {
C_ReportError(-1); C_ReportError(-1);
BITPTR_CLEAR(g_scriptPtr-apScript-1); scriptWriteAtOffset(0, g_scriptPtr-1);
*(g_scriptPtr-1) = 0;
initprintf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,g_lineNumber); initprintf("%s:%d: warning: expected a move, found a constant.\n",g_scriptFileName,g_lineNumber);
g_warningCnt++; g_warningCnt++;
} }
break; break;
} }
if (*(g_scriptPtr-1) >= (intptr_t)&apScript[0] && *(g_scriptPtr-1) < (intptr_t)&apScript[g_scriptSize]) if (*(g_scriptPtr-1) >= (intptr_t)&apScript[0] && *(g_scriptPtr-1) < (intptr_t)&apScript[g_scriptSize])
BITPTR_SET(g_parsingActorPtr+j); scriptWritePointer(*(g_scriptPtr-1), apScript + g_parsingActorPtr + j);
else BITPTR_CLEAR(g_parsingActorPtr+j); else
*((apScript+j)+g_parsingActorPtr) = *(g_scriptPtr-1); scriptWriteAtOffset(*(g_scriptPtr-1), apScript + g_parsingActorPtr + j);
} }
} }
g_checkingIfElse = 0; g_checkingIfElse = 0;
@ -3674,14 +3651,11 @@ DO_DEFSTATE:
} }
else // if (tw == CON_APPENDEVENT) else // if (tw == CON_APPENDEVENT)
{ {
intptr_t *previous_event_end = apScript + apScriptGameEventEnd[j]; auto previous_event_end = apScript + apScriptGameEventEnd[j];
BITPTR_CLEAR(previous_event_end-apScript); scriptWriteAtOffset(CON_JUMP | (g_lineNumber << 12), previous_event_end++);
*(previous_event_end++) = CON_JUMP | (g_lineNumber << 12); scriptWriteAtOffset(GV_FLAG_CONSTANT, previous_event_end++);
BITPTR_CLEAR(previous_event_end-apScript);
*(previous_event_end++) = GV_FLAG_CONSTANT;
C_FillEventBreakStackWithJump((intptr_t *)*previous_event_end, g_parsingEventPtr); C_FillEventBreakStackWithJump((intptr_t *)*previous_event_end, g_parsingEventPtr);
BITPTR_CLEAR(previous_event_end-apScript); scriptWriteAtOffset(g_parsingEventPtr, previous_event_end++);
*(previous_event_end++) = g_parsingEventPtr;
} }
g_checkingIfElse = 0; g_checkingIfElse = 0;
@ -3696,7 +3670,7 @@ DO_DEFSTATE:
while (C_GetKeyword() == -1 && j < 32) while (C_GetKeyword() == -1 && j < 32)
C_GetNextVar(), j++; C_GetNextVar(), j++;
*g_scriptPtr++ = CON_NULLOP + (g_lineNumber<<12); scriptWriteValue(CON_NULLOP + (g_lineNumber<<12));
continue; continue;
case CON_CSTAT: case CON_CSTAT:
@ -3818,8 +3792,7 @@ DO_DEFSTATE:
continue; continue;
intptr_t *tempscrptr = (intptr_t *) apScript+offset; intptr_t *tempscrptr = (intptr_t *) apScript+offset;
*tempscrptr = (intptr_t) g_scriptPtr; scriptWritePointer((intptr_t)g_scriptPtr, tempscrptr);
BITPTR_SET(tempscrptr-apScript);
continue; continue;
} }
@ -3832,8 +3805,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(SectorLabels[labelNum].lId);
*g_scriptPtr++=SectorLabels[labelNum].lId;
C_GetNextVarType((tw == CON_GETSECTOR) ? GAMEVAR_READONLY : 0); C_GetNextVarType((tw == CON_GETSECTOR) ? GAMEVAR_READONLY : 0);
continue; continue;
@ -3872,8 +3844,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(WallLabels[labelNum].lId);
*g_scriptPtr++=WallLabels[labelNum].lId;
C_GetNextVarType((tw == CON_GETWALL) ? GAMEVAR_READONLY : 0); C_GetNextVarType((tw == CON_GETWALL) ? GAMEVAR_READONLY : 0);
continue; continue;
@ -3887,8 +3858,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(PlayerLabels[labelNum].lId);
*g_scriptPtr++=PlayerLabels[labelNum].lId;
if (PlayerLabels[labelNum].flags & LABEL_HASPARM2) if (PlayerLabels[labelNum].flags & LABEL_HASPARM2)
C_GetNextVar(); C_GetNextVar();
@ -3905,8 +3875,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(InputLabels[labelNum].lId);
*g_scriptPtr++=InputLabels[labelNum].lId;
C_GetNextVarType(tw == CON_GETINPUT ? GAMEVAR_READONLY : 0); C_GetNextVarType(tw == CON_GETINPUT ? GAMEVAR_READONLY : 0);
continue; continue;
@ -3920,8 +3889,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr - apScript); scriptWriteValue(TileDataLabels[labelNum].lId);
*g_scriptPtr++ = TileDataLabels[labelNum].lId;
C_GetNextVarType((tw == CON_GETTILEDATA) ? GAMEVAR_READONLY : 0); C_GetNextVarType((tw == CON_GETTILEDATA) ? GAMEVAR_READONLY : 0);
continue; continue;
@ -3956,8 +3924,7 @@ DO_DEFSTATE:
C_ReportError(ERROR_NOTAMEMBER); C_ReportError(ERROR_NOTAMEMBER);
continue; continue;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(labelNum);
*g_scriptPtr++=labelNum;
if (UserdefsLabels[labelNum].flags & LABEL_HASPARM2) if (UserdefsLabels[labelNum].flags & LABEL_HASPARM2)
C_GetNextVar(); C_GetNextVar();
@ -4045,8 +4012,7 @@ DO_DEFSTATE:
break; break;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(i); // the ID of the DEF (offset into array...)
*g_scriptPtr++=i; // the ID of the DEF (offset into array...)
switch (tw) switch (tw)
{ {
@ -4083,8 +4049,7 @@ DO_DEFSTATE:
*ins = CON_SETSPRITESTRUCT; *ins = CON_SETSPRITESTRUCT;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(label.lId);
*g_scriptPtr++=label.lId;
if (label.flags & LABEL_HASPARM2) if (label.flags & LABEL_HASPARM2)
C_GetNextVar(); C_GetNextVar();
@ -4115,8 +4080,7 @@ DO_DEFSTATE:
*ins = CON_GETSPRITESTRUCT; *ins = CON_GETSPRITESTRUCT;
} }
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(label.lId);
*g_scriptPtr++=label.lId;
if (label.flags & LABEL_HASPARM2) if (label.flags & LABEL_HASPARM2)
C_GetNextVar(); C_GetNextVar();
@ -4141,8 +4105,7 @@ DO_DEFSTATE:
if (labelNum == -1) if (labelNum == -1)
continue; continue;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(TsprLabels[labelNum].lId);
*g_scriptPtr++=TsprLabels[labelNum].lId;
C_GetNextVarType((tw == CON_GETTSPR) ? GAMEVAR_READONLY : 0); C_GetNextVarType((tw == CON_GETTSPR) ? GAMEVAR_READONLY : 0);
continue; continue;
@ -4360,7 +4323,7 @@ DO_DEFSTATE:
if (i == j) if (i == j)
continue; continue;
*g_scriptPtr++ = CON_INV+(g_lineNumber<<12); scriptWriteValue(CON_INV+(g_lineNumber<<12));
textptr = tptr; textptr = tptr;
C_GetNextVarType(GAMEVAR_READONLY); C_GetNextVarType(GAMEVAR_READONLY);
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
@ -4568,7 +4531,7 @@ DO_DEFSTATE:
case CON_ACTIVATE: case CON_ACTIVATE:
*(g_scriptPtr-1) = CON_OPERATEACTIVATORS; *(g_scriptPtr-1) = CON_OPERATEACTIVATORS;
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
*g_scriptPtr++ = 0; scriptWriteValue(0);
continue; continue;
case CON_GETFLORZOFSLOPE: case CON_GETFLORZOFSLOPE:
@ -4620,7 +4583,7 @@ DO_DEFSTATE:
g_scriptPtr--; g_scriptPtr--;
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
j = *(g_scriptPtr - 1); j = *(g_scriptPtr-1);
if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXTILES)) if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXTILES))
{ {
@ -4645,9 +4608,9 @@ DO_DEFSTATE:
g_scriptPtr--; g_scriptPtr--;
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
i = *(g_scriptPtr - 1); i = *(g_scriptPtr-1);
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
j = *(g_scriptPtr - 1); j = *(g_scriptPtr-1);
if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXTILES || (unsigned)j >= MAXTILES)) if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXTILES || (unsigned)j >= MAXTILES))
{ {
@ -4786,8 +4749,7 @@ DO_DEFSTATE:
continue; continue;
intptr_t *tempscrptr = (intptr_t *)apScript+offset; intptr_t *tempscrptr = (intptr_t *)apScript+offset;
*tempscrptr = (intptr_t) g_scriptPtr; scriptWritePointer((intptr_t)g_scriptPtr, tempscrptr);
BITPTR_SET(tempscrptr-apScript);
if (tw != CON_WHILEVARVARN) if (tw != CON_WHILEVARVARN)
{ {
@ -4842,8 +4804,7 @@ DO_DEFSTATE:
continue; continue;
tempscrptr = (intptr_t *)apScript+offset; tempscrptr = (intptr_t *)apScript+offset;
*tempscrptr = (intptr_t) g_scriptPtr; scriptWritePointer((intptr_t)g_scriptPtr, tempscrptr);
BITPTR_SET(tempscrptr-apScript);
if (tw != CON_WHILEVARN && tw != CON_WHILEVARL) if (tw != CON_WHILEVARN && tw != CON_WHILEVARL)
{ {
@ -4869,7 +4830,7 @@ DO_DEFSTATE:
C_CUSTOMERROR("unknown iteration type `%s'.", LAST_LABEL); C_CUSTOMERROR("unknown iteration type `%s'.", LAST_LABEL);
return 1; return 1;
} }
*g_scriptPtr++ = iterType; scriptWriteValue(iterType);
if (iterType >= ITER_SPRITESOFSECTOR) if (iterType >= ITER_SPRITESOFSECTOR)
C_GetNextVar(); C_GetNextVar();
@ -4879,8 +4840,9 @@ DO_DEFSTATE:
C_ParseCommand(0); C_ParseCommand(0);
intptr_t *tscrptr = (intptr_t *) apScript+offset; // write relative offset
*tscrptr = (g_scriptPtr-apScript)-offset; // relative offset auto const tscrptr = (intptr_t *) apScript+offset;
scriptWriteAtOffset((g_scriptPtr-apScript)-offset, tscrptr);
continue; continue;
} }
@ -5044,19 +5006,15 @@ DO_DEFSTATE:
intptr_t const tempoffset = (unsigned)(g_scriptPtr-apScript); intptr_t const tempoffset = (unsigned)(g_scriptPtr-apScript);
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0); // leave spot for end location (for after processing)
*g_scriptPtr++=0; // leave spot for end location (for after processing) scriptWriteValue(0); // count of case statements
BITPTR_CLEAR(g_scriptPtr-apScript);
*g_scriptPtr++=0; // count of case statements
auto const backupCaseScriptPtr = g_caseScriptPtr; auto const backupCaseScriptPtr = g_caseScriptPtr;
g_caseScriptPtr=g_scriptPtr; // the first case's pointer. g_caseScriptPtr=g_scriptPtr; // the first case's pointer.
int const backupNumCases = g_numCases; int const backupNumCases = g_numCases;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0); // leave spot for 'default' location (null if none)
*g_scriptPtr++=0; // leave spot for 'default' location (null if none)
// temptextptr=textptr; // temptextptr=textptr;
// probably does not allow nesting... // probably does not allow nesting...
@ -5077,8 +5035,8 @@ DO_DEFSTATE:
if (tempscrptr) if (tempscrptr)
{ {
tempscrptr[1]=(intptr_t)j; // save count of cases // save count of cases
BITPTR_CLEAR(&tempscrptr[1]-apScript); scriptWriteAtOffset(j, &tempscrptr[1]);
} }
else else
{ {
@ -5089,10 +5047,9 @@ DO_DEFSTATE:
while (j--) while (j--)
{ {
// leave room for statements // leave room for statements
BITPTR_CLEAR(g_scriptPtr-apScript);
*g_scriptPtr++=0; // value check scriptWriteValue(0); // value check
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(0); // code offset
*g_scriptPtr++=0; // code offset
C_SkipComments(); C_SkipComments();
} }
@ -5133,8 +5090,9 @@ DO_DEFSTATE:
} }
} }
// for (j=3;j<3+tempscrptr[1]*2;j+=2)initprintf("%5d %8x\n",tempscrptr[j],tempscrptr[j+1]); // for (j=3;j<3+tempscrptr[1]*2;j+=2)initprintf("%5d %8x\n",tempscrptr[j],tempscrptr[j+1]);
tempscrptr[0]= (intptr_t)g_scriptPtr - (intptr_t)&apScript[0]; // save 'end' location
BITPTR_CLEAR(tempscrptr-apScript); // save 'end' location
scriptWriteAtOffset((intptr_t)g_scriptPtr - (intptr_t)&apScript[0], tempscrptr);
} }
else else
{ {
@ -5358,8 +5316,7 @@ repeatcase:
continue; continue;
tempscrptr = (intptr_t *)apScript+offset; tempscrptr = (intptr_t *)apScript+offset;
*tempscrptr = (intptr_t) g_scriptPtr; scriptWritePointer((intptr_t)g_scriptPtr, tempscrptr);
BITPTR_SET(tempscrptr-apScript);
j = C_GetKeyword(); j = C_GetKeyword();
@ -5411,8 +5368,7 @@ repeatcase:
continue; continue;
tempscrptr = (intptr_t *)apScript+offset; tempscrptr = (intptr_t *)apScript+offset;
*tempscrptr = (intptr_t) g_scriptPtr; scriptWritePointer((intptr_t)g_scriptPtr, tempscrptr);
BITPTR_SET(tempscrptr-apScript);
j = C_GetKeyword(); j = C_GetKeyword();
@ -5983,9 +5939,7 @@ repeatcase:
else else
{ {
*(apXStrings[g_numXStrings]+i) = '\0'; *(apXStrings[g_numXStrings]+i) = '\0';
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(g_numXStrings++);
*g_scriptPtr++=g_numXStrings;
g_numXStrings++;
} }
continue; continue;
@ -6142,14 +6096,10 @@ repeatcase:
if (previous_event) if (previous_event)
{ {
g_scriptPtr--; g_scriptPtr--;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(CON_JUMP | (g_lineNumber << 12));
*(g_scriptPtr++) = CON_JUMP | (g_lineNumber << 12); scriptWriteValue(GV_FLAG_CONSTANT);
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(previous_event);
*(g_scriptPtr++) = GV_FLAG_CONSTANT; scriptWriteValue(CON_ENDEVENT | (g_lineNumber << 12));
BITPTR_CLEAR(g_scriptPtr-apScript);
*(g_scriptPtr++) = previous_event;
BITPTR_CLEAR(g_scriptPtr-apScript);
*(g_scriptPtr++) = CON_ENDEVENT | (g_lineNumber << 12);
C_FillEventBreakStackWithJump((intptr_t *)g_parsingEventBreakPtr, previous_event); C_FillEventBreakStackWithJump((intptr_t *)g_parsingEventBreakPtr, previous_event);
@ -6159,12 +6109,9 @@ repeatcase:
{ {
// pad space for the next potential appendevent // pad space for the next potential appendevent
apScriptGameEventEnd[g_currentEvent] = (g_scriptPtr-1)-apScript; apScriptGameEventEnd[g_currentEvent] = (g_scriptPtr-1)-apScript;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(CON_ENDEVENT | (g_lineNumber << 12));
*(g_scriptPtr++) = CON_ENDEVENT | (g_lineNumber << 12); scriptWriteValue(g_parsingEventBreakPtr);
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(CON_ENDEVENT | (g_lineNumber << 12));
*(g_scriptPtr++) = g_parsingEventBreakPtr;
BITPTR_CLEAR(g_scriptPtr-apScript);
*(g_scriptPtr++) = CON_ENDEVENT | (g_lineNumber << 12);
} }
g_parsingEventBreakPtr = g_parsingEventPtr = g_parsingActorPtr = 0; g_parsingEventBreakPtr = g_parsingEventPtr = g_parsingActorPtr = 0;
@ -6215,13 +6162,10 @@ repeatcase:
else if (g_parsingEventPtr) else if (g_parsingEventPtr)
{ {
g_scriptPtr--; g_scriptPtr--;
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(CON_JUMP | (g_lineNumber << 12));
*(g_scriptPtr++) = CON_JUMP | (g_lineNumber << 12); scriptWriteValue(GV_FLAG_CONSTANT);
BITPTR_CLEAR(g_scriptPtr-apScript); scriptWriteValue(g_parsingEventBreakPtr);
*(g_scriptPtr++) = GV_FLAG_CONSTANT; g_parsingEventBreakPtr = g_scriptPtr-1 - apScript;
BITPTR_CLEAR(g_scriptPtr-apScript);
*g_scriptPtr = g_parsingEventBreakPtr;
g_parsingEventBreakPtr = g_scriptPtr++ - apScript;
} }
continue; continue;
@ -6690,7 +6634,7 @@ void C_Compile(const char *fileName)
while (breakPtr) while (breakPtr)
{ {
breakPtr = apScript + (intptr_t)breakPtr; breakPtr = apScript + (intptr_t)breakPtr;
*(breakPtr-2) = CON_ENDEVENT | (g_lineNumber << 12); scriptWriteAtOffset(CON_ENDEVENT | (g_lineNumber << 12), breakPtr-2);
breakPtr = (intptr_t*)*breakPtr; breakPtr = (intptr_t*)*breakPtr;
} }
} }