From 6fdc8dd8b11fc36b21d58fe7099eb09e3157f5f9 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Wed, 26 Mar 2008 02:35:26 +0000 Subject: [PATCH] Dont store values and types seperately. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4346 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/script/event.c | 16 +++++----------- lib/script/interp.c | 2 +- lib/script/interp.h | 6 ++---- lib/script/script.c | 8 ++------ lib/script/script_parser.y | 9 +++++---- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/script/event.c b/lib/script/event.c index 7417c3ae3..da81eaa15 100644 --- a/lib/script/event.c +++ b/lib/script/event.c @@ -374,7 +374,7 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release, if (psCode->numArrays > 0) { - for(i=0; ipsArrayInfo[arrayNum].dimensions; i++) + for(i = 0; ipsArrayInfo[arrayNum].dimensions; i++) { arraySize *= psCode->psArrayInfo[arrayNum].elements[i]; } @@ -383,25 +383,19 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release, //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 { unsigned int j; - 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++) { - INTERP_TYPE type = psCode->ppsLocalVars[i][j]; + INTERP_TYPE type = psCode->ppsLocalVars[i][j].type; - if (!interpInitValue(type, &psCode->ppsLocalVarVal[i][j])) + if (!interpInitValue(type, &psCode->ppsLocalVars[i][j])) { debug(LOG_ERROR, "eventNewContext: failed to init local value"); return false; @@ -410,7 +404,7 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release, //Initialize objects if (asCreateFuncs != NULL && type < numFuncs && asCreateFuncs[type]) { - if (!asCreateFuncs[type](&(psCode->ppsLocalVarVal[i][j]) )) + if (!asCreateFuncs[type](&(psCode->ppsLocalVars[i][j]))) { debug(LOG_ERROR,"eventNewContext: asCreateFuncs failed for local var"); return false; @@ -420,7 +414,7 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release, } else //this event has no local vars { - psCode->ppsLocalVarVal[i] = NULL; + psCode->ppsLocalVars[i] = NULL; } } diff --git a/lib/script/interp.c b/lib/script/interp.c index ed993fd23..f707735d0 100644 --- a/lib/script/interp.c +++ b/lib/script/interp.c @@ -1406,7 +1406,7 @@ static inline void createVarEnvironment(SCRIPT_CONTEXT *psContext, UDWORD eventI varEnvironment[callDepth] = (INTERP_VAL *)malloc(sizeof(INTERP_VAL) * numEventVars); // create environment - memcpy(varEnvironment[callDepth], psContext->psCode->ppsLocalVarVal[eventIndex], sizeof(INTERP_VAL) * numEventVars); + memcpy(varEnvironment[callDepth], psContext->psCode->ppsLocalVars[eventIndex], sizeof(INTERP_VAL) * numEventVars); // allocate new space for strings to preserve original ones for (i = 0; i < numEventVars; i++) diff --git a/lib/script/interp.h b/lib/script/interp.h index debc5215d..9ac7d3b0b 100644 --- a/lib/script/interp.h +++ b/lib/script/interp.h @@ -245,12 +245,10 @@ typedef struct _script_code 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 (type) 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 + INTERP_VAL **ppsLocalVars; //storage for local vars + 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 diff --git a/lib/script/script.c b/lib/script/script.c index 993b5a337..15a203937 100644 --- a/lib/script/script.c +++ b/lib/script/script.c @@ -81,11 +81,10 @@ void scriptFreeCode(SCRIPT_CODE *psCode) //free strings for event i for(j=0; j < psCode->numLocalVars[i]; j++) { - interpCleanValue(&psCode->ppsLocalVarVal[i][j]); + interpCleanValue(&psCode->ppsLocalVars[i][j]); } - free(psCode->ppsLocalVars[i]); - free(psCode->ppsLocalVarVal[i]); //free pointer to event i local vars + free(psCode->ppsLocalVars[i]); // free pointer to event i local vars } } @@ -153,9 +152,6 @@ void scriptFreeCode(SCRIPT_CODE *psCode) if(psCode->ppsLocalVars != NULL) free(psCode->ppsLocalVars); - if(psCode->ppsLocalVarVal != NULL) - free(psCode->ppsLocalVarVal); - psCode->numEvents = 0; free(psCode); diff --git a/lib/script/script_parser.y b/lib/script/script_parser.y index aa90f291c..3a3d1fc99 100644 --- a/lib/script/script_parser.y +++ b/lib/script/script_parser.y @@ -1991,12 +1991,13 @@ script: header var_list ALLOC_PROG(psFinalProg, size, psCurrBlock->pCode, numVars, numArrays, numTriggers, numEvents); + debug(LOG_SCRIPT, "allocated space for %d events", numEvents); + //store local vars psFinalProg->numLocalVars = (UDWORD *)malloc(sizeof(UDWORD) * numEvents); //how many local vars each event has //allocate array for holding an array of local vars for each event - psFinalProg->ppsLocalVars = (INTERP_TYPE **)malloc(sizeof(INTERP_TYPE*) * numEvents); - psFinalProg->ppsLocalVarVal = NULL; + psFinalProg->ppsLocalVars = (INTERP_VAL **)malloc(sizeof(INTERP_VAL*) * numEvents); psFinalProg->numParams = (UDWORD *)malloc(sizeof(UDWORD) * numEvents); //how many arguments each event has @@ -2010,11 +2011,11 @@ script: header var_list if(numEventLocalVars[i] > 0) { unsigned int j; - INTERP_TYPE * pCurEvLocalVars = (INTERP_TYPE*)malloc(sizeof(INTERP_TYPE) * numEventLocalVars[i]); + INTERP_VAL * pCurEvLocalVars = (INTERP_VAL*)malloc(sizeof(INTERP_VAL) * numEventLocalVars[i]); for(psCurr = psLocalVarsB[i], j = 0; psCurr != NULL; psCurr = psCurr->psNext, j++) { - pCurEvLocalVars[numEventLocalVars[i] - j - 1] = psCurr->type; //save type, order is reversed + interpInitValue(psCurr->type, &pCurEvLocalVars[numEventLocalVars[i] - j - 1]); } psFinalProg->ppsLocalVars[i] = pCurEvLocalVars;