- Optimize away PCD_DUP when the preceding instruction is PCD_PUSHBYTE.

- Added NamedScriptWait (PCD_SCRIPTWAITNAMED) and ACS_NamedExecuteWait.

SVN r3755 (trunk)
This commit is contained in:
Randy Heit 2012-07-11 03:59:01 +00:00
parent 43ff84e0a1
commit 72b11c089f
6 changed files with 44 additions and 10 deletions

19
parse.c
View file

@ -94,7 +94,7 @@ static boolean ProcessStatement(statement_t owner);
static void LeadingCompoundStatement(statement_t owner); static void LeadingCompoundStatement(statement_t owner);
static void LeadingVarDeclare(void); static void LeadingVarDeclare(void);
static void LeadingLineSpecial(boolean executewait); static void LeadingLineSpecial(boolean executewait);
static void LeadingFunction(); static void LeadingFunction(boolean executewait);
static void LeadingIdentifier(void); static void LeadingIdentifier(void);
static void BuildPrintString(void); static void BuildPrintString(void);
static void ActionOnCharRange(boolean write); static void ActionOnCharRange(boolean write);
@ -1310,7 +1310,7 @@ static boolean ProcessStatement(statement_t owner)
} }
else else
{ {
LeadingFunction(); LeadingFunction(NO);
} }
break; break;
case TK_ACSEXECUTEWAIT: case TK_ACSEXECUTEWAIT:
@ -1318,6 +1318,11 @@ static boolean ProcessStatement(statement_t owner)
tk_SpecialValue = 80; tk_SpecialValue = 80;
LeadingLineSpecial(YES); LeadingLineSpecial(YES);
break; break;
case TK_ACSNAMEDEXECUTEWAIT:
tk_SpecialArgCount = 1 | (5<<16);
tk_SpecialValue = -39;
LeadingFunction(YES);
break;
case TK_RESTART: case TK_RESTART:
LeadingRestart(); LeadingRestart();
break; break;
@ -1684,7 +1689,7 @@ static void LeadingLineSpecial(boolean executewait)
// //
//========================================================================== //==========================================================================
static void LeadingFunction() static void LeadingFunction(boolean executewait)
{ {
int i; int i;
int argCount; int argCount;
@ -1718,6 +1723,10 @@ static void LeadingFunction()
} }
TK_NextToken(); TK_NextToken();
EvalExpression(); EvalExpression();
if (i == 0 && executewait)
{
PC_AppendCmd(PCD_DUP);
}
if(i < argCountMax) if(i < argCountMax)
{ {
i++; i++;
@ -1750,6 +1759,10 @@ static void LeadingFunction()
PC_AppendWord((U_WORD)specialValue); PC_AppendWord((U_WORD)specialValue);
} }
PC_AppendCmd(PCD_DROP); PC_AppendCmd(PCD_DROP);
if(executewait)
{
PC_AppendCmd(PCD_SCRIPTWAITNAMED);
}
TK_NextToken(); TK_NextToken();
} }

27
pcode.c
View file

@ -465,13 +465,16 @@ static char *PCDNames[PCODE_COMMAND_COUNT] =
"PCD_PRINTBINARY", "PCD_PRINTBINARY",
"PCD_PRINTHEX", "PCD_PRINTHEX",
"PCD_CALLFUNC", "PCD_CALLFUNC",
"PCD_SAVESTRING", // [FDARI] "PCD_SAVESTRING", // [FDARI]
"PCD_PRINTMAPCHRANGE", // [FDARI] output range "PCD_PRINTMAPCHRANGE", // [FDARI] output range
"PCD_PRINTWORLDCHRANGE", "PCD_PRINTWORLDCHRANGE",
"PCD_PRINTGLOBALCHRANGE", "PCD_PRINTGLOBALCHRANGE",
"PCD_STRCPYTOMAPCHRANGE", // [FDARI] input range "PCD_STRCPYTOMAPCHRANGE", // [FDARI] input range
"PCD_STRCPYTOWORLDCHRANGE", "PCD_STRCPYTOWORLDCHRANGE",
"PCD_STRCPYTOGLOBALCHRANGE", "PCD_STRCPYTOGLOBALCHRANGE",
"PCD_PUSHFUNCTION", // from Eternity
"PCD_CALLSTACK", // from Eternity
"PCD_SCRIPTWAITNAMED",
}; };
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
@ -1092,6 +1095,7 @@ void PC_AppendString(char *string)
void PC_AppendCmd(pcd_t command) void PC_AppendCmd(pcd_t command)
{ {
boolean dupbyte = NO;
if (ImportMode != IMPORT_Importing) if (ImportMode != IMPORT_Importing)
{ {
pc_LastAppendedCommand = command; pc_LastAppendedCommand = command;
@ -1105,7 +1109,14 @@ void PC_AppendCmd(pcd_t command)
else else
{ {
U_BYTE cmd; U_BYTE cmd;
if (command != PCD_PUSHBYTE && PushByteAddr) if (command == PCD_DUP && PushByteAddr)
{ // If the last instruction was PCD_PUSHBYTE, convert this PCD_DUP to a
// duplicate PCD_PUSHBYTE, so it can be merged into a single instruction below.
command = PCD_PUSHBYTE;
dupbyte = YES;
MS_Message(MSG_DEBUG, "AC> PCD_DUP changed to PCD_PUSHBYTE\n");
}
else if (command != PCD_PUSHBYTE && PushByteAddr)
{ // Maybe shrink a PCD_PUSHBYTE sequence into PCD_PUSHBYTES { // Maybe shrink a PCD_PUSHBYTE sequence into PCD_PUSHBYTES
int runlen = (pc_Address - PushByteAddr) / 2; int runlen = (pc_Address - PushByteAddr) / 2;
int i; int i;
@ -1120,7 +1131,7 @@ void PC_AppendCmd(pcd_t command)
pc_Buffer[PushByteAddr+1] = runlen; pc_Buffer[PushByteAddr+1] = runlen;
pc_Address = PushByteAddr + runlen + 2; pc_Address = PushByteAddr + runlen + 2;
pc_BufferPtr = pc_Buffer + pc_Address; pc_BufferPtr = pc_Buffer + pc_Address;
MS_Message (MSG_DEBUG, "AC> Last %d PCD_PUSHBYTEs changed to #%d:PCD_PUSHBYTES\n", MS_Message(MSG_DEBUG, "AC> Last %d PCD_PUSHBYTEs changed to #%d:PCD_PUSHBYTES\n",
runlen, PCD_PUSHBYTES); runlen, PCD_PUSHBYTES);
} }
else if (runlen > 1) else if (runlen > 1)
@ -1132,12 +1143,12 @@ void PC_AppendCmd(pcd_t command)
} }
pc_Address = PushByteAddr + runlen + 1; pc_Address = PushByteAddr + runlen + 1;
pc_BufferPtr = pc_Buffer + pc_Address; pc_BufferPtr = pc_Buffer + pc_Address;
MS_Message (MSG_DEBUG, "AC> Last %d PCD_PUSHBYTEs changed to #%d:PCD_PUSH%dBYTES\n", MS_Message(MSG_DEBUG, "AC> Last %d PCD_PUSHBYTEs changed to #%d:PCD_PUSH%dBYTES\n",
runlen, PCD_PUSH2BYTES+runlen-2, runlen); runlen, PCD_PUSH2BYTES+runlen-2, runlen);
} }
PushByteAddr = 0; PushByteAddr = 0;
} }
else if (command == PCD_PUSHBYTE && PushByteAddr == 0) else if(command == PCD_PUSHBYTE && PushByteAddr == 0)
{ // Remember the first PCD_PUSHBYTE, in case there are more { // Remember the first PCD_PUSHBYTE, in case there are more
PushByteAddr = pc_Address; PushByteAddr = pc_Address;
} }
@ -1159,6 +1170,10 @@ void PC_AppendCmd(pcd_t command)
cmd = (command - (256-16)) & 255; cmd = (command - (256-16)) & 255;
Append(&cmd, sizeof(U_BYTE)); Append(&cmd, sizeof(U_BYTE));
} }
if (dupbyte)
{
PC_AppendByte(pc_Buffer[pc_Address-2]);
}
} }
} }
} }

View file

@ -421,6 +421,9 @@ typedef enum
PCD_STRCPYTOMAPCHRANGE, // [FDARI] input range PCD_STRCPYTOMAPCHRANGE, // [FDARI] input range
PCD_STRCPYTOWORLDCHRANGE, PCD_STRCPYTOWORLDCHRANGE,
PCD_STRCPYTOGLOBALCHRANGE, PCD_STRCPYTOGLOBALCHRANGE,
PCD_PUSHFUNCTION, // from Eternity
PCD_CALLSTACK, // from Eternity
PCD_SCRIPTWAITNAMED,
PCODE_COMMAND_COUNT PCODE_COMMAND_COUNT
} pcd_t; } pcd_t;

View file

@ -57,7 +57,8 @@ static internFuncDef_t InternalFunctions[] =
{ {
{ "tagwait", PCD_TAGWAITDIRECT, PCD_TAGWAIT, 1, 0, 0, NO, YES }, { "tagwait", PCD_TAGWAITDIRECT, PCD_TAGWAIT, 1, 0, 0, NO, YES },
{ "polywait", PCD_POLYWAITDIRECT, PCD_POLYWAIT, 1, 0, 0, NO, YES }, { "polywait", PCD_POLYWAITDIRECT, PCD_POLYWAIT, 1, 0, 0, NO, YES },
{ "scriptwait", PCD_SCRIPTWAITDIRECT, PCD_SCRIPTWAIT, 1, 0, 0, NO, YES}, { "scriptwait", PCD_SCRIPTWAITDIRECT, PCD_SCRIPTWAIT, 1, 0, 0, NO, YES },
{ "namedscriptwait", PCD_NOP, PCD_SCRIPTWAITNAMED, 1, 0, 0, NO, YES },
{ "delay", PCD_DELAYDIRECT, PCD_DELAY, 1, 0, 0, NO, YES }, { "delay", PCD_DELAYDIRECT, PCD_DELAY, 1, 0, 0, NO, YES },
{ "random", PCD_RANDOMDIRECT, PCD_RANDOM, 2, 0, 0, YES, NO }, { "random", PCD_RANDOMDIRECT, PCD_RANDOM, 2, 0, 0, YES, NO },
{ "thingcount", PCD_THINGCOUNTDIRECT, PCD_THINGCOUNT, 2, 0, 0, YES, NO }, { "thingcount", PCD_THINGCOUNTDIRECT, PCD_THINGCOUNT, 2, 0, 0, YES, NO },

View file

@ -183,6 +183,7 @@ static struct keyword_s
{ "wadauthor", TK_WADAUTHOR }, { "wadauthor", TK_WADAUTHOR },
{ "nowadauthor", TK_NOWADAUTHOR }, { "nowadauthor", TK_NOWADAUTHOR },
{ "acs_executewait", TK_ACSEXECUTEWAIT }, { "acs_executewait", TK_ACSEXECUTEWAIT },
{ "acs_namedexecutewait", TK_ACSNAMEDEXECUTEWAIT },
{ "encryptstrings", TK_ENCRYPTSTRINGS }, { "encryptstrings", TK_ENCRYPTSTRINGS },
{ "import", TK_IMPORT }, { "import", TK_IMPORT },
{ "library", TK_LIBRARY }, { "library", TK_LIBRARY },

View file

@ -113,6 +113,7 @@ typedef enum
TK_WADAUTHOR, // 'wadauthor' TK_WADAUTHOR, // 'wadauthor'
TK_NOWADAUTHOR, // 'nowadauthor' TK_NOWADAUTHOR, // 'nowadauthor'
TK_ACSEXECUTEWAIT, // 'acs_executewait' TK_ACSEXECUTEWAIT, // 'acs_executewait'
TK_ACSNAMEDEXECUTEWAIT,// 'acs_namedexecutewait'
TK_ENCRYPTSTRINGS, // 'encryptstrings' TK_ENCRYPTSTRINGS, // 'encryptstrings'
TK_IMPORT, // 'import' TK_IMPORT, // 'import'
TK_LIBRARY, // 'library' TK_LIBRARY, // 'library'