git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@570 4a71c877-e1ca-e34f-864e-861f7616d084

master
Roman C 2006-08-15 18:38:51 +00:00
parent 6d8b190950
commit a891af6a7a
9 changed files with 832 additions and 91 deletions

View File

@ -176,7 +176,7 @@ UINT HashStringIgnoreCase( char *String );
/* Endianness hacks */
static inline void endian_uword(UWORD *uword) {
static __inline void endian_uword(UWORD *uword) {
#ifdef __BIG_ENDIAN__
UBYTE tmp, *ptr;
@ -187,7 +187,7 @@ static inline void endian_uword(UWORD *uword) {
#endif
}
static inline void endian_sword(SWORD *sword) {
static __inline void endian_sword(SWORD *sword) {
#ifdef __BIG_ENDIAN__
UBYTE tmp, *ptr;
@ -198,7 +198,7 @@ static inline void endian_sword(SWORD *sword) {
#endif
}
static inline void endian_udword(UDWORD *udword) {
static __inline void endian_udword(UDWORD *udword) {
#ifdef __BIG_ENDIAN__
UBYTE tmp, *ptr;
@ -212,7 +212,7 @@ static inline void endian_udword(UDWORD *udword) {
#endif
}
static inline void endian_sdword(SDWORD *sdword) {
static __inline void endian_sdword(SDWORD *sdword) {
#ifdef __BIG_ENDIAN__
UBYTE tmp, *ptr;
@ -226,7 +226,7 @@ static inline void endian_sdword(SDWORD *sdword) {
#endif
}
static inline void endian_fract(FRACT *fract) {
static __inline void endian_fract(FRACT *fract) {
#ifdef __BIG_ENDIAN__
UBYTE tmp, *ptr;

View File

@ -359,7 +359,7 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release,
SCRIPT_CONTEXT **ppsContext)
{
SCRIPT_CONTEXT *psContext;
SDWORD val, storeIndex, type, arrayNum, i, arraySize;
SDWORD val, storeIndex, type, arrayNum, i,j, arraySize;
VAL_CHUNK *psNewChunk, *psNextChunk;
ASSERT((PTRVALID(psCode, sizeof(SCRIPT_CODE)),
@ -368,6 +368,7 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release,
// Get a new context
if (!HEAP_ALLOC(psContHeap, (void*) &psContext))
{
debug(LOG_ERROR,"eventNewContext: HEAP_ALLOC failed");
return FALSE;
}
@ -387,6 +388,66 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release,
arraySize *= psCode->psArrayInfo[arrayNum].elements[i];
}
}
//prepare local variables (initialize, store type)
//-------------------------------
psCode->ppsLocalVarVal = (INTERP_VAL **)MALLOC(sizeof(INTERP_VAL*) * psCode->numEvents); //allocate space for array of local var arrays for each event
debug(LOG_SCRIPT,"allocated space for %d events", psCode->numEvents);
for(i=0;i < psCode->numEvents; i++)
{
if(psCode->numLocalVars[i] > 0) //this event has any local vars declared
{
psCode->ppsLocalVarVal[i] = (INTERP_VAL*)MALLOC(sizeof(INTERP_VAL) * psCode->numLocalVars[i]); //allocate space for local vars array (for the current event)
debug(LOG_SCRIPT,"Event %d has %d local variables", i, psCode->numLocalVars[i]);
for(j=0; j < psCode->numLocalVars[i]; j++)
{
type = psCode->ppsLocalVars[i][j];
psCode->ppsLocalVarVal[i][j].type = type; //store (copy) var type (data used during parsing -> data used during interpreting)
//debug(LOG_SCRIPT,"var %d's type: %d", i, type);
//initialize Strings and integers
if(type == VAL_STRING)
{
debug(LOG_SCRIPT,"eventNewContext: STRING type variables are not implemented");
psCode->ppsLocalVarVal[i][j].v.sval = (char*)MALLOC(255); //TODO: MAXSTRLEN
strcpy(psCode->ppsLocalVarVal[i][j].v.sval,"\0");
}
else
{
psCode->ppsLocalVarVal[i][j].v.ival = 0;
}
//Initialize objects
if (asCreateFuncs != NULL && type < numFuncs && asCreateFuncs[type])
{
if (!asCreateFuncs[type](&(psCode->ppsLocalVarVal[i][j]) ))
{
debug(LOG_ERROR,"eventNewContext: asCreateFuncs failed for local var");
return FALSE;
}
}
//debug(LOG_SCRIPT, "i=%d, j=%d, value=%d",i,j,psCode->ppsLocalVarVal[i][j].v.ival);
}
debug(LOG_SCRIPT,"------");
}
else //this event has no local vars
{
psCode->ppsLocalVarVal[i] = NULL;
}
}
while (val >= 0)
{
if (!HEAP_ALLOC(psValHeap, (void*) &psNewChunk))

View File

@ -202,6 +202,50 @@ BOOL interpInitialise(void)
return TRUE;
}
//reset local vars
BOOL resetLocalVars(SCRIPT_CODE *psCode, UDWORD EventIndex)
{
SDWORD i;
if(EventIndex >= psCode->numEvents)
{
debug(LOG_ERROR, "resetLocalVars: wrong event index: %d", EventIndex);
return FALSE;
}
for(i=0; i < psCode->numLocalVars[EventIndex]; i++)
{
//Initialize main value
if(psCode->ppsLocalVarVal[EventIndex][i].type == VAL_STRING)
{
debug(LOG_ERROR , "resetLocalVars: String type is not implemented");
psCode->ppsLocalVarVal[EventIndex][i].v.sval = (char*)MALLOC(255); //MAXSTRLEN
strcpy(psCode->ppsLocalVarVal[EventIndex][i].v.sval,"\0");
}
else
{
psCode->ppsLocalVarVal[EventIndex][i].v.ival = 0;
}
/* only group (!) must be re-created each time */
//if (psCode->ppsLocalVarVal[EventIndex][i].type == ST_GROUP)
//{
// //DB_INTERP(("resetLocalVars - created\n"));
//
// if (!asCreateFuncs[psCode->ppsLocalVarVal[EventIndex][i].type](&(psCode->ppsLocalVarVal[EventIndex][i]) ))
// {
// debug(LOG_ERROR, "asCreateFuncs failed for local var (re-init)");
// return FALSE;
// }
//}
}
//debug(LOG_SCRIPT, "Reset local vars for event %d", EventIndex);
return TRUE;
}
/* Run a compiled script */
BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD index, UDWORD offset)
{
@ -217,7 +261,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
SDWORD instructionCount = 0;
UDWORD CurEvent;
BOOL bStop;
BOOL bStop,bEvent;
ASSERT((PTRVALID(psContext, sizeof(SCRIPT_CONTEXT)),
"interpRunScript: invalid context pointer"));
@ -227,6 +271,8 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
if (bInterpRunning)
{
debug(LOG_ERROR,"interpRunScript: interpreter already running"
" - callback being called from within a script function?");
ASSERT((FALSE,
"interpRunScript: interpreter already running"
" - callback being called from within a script function?"));
@ -249,12 +295,15 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
numGlobals = psProg->numGlobals;
psGlobals = psContext->psGlobals;
bEvent = FALSE;
// Find the code range
switch (runType)
{
case IRT_TRIGGER:
if (index > psProg->numTriggers)
{
debug(LOG_ERROR,"interpRunScript: trigger index out of range");
ASSERT((FALSE, "interpRunScript: trigger index out of range"));
return FALSE;
}
@ -265,14 +314,18 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
case IRT_EVENT:
if (index > psProg->numEvents)
{
debug(LOG_ERROR,"interpRunScript: trigger index out of range");
ASSERT((FALSE, "interpRunScript: trigger index out of range"));
return FALSE;
}
pCodeBase = psProg->pCode + psProg->pEventTab[index];
pCodeStart = pCodeBase + offset;
pCodeEnd = psProg->pCode + psProg->pEventTab[index+1];
bEvent = TRUE; //remember it's an event
break;
default:
debug(LOG_ERROR,"interpRunScript: unknown run type");
ASSERT((FALSE, "interpRunScript: unknown run type"));
return FALSE;
}
@ -292,6 +345,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
{
if (instructionCount > INTERP_MAXINSTRUCTIONS)
{
debug( LOG_ERROR, "interpRunScript: max instruction count exceeded - infinite loop ?" );
ASSERT((FALSE,
"interpRunScript: max instruction count exceeded - infinite loop ?"));
goto exit_with_error;
@ -305,8 +359,9 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
{
/* Custom function call */
case OP_FUNC:
debug( LOG_SCRIPT, "OP_FUNC" );
if(!RetStackRemember(CurEvent, (UDWORD)(ip + 2))) //Remember where to jump back later
//debug( LOG_SCRIPT, "-OP_FUNC" );
//debug( LOG_SCRIPT, "OP_FUNC: remember event %d, ip=%d", CurEvent, (ip + 2) );
if(!RetStackRemember(CurEvent, (ip + 2))) //Remember where to jump back later
{
debug( LOG_ERROR, "interpRunScript() - RetStackRemember() failed.");
return FALSE;
@ -314,6 +369,8 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
CurEvent = *(ip+1); //Current event = event to jump to
if (CurEvent > psProg->numEvents)
{
debug( LOG_ERROR, "interpRunScript: trigger index out of range");
@ -328,8 +385,96 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
ip = pCodeStart; //Start at the beginning of the new event
//debug( LOG_SCRIPT, "-OP_FUNC: jumped to event %d; ip=%d, numLocalVars: %d", CurEvent, ip, psContext->psCode->numLocalVars[CurEvent] );
//debug( LOG_SCRIPT, "-END OP_FUNC" );
break;
//handle local variables
case OP_PUSHLOCAL:
//debug( LOG_SCRIPT, "OP_PUSHLOCAL");
//debug( LOG_SCRIPT, "OP_PUSHLOCAL, (CurEvent=%d, data =%d) num loc vars: %d; pushing: %d", CurEvent, data, psContext->psCode->numLocalVars[CurEvent], psContext->psCode->ppsLocalVarVal[CurEvent][data].v.ival);
if (data >= psContext->psCode->numLocalVars[CurEvent])
{
debug(LOG_ERROR, "interpRunScript: OP_PUSHLOCAL: variable index out of range");
ASSERT((FALSE, "interpRunScript: OP_PUSHLOCAL: variable index out of range"));
goto exit_with_error;
}
//debug( LOG_SCRIPT, "OP_PUSHLOCAL 2");
//debug(LOG_SCRIPT, "OP_PUSHLOCAL type: %d", psContext->psCode->ppsLocalVarVal[CurEvent][data].type);
if (!stackPush( &(psContext->psCode->ppsLocalVarVal[CurEvent][data]) ))
{
debug(LOG_ERROR, "interpRunScript: OP_PUSHLOCAL: push failed");
goto exit_with_error;
}
//debug( LOG_SCRIPT, "OP_PUSHLOCAL 3");
ip += 1;//aOpSize[opcode];
break;
case OP_POPLOCAL:
//debug( LOG_SCRIPT, "OP_POPLOCAL, event index: '%d', data: '%d'", CurEvent, data);
//debug( LOG_SCRIPT, "OP_POPLOCAL, numLocalVars: '%d'", psContext->psCode->numLocalVars[CurEvent]);
if (data >= psContext->psCode->numLocalVars[CurEvent])
{
debug(LOG_ERROR, "interpRunScript: OP_POPLOCAL: variable index out of range");
ASSERT((FALSE, "interpRunScript: variable index out of range"));
goto exit_with_error;
}
//debug( LOG_SCRIPT, "OP_POPLOCAL 2");
//DbgMsg("OP_POPLOCAL type: %d, CurEvent=%d, data=%d", psContext->psCode->ppsLocalVarVal[CurEvent][data].type, CurEvent, data);
if (!stackPopType( &(psContext->psCode->ppsLocalVarVal[CurEvent][data]) ))
{
debug(LOG_ERROR, "interpRunScript: OP_POPLOCAL: pop failed");
goto exit_with_error;
}
//debug(LOG_SCRIPT, "OP_POPLOCAL: type=%d, val=%d", psContext->psCode->ppsLocalVarVal[CurEvent][data].type, psContext->psCode->ppsLocalVarVal[CurEvent][data].v.ival);
//debug( LOG_SCRIPT, "OP_POPLOCAL 3");
ip += 1; //aOpSize[opcode];
break;
case OP_PUSHLOCALREF:
// The type of the variable is stored in with the opcode
sVal.type = (*ip) & OPCODE_DATAMASK;
/* get local var index */
data = *(ip + 1);
if (data >= psContext->psCode->numLocalVars[CurEvent])
{
debug(LOG_ERROR, "interpRunScript: OP_PUSHLOCALREF: variable index out of range");
ASSERT((FALSE, "interpRunScript: OP_PUSHLOCALREF: variable index out of range"));
goto exit_with_error;
}
/* get local variable */
psVar = &(psContext->psCode->ppsLocalVarVal[CurEvent][data]);
sVal.v.oval = &(psVar->v.ival);
TRCPRINTF(("PUSHREF "));
TRCPRINTVAL(&sVal);
TRCPRINTF(("\n"));
if (!stackPush(&sVal))
{
debug(LOG_ERROR, "interpRunScript: OP_PUSHLOCALREF: push failed");
goto exit_with_error;
}
ip += 2;
break;
case OP_PUSH:
// The type of the value is stored in with the opcode
sVal.type = (*ip) & OPCODE_DATAMASK;
@ -341,6 +486,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
if (!stackPush(&sVal))
{
// Eeerk, out of memory
debug( LOG_ERROR, "interpRunScript: out of memory!" );
ASSERT((FALSE, "interpRunScript: out of memory!"));
goto exit_with_error;
}
@ -358,6 +504,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
if (!stackPush(&sVal))
{
// Eeerk, out of memory
debug( LOG_ERROR, "interpRunScript: out of memory!" );
ASSERT((FALSE, "interpRunScript: out of memory!"));
goto exit_with_error;
}
@ -367,6 +514,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTF(("POP\n"));
if (!stackPop(&sVal))
{
debug( LOG_ERROR, "interpRunScript: could not do stack pop" );
ASSERT((FALSE, "interpRunScript: could not do stack pop"));
goto exit_with_error;
}
@ -376,6 +524,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTMATHSOP(data);
if (!stackBinaryOp((OPCODE)data))
{
debug( LOG_ERROR, "interpRunScript: could not do binary op" );
ASSERT((FALSE, "interpRunScript: could not do binary op"));
goto exit_with_error;
}
@ -387,6 +536,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTMATHSOP(data);
if (!stackUnaryOp((OPCODE)data))
{
debug( LOG_ERROR, "interpRunScript: could not do unary op" );
ASSERT((FALSE, "interpRunScript: could not do unary op"));
goto exit_with_error;
}
@ -398,11 +548,13 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTF(("PUSHGLOBAL %d\n", data));
if (data >= numGlobals)
{
debug( LOG_ERROR, "interpRunScript: variable index out of range" );
ASSERT((FALSE, "interpRunScript: variable index out of range"));
goto exit_with_error;
}
if (!stackPush(interpGetVarData(psGlobals, data)))
{
debug( LOG_ERROR, "interpRunScript: could not do stack push" );
ASSERT((FALSE, "interpRunScript: could not do stack push"));
goto exit_with_error;
}
@ -414,11 +566,13 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTF(("\n"));
if (data >= numGlobals)
{
debug( LOG_ERROR, "interpRunScript: variable index out of range" );
ASSERT((FALSE, "interpRunScript: variable index out of range"));
goto exit_with_error;
}
if (!stackPopType(interpGetVarData(psGlobals, data)))
{
debug( LOG_ERROR, "interpRunScript: could not do stack pop" );
ASSERT((FALSE, "interpRunScript: could not do stack pop"));
goto exit_with_error;
}
@ -447,12 +601,14 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTF(("PUSHARRAYGLOBAL "));
if (!interpGetArrayVarData(&ip, psGlobals, psProg, &psVar))
{
debug( LOG_ERROR, "interpRunScript: could not get array var data, CurEvent=%d", CurEvent );
ASSERT((FALSE, "interpRunScript: could not get array var data"));
goto exit_with_error;
}
TRCPRINTF(("\n"));
if (!stackPush(psVar))
{
debug( LOG_ERROR, "interpRunScript: could not do stack push" );
ASSERT((FALSE, "interpRunScript: could not do stack push"));
goto exit_with_error;
}
@ -489,6 +645,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTF(("POPARRAYGLOBAL "));
if (!interpGetArrayVarData(&ip, psGlobals, psProg, &psVar))
{
debug( LOG_ERROR, "interpRunScript: could not get array var data" );
ASSERT((FALSE, "interpRunScript: could not get array var data"));
goto exit_with_error;
}
@ -496,6 +653,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
TRCPRINTF(("\n"));
if (!stackPopType(psVar))
{
debug( LOG_ERROR, "interpRunScript: could not do pop stack of type" );
ASSERT((FALSE, "interpRunScript: could not do pop stack of type"));
goto exit_with_error;
}
@ -505,6 +663,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
(SWORD)data, ip - psProg->pCode + (SWORD)data));
if (!stackPop(&sVal))
{
debug( LOG_ERROR, "interpRunScript: could not do pop of stack" );
ASSERT((FALSE, "interpRunScript: could not do pop of stack"));
goto exit_with_error;
}
@ -515,6 +674,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
ip += (SWORD)data;
if (ip < pCodeStart || ip > pCodeEnd)
{
debug( LOG_ERROR, "interpRunScript: jump out of range" );
ASSERT((FALSE, "interpRunScript: jump out of range"));
goto exit_with_error;
}
@ -532,6 +692,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
ip += (SWORD)data;
if (ip < pCodeStart || ip > pCodeEnd)
{
debug( LOG_ERROR, "interpRunScript: jump out of range" );
ASSERT((FALSE, "interpRunScript: jump out of range"));
goto exit_with_error;
}
@ -543,6 +704,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
scriptFunc = (SCRIPT_FUNC)*(ip+1);
if (!scriptFunc())
{
debug( LOG_ERROR, "interpRunScript: could not do func" );
ASSERT((FALSE, "interpRunScript: could not do func"));
goto exit_with_error;
}
@ -555,6 +717,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
scriptVarFunc = (SCRIPT_VARFUNC)*(ip+1);
if (!scriptVarFunc(data))
{
debug( LOG_ERROR, "interpRunScript: could not do var func" );
ASSERT((FALSE, "interpRunScript: could not do var func"));
goto exit_with_error;
}
@ -572,6 +735,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
// tell the event system to reschedule this event
if (!eventAddPauseTrigger(psContext, index, ip - pCodeBase, data))
{
debug( LOG_ERROR, "interpRunScript: could not add pause trigger" );
ASSERT((FALSE, "interpRunScript: could not add pause trigger"));
goto exit_with_error;
}
@ -579,6 +743,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
ip = pCodeEnd;
break;
default:
debug(LOG_ERROR, "interpRunScript: unknown opcode");
ASSERT((FALSE, "interpRunScript: unknown opcode"));
goto exit_with_error;
break;
@ -587,26 +752,34 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
else //End of the event reached, see if we have to jump back to the caller function or just exit
{
//debug(LOG_SCRIPT, "End of event reached");
//reset local vars
//if(!resetLocalVars(psProg, CurEvent))
// goto exit_with_error;
if(!resetLocalVars(psProg, CurEvent))
{
debug( LOG_ERROR, "interpRunScript: could not reset local vars for event %d", CurEvent );
goto exit_with_error;
}
if(!IsRetStackEmpty()) //There was a caller function before this one
{
if (!PopRetStack((UDWORD *)&ip)) //Pop return address
//debug(LOG_SCRIPT, "GetCallDepth = %d", GetCallDepth());
if(!PopRetStack((UDWORD *)&ip)) //Pop return address
{
debug( LOG_ERROR, "interpRunScript() - PopRetStack(): failed to pop return adress.");
return FALSE;
}
//debug(LOG_SCRIPT, "Return adress = %d", ip);
if(!PopRetStack(&CurEvent)) //Pop event index
{
debug( LOG_ERROR, "interpRunScript() - PopRetStack(): failed to pop return event index.");
return FALSE;
}
debug( LOG_SCRIPT, "RETURN" );
//debug( LOG_SCRIPT, "RETURNED TO CALLER EVENT %d", CurEvent );
//Set new boundries
//--------------------------
@ -619,9 +792,14 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
}
else
{
//debug( LOG_SCRIPT, " *** CALL STACK EMPTY ***" );
//reset local vars
//if(!resetLocalVars(psProg, index))
// goto exit_with_error;
if(!resetLocalVars(psProg, index))
{
debug( LOG_ERROR, "interpRunScript: could not reset local vars" );
goto exit_with_error;
}
bStop = TRUE; //Stop execution of this event here, no more calling functions stored
}
@ -640,6 +818,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
exit_with_error:
// Deal with the script crashing or running out of memory
debug(LOG_ERROR,"interpRunScript: *** ERROR EXIT *** (CurEvent=%d)", CurEvent);
TRCPRINTF(("*** ERROR EXIT ***\n"));
bInterpRunning = FALSE;
return FALSE;
@ -753,6 +932,8 @@ UDWORD RetStackRemember(UDWORD EvTrigIndex, UDWORD address)
retStack[retStackPos - 1] = EvTrigIndex; //First store event index
retStack[retStackPos] = address; //current ip
//debug( LOG_SCRIPT, "RetStackRemember: ip=%d, event=%d", address, EvTrigIndex);
return TRUE;
}
@ -764,9 +945,9 @@ BOOL IsRetStackEmpty()
BOOL PopRetStack(UDWORD *psVal)
{
//DbgMsg("Popping: %d", retStackPos);
if(retStackPos < 0)
{
debug( LOG_ERROR, "PopRetStack: retStackPos < 0");
return FALSE;
}
@ -774,7 +955,7 @@ BOOL PopRetStack(UDWORD *psVal)
retStackPos = retStackPos - 1;
//DbgMsg("Popped: %d, %d", retStackPos, *psVal);
//debug( LOG_SCRIPT, "PopRetStack: val=%d", *psVal);
return TRUE;
}

View File

@ -105,6 +105,9 @@ typedef enum _op_code
OP_LESS,
OP_FUNC, //custom (in-script) function call
OP_POPLOCAL, //local var
OP_PUSHLOCAL,
OP_PUSHLOCALREF,
} OPCODE;
/* How far the opcode is shifted up a UDWORD to allow other data to be
@ -135,6 +138,7 @@ typedef enum _storage_type
ST_PRIVATE, // Private variable
ST_OBJECT, // A value stored in an objects data space.
ST_EXTERN, // An external value accessed by function call
ST_LOCAL, // A local variable
} enum_STORAGE_TYPE;
typedef UBYTE STORAGE_TYPE;
@ -208,6 +212,14 @@ typedef struct _script_code
UWORD numArrays; // the number of arrays in the program
UDWORD arraySize; // the number of elements in all the defined arrays
INTERP_TYPE *pGlobals; // Types of the global variables
INTERP_TYPE **ppsLocalVars; //storage for local vars
UDWORD *numLocalVars; //number of local vars each event has
INTERP_VAL **ppsLocalVarVal; //Values of the local vars used during interpreting process
UDWORD *numParams; //number of arguments this event has
VAR_DEBUG *psVarDebug; // The names and storage types of variables
ARRAY_DATA *psArrayInfo; // The sizes of the program arrays
ARRAY_DEBUG *psArrayDebug; // Debug info for the arrays

View File

@ -306,5 +306,8 @@ extern BOOL scriptSetCode(CODE_BLOCK *psBlock); // The code block
/* Look up a function symbol */
extern BOOL scriptLookUpFunction(STRING *pIdent, FUNC_SYMBOL **ppsSym);
/* Look up an in-script custom function symbol */
extern BOOL scriptLookUpCustomFunction(STRING *pIdent, EVENT_SYMBOL **ppsSym);
#endif

View File

@ -103,6 +103,23 @@ void scriptFreeCode(SCRIPT_CODE *psCode)
}
FREE(psCode->psArrayDebug);
}
/* Free local vars */
for(i=0; i < psCode->numEvents; i++)
{
FREE(psCode->ppsLocalVars[i]);
FREE(psCode->ppsLocalVarVal[i]);
psCode->numParams = 0;
psCode->numLocalVars = 0;
FREE(psCode->numParams);
FREE(psCode->numLocalVars);
}
FREE(psCode->ppsLocalVars);
FREE(psCode->ppsLocalVarVal);
FREE(psCode);
}

View File

@ -44,6 +44,8 @@ SDWORD scriptGetVarToken(VAR_SYMBOL *psVar)
{
BOOL object;
//debug( LOG_SCRIPT, "scriptGetVarToken" );
// See if this is an object pointer
if (!asScrTypeTab || psVar->type < VAL_USERTYPESTART)
{
@ -118,6 +120,7 @@ SDWORD scriptGetVarToken(VAR_SYMBOL *psVar)
break;
case VAL_INT:
// case VAL_FLOAT:
//debug( LOG_SCRIPT, "scriptGetVarToken: VAL_INT (NUM_VAR)" );
return NUM_VAR;
break;
default:
@ -126,6 +129,8 @@ SDWORD scriptGetVarToken(VAR_SYMBOL *psVar)
}
}
}
//debug( LOG_SCRIPT, "END scriptGetVarToken" );
}
/* Get the token type for a constant symbol */
@ -133,6 +138,8 @@ SDWORD scriptGetConstToken(CONST_SYMBOL *psConst)
{
BOOL object;
//debug( LOG_SCRIPT, "scriptGetConstToken" );
// See if this is an object constant
if (!asScrTypeTab || psConst->type < VAL_USERTYPESTART)
{
@ -163,6 +170,8 @@ SDWORD scriptGetConstToken(CONST_SYMBOL *psConst)
}
break;
}
//debug( LOG_SCRIPT, "END scriptGetConstToken" );
}
/* Get the token type for a function symbol */
@ -170,6 +179,8 @@ SDWORD scriptGetFuncToken(FUNC_SYMBOL *psFunc)
{
BOOL object;
//debug( LOG_SCRIPT, "scriptGetFuncToken" );
// See if this is an object pointer
if (!asScrTypeTab || psFunc->type < VAL_USERTYPESTART)
{
@ -203,6 +214,8 @@ SDWORD scriptGetFuncToken(FUNC_SYMBOL *psFunc)
break;
}
}
//debug( LOG_SCRIPT, "END scriptGetFuncToken" );
}
@ -211,16 +224,16 @@ SDWORD scriptGetCustomFuncToken(EVENT_SYMBOL *psFunc)
{
BOOL object;
debug( LOG_SCRIPT, "scriptGetCustomFuncToken" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken" );
// See if this is an object pointer
object = asScrTypeTab[psFunc->retType - VAL_USERTYPESTART].accessType == AT_OBJECT;
debug( LOG_SCRIPT, "scriptGetCustomFuncToken 3" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken 3" );
if (object)
{
debug( LOG_SCRIPT, "scriptGetCustomFuncToken: object" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken: object" );
return OBJ_FUNC_CUST;
}
else
@ -228,30 +241,30 @@ SDWORD scriptGetCustomFuncToken(EVENT_SYMBOL *psFunc)
switch (psFunc->retType)
{
case VAL_BOOL:
debug( LOG_SCRIPT, "scriptGetCustomFuncToken: VAL_BOOL" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken: VAL_BOOL" );
return BOOL_FUNC_CUST;
break;
case VAL_INT:
// case VAL_FLOAT:
debug( LOG_SCRIPT, "scriptGetCustomFuncToken: VAL_INT" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken: VAL_INT" );
return NUM_FUNC_CUST;
break;
case VAL_STRING: /* <NEW> */
debug( LOG_SCRIPT, "scriptGetCustomFuncToken: VAL_STRING" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken: VAL_STRING" );
return STRING_FUNC_CUST;
break;
case VAL_VOID:
debug( LOG_SCRIPT, "scriptGetCustomFuncToken: void function" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken: void function" );
return VOID_FUNC_CUST;
break;
default:
debug( LOG_SCRIPT, "scriptGetCustomFuncToken: default" );
//debug( LOG_SCRIPT, "scriptGetCustomFuncToken: default" );
return USER_FUNC_CUST;
break;
}
}
debug( LOG_SCRIPT, "END scriptGetCustomFuncToken" );
//debug( LOG_SCRIPT, "END scriptGetCustomFuncToken" );
}
@ -281,10 +294,11 @@ ref return REF;
/* new stuff */
function return FUNCTION;
return return RETURN;
return { return RET; }
public { scr_lval.stype = ST_PUBLIC; return STORAGE; }
private { scr_lval.stype = ST_PRIVATE; return STORAGE; }
local { scr_lval.stype = ST_LOCAL; return STORAGE; }
while return WHILE;
if return IF;
else return ELSE;
@ -333,6 +347,8 @@ NOT return _NOT;
/* Match identifiers */
[a-zA-Z][0-9_a-zA-Z]* {
//debug( LOG_SCRIPT, "FLEX: looking up '%s'", scr_text );
/* See if this identifier has been defined as a type */
if (scriptLookUpType(scr_text, &scr_lval.tval))
{
@ -361,7 +377,7 @@ NOT return _NOT;
/* See if this identifier has been defined as a custom function */
else if (scriptLookUpCustomFunction(scr_text, &scr_lval.eSymbol))
{
debug( LOG_SCRIPT, "scriptLookUpCustomFunction: '%s' - custom function", scr_text );
//debug( LOG_SCRIPT, "scriptLookUpCustomFunction: '%s' - custom function", scr_text );
return scriptGetCustomFuncToken(scr_lval.eSymbol);
}
@ -382,6 +398,8 @@ NOT return _NOT;
}
else
{
//debug( LOG_SCRIPT, "FLEX: '%s' is an ident", scr_text );
strcpy(aText[currText], scr_text);
scr_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
@ -440,7 +458,7 @@ int scr_wrap(void)
{
if (inComment)
{
DBERROR(("Warning: reached end of file in a comment"));
DBERROR(("Warning: reched end of file in a comment"));
}
return 1;
}

File diff suppressed because it is too large Load Diff

View File

@ -142,12 +142,17 @@ BOOL stackPopType(INTERP_VAL *psVal)
{
INTERP_VAL *psTop;
//debug(LOG_SCRIPT, "stackPopType 1");
if ((psCurrChunk->psPrev == NULL) && (currEntry == 0))
{
debug(LOG_ERROR, "stackPopType: stack empty");
ASSERT((FALSE, "stackPopType: stack empty"));
return FALSE;
}
//debug(LOG_SCRIPT, "stackPopType 2");
/* move the stack pointer down one */
if (currEntry == 0)
{
@ -160,16 +165,26 @@ BOOL stackPopType(INTERP_VAL *psVal)
currEntry--;
}
//debug(LOG_SCRIPT, "stackPopType 3");
psTop = psCurrChunk->aVals + currEntry;
//debug(LOG_SCRIPT, "stackPopType 4");
if (!interpCheckEquiv(psVal->type,psTop->type))
{
debug(LOG_ERROR, "stackPopType: type mismatch");
ASSERT((FALSE, "stackPopType: type mismatch"));
return FALSE;
}
//debug(LOG_SCRIPT, "stackPopType 5");
/* copy the value off the stack */
psVal->v.ival = psTop->v.ival;
//debug(LOG_SCRIPT, "stackPopType 6");
return TRUE;
}