- Generic cleanup
- Strings are not equivalent to anything, only convertible (mistake in one of my last commits) - Clarify names - Print user types git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4339 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
7092a1f808
commit
ce8e1d1846
|
@ -824,7 +824,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
|
|||
ASSERT( InstrPointer->type == VAL_OPCODE,
|
||||
"wrong value type passed for OP_TO_FLOAT: %d", InstrPointer->type);
|
||||
|
||||
if(!castTop(VAL_FLOAT))
|
||||
if(!stackCastTop(VAL_FLOAT))
|
||||
{
|
||||
debug( LOG_ERROR, "interpRunScript: OP_TO_FLOAT failed" );
|
||||
goto exit_with_error;
|
||||
|
@ -835,7 +835,7 @@ BOOL interpRunScript(SCRIPT_CONTEXT *psContext, INTERP_RUNTYPE runType, UDWORD i
|
|||
ASSERT( InstrPointer->type == VAL_OPCODE,
|
||||
"wrong value type passed for OP_TO_INT: %d", InstrPointer->type);
|
||||
|
||||
if(!castTop(VAL_INT))
|
||||
if(!stackCastTop(VAL_INT))
|
||||
{
|
||||
debug( LOG_ERROR, "interpRunScript: OP_TO_INT failed" );
|
||||
goto exit_with_error;
|
||||
|
@ -1000,17 +1000,36 @@ const char *interpTypeToString(INTERP_TYPE type)
|
|||
{
|
||||
int i; // Loop goes down -> signed
|
||||
|
||||
for (i = ARRAY_SIZE(typeToStringMap)-1; i >= 0; i--)
|
||||
// Look whether it is a defaul type:
|
||||
for (i = ARRAY_SIZE(typeToStringMap)-1;
|
||||
i >= 0 && type <= typeToStringMap[i].type;
|
||||
i--)
|
||||
{
|
||||
if (type >= typeToStringMap[i].type)
|
||||
return typeToStringMap[i].name;
|
||||
}
|
||||
|
||||
// Look whether it is a user type:
|
||||
if (asScrTypeTab)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i = 0; asScrTypeTab[i].typeID != 0; i++)
|
||||
{
|
||||
if (asScrTypeTab[i].typeID == type)
|
||||
{
|
||||
return asScrTypeTab[i].pIdent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
/* Check if two types are equivalent */
|
||||
/* Check if two types are equivalent
|
||||
* Means: Their data can be copied without conversion.
|
||||
* I.e. strings are NOT equivalent to anything but strings, even though they can be converted
|
||||
*/
|
||||
BOOL interpCheckEquiv(INTERP_TYPE to, INTERP_TYPE from)
|
||||
{
|
||||
BOOL toRef = false, fromRef = false;
|
||||
|
@ -1019,12 +1038,12 @@ BOOL interpCheckEquiv(INTERP_TYPE to, INTERP_TYPE from)
|
|||
if (to & VAL_REF)
|
||||
{
|
||||
toRef = true;
|
||||
to = (INTERP_TYPE)(to & ~VAL_REF);
|
||||
to &= ~VAL_REF;
|
||||
}
|
||||
if (from & VAL_REF)
|
||||
{
|
||||
fromRef = true;
|
||||
from = (INTERP_TYPE)(from & ~VAL_REF);
|
||||
from &= ~VAL_REF;
|
||||
}
|
||||
if (toRef != fromRef)
|
||||
{
|
||||
|
@ -1032,14 +1051,8 @@ BOOL interpCheckEquiv(INTERP_TYPE to, INTERP_TYPE from)
|
|||
}
|
||||
|
||||
/* Void pointer is compatible with any other type */
|
||||
if (to == VAL_VOID && toRef == true && fromRef == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Strings can be converted to */
|
||||
if ( to == VAL_STRING &&
|
||||
(from == VAL_BOOL || from == VAL_INT || from == VAL_FLOAT) )
|
||||
if (toRef == true && fromRef == true &&
|
||||
(to == VAL_VOID || from == VAL_VOID) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ typedef enum _interp_runtype
|
|||
extern SDWORD aOpSize[];
|
||||
|
||||
/* Check if two types are equivalent */
|
||||
extern BOOL interpCheckEquiv(INTERP_TYPE to, INTERP_TYPE from);
|
||||
extern BOOL interpCheckEquiv(INTERP_TYPE to, INTERP_TYPE from) WZ_DECL_PURE;
|
||||
|
||||
// Initialise the interpreter
|
||||
extern BOOL interpInitialise(void);
|
||||
|
|
|
@ -67,7 +67,7 @@ static inline BOOL stackRemoveTop(void);
|
|||
/* Check if the stack is empty */
|
||||
BOOL stackEmpty(void)
|
||||
{
|
||||
return psCurrChunk == psStackBase && currEntry == 0;
|
||||
return (psCurrChunk->psPrev == NULL && currEntry == 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,6 +110,7 @@ static BOOL stackNewChunk(UDWORD size)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Push a value onto the stack */
|
||||
BOOL stackPush(INTERP_VAL *psVal)
|
||||
{
|
||||
|
@ -162,7 +163,7 @@ BOOL stackPush(INTERP_VAL *psVal)
|
|||
/* Pop a value off the stack */
|
||||
BOOL stackPop(INTERP_VAL *psVal)
|
||||
{
|
||||
if ((psCurrChunk->psPrev == NULL) && (currEntry == 0))
|
||||
if (stackEmpty())
|
||||
{
|
||||
debug(LOG_ERROR, "stackPop: stack empty");
|
||||
ASSERT( false, "stackPop: stack empty" );
|
||||
|
@ -909,13 +910,12 @@ BOOL stackUnaryOp(OPCODE opcode)
|
|||
return true;
|
||||
}
|
||||
|
||||
BOOL castTop(INTERP_TYPE neededType)
|
||||
BOOL stackCastTop(INTERP_TYPE neededType)
|
||||
{
|
||||
INTERP_VAL *pTop=NULL;
|
||||
INTERP_VAL *pTop;
|
||||
|
||||
//debug(LOG_WZ, "casting to %d", neededType);
|
||||
|
||||
ASSERT(neededType == VAL_INT || neededType == VAL_FLOAT, "stackCast: can't cast to %d", neededType);
|
||||
ASSERT(neededType == VAL_INT || neededType == VAL_FLOAT,
|
||||
"stackCast: can't cast to %d", neededType);
|
||||
|
||||
if (!stackPeekTop(&pTop) || pTop==NULL)
|
||||
{
|
||||
|
@ -923,61 +923,50 @@ BOOL castTop(INTERP_TYPE neededType)
|
|||
return false;
|
||||
}
|
||||
|
||||
//debug(LOG_WZ, "castTop: stack type %d", pTop->type);
|
||||
|
||||
/* see if we can cast this data type */
|
||||
switch (pTop->type)
|
||||
{
|
||||
case VAL_BOOL:
|
||||
|
||||
switch (neededType)
|
||||
{
|
||||
case VAL_FLOAT: /* casting from bool to float */
|
||||
|
||||
pTop->v.fval = (float)pTop->v.bval;
|
||||
pTop->type = VAL_FLOAT;
|
||||
return true;
|
||||
case VAL_BOOL:
|
||||
switch (neededType)
|
||||
{
|
||||
case VAL_FLOAT: /* casting from bool to float */
|
||||
|
||||
pTop->v.fval = (float)pTop->v.bval;
|
||||
pTop->type = VAL_FLOAT;
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VAL_INT:
|
||||
switch (neededType)
|
||||
{
|
||||
case VAL_FLOAT: /* casting from int to float */
|
||||
pTop->v.fval = (float)pTop->v.ival;
|
||||
pTop->type = VAL_FLOAT;
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VAL_FLOAT:
|
||||
switch (neededType)
|
||||
{
|
||||
case VAL_INT: /* casting from float to int */
|
||||
pTop->v.ival = (int)pTop->v.fval;
|
||||
pTop->type = VAL_INT;
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
debug(LOG_ERROR, "cast error %d->%d", pTop->type, neededType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VAL_INT:
|
||||
|
||||
switch (neededType)
|
||||
{
|
||||
case VAL_FLOAT: /* casting from int to float */
|
||||
pTop->v.fval = (float)pTop->v.ival;
|
||||
pTop->type = VAL_FLOAT;
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
debug(LOG_ERROR, "cast error %d->%d", pTop->type, neededType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VAL_FLOAT:
|
||||
|
||||
switch (neededType)
|
||||
{
|
||||
case VAL_INT: /* casting from float to int */
|
||||
pTop->v.ival = (SDWORD)pTop->v.fval;
|
||||
pTop->type = VAL_INT;
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
debug(LOG_ERROR, "cast error %d->%d", pTop->type, neededType);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
debug(LOG_ERROR, "can't cast from %d to %d", pTop->type, neededType);
|
||||
break;
|
||||
}
|
||||
|
||||
debug(LOG_ERROR, "can't cast from %s to %s",
|
||||
interpTypeToString(pTop->type), interpTypeToString(neededType));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ extern BOOL stackBinaryOp(OPCODE opcode);
|
|||
extern BOOL stackUnaryOp(OPCODE opcode);
|
||||
|
||||
/* casts top of the stack to some other data type */
|
||||
extern BOOL castTop(INTERP_TYPE neededType);
|
||||
extern BOOL stackCastTop(INTERP_TYPE neededType);
|
||||
|
||||
/* Reset the stack to an empty state */
|
||||
extern void stackReset(void);
|
||||
|
|
|
@ -164,16 +164,14 @@ void scrvReleaseBasePointer(INTERP_VAL *psVal)
|
|||
// Check all the base pointers to see if they have died
|
||||
void scrvUpdateBasePointers(void)
|
||||
{
|
||||
SDWORD i;
|
||||
INTERP_VAL *psVal;
|
||||
BASE_OBJECT *psObj;
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<MAX_BASEPOINTER; i++)
|
||||
for(i = 0; i < MAX_BASEPOINTER; i++)
|
||||
{
|
||||
if (asBasePointers[i] != NULL)
|
||||
{
|
||||
psVal = asBasePointers[i];
|
||||
psObj = (BASE_OBJECT *)psVal->v.oval;
|
||||
INTERP_VAL *psVal = asBasePointers[i];
|
||||
BASE_OBJECT *psObj = (BASE_OBJECT *)psVal->v.oval;
|
||||
|
||||
if (psObj && isDead(psObj))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue