- Fixed errors and warnings when compiling with GCC. (Unfortunately, the VC++ debug builds

become ungodly slow when using mods with complex DECORATE. The GCC debug builds run just
  fine, however. Hopefully this is something that can be fixed later with an assembly-optimized
  version of the main VM loop, because I don't relish the thought of being stuck with GDB
  for debugging.)
- Fixed: The ACS_Named* action specials were erroneously defined as taking strings instead of
  names.
- Fixed: Copy-paste error caused FxMultiNameState::Emit to generate code that called
  DecoNameToClass instead of DecoFindMultiNameState.
- Updated FxActionSpecialCall::Emit for named script specials.
- Fixed inverted asserts for FxMinusSign::Emit and FxUnaryNotBitwise::Emit.


SVN r3893 (scripting)
This commit is contained in:
Randy Heit 2012-10-18 03:19:27 +00:00
parent e7efa1d802
commit 38d7b7d203
23 changed files with 73 additions and 65 deletions

View File

@ -566,11 +566,6 @@ else( NO_ASM )
ADD_ASM_FILE( asm_ia32 tmap2 )
ADD_ASM_FILE( asm_ia32 tmap3 )
endif( X64 )
if( WIN32 )
if( NOT X64 )
ADD_ASM_FILE( win32 wrappers )
endif( NOT X64 )
endif( WIN32 )
endif( NO_ASM )
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.c ${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.h
@ -880,7 +875,6 @@ add_executable( zdoom WIN32
thingdef/thingdef_data.cpp
thingdef/thingdef_exp.cpp
thingdef/thingdef_expression.cpp
thingdef/thingdef_function.cpp
thingdef/thingdef_parse.cpp
thingdef/thingdef_properties.cpp
thingdef/thingdef_states.cpp
@ -910,6 +904,7 @@ add_executable( zdoom WIN32
r_data/renderstyle.cpp
r_data/r_interpolate.cpp
r_data/r_translate.cpp
zscript/ast.cpp
zscript/vmbuilder.cpp
zscript/vmdisasm.cpp
zscript/vmexec.cpp

View File

@ -500,7 +500,7 @@ inline AActor *GetDefaultByType (const PClass *type)
template<class T>
inline T *GetDefault ()
{
return (T *)(RUNTIME_CLASS(T)->Defaults);
return (T *)(RUNTIME_CLASS_CASTLESS(T)->Defaults);
}
struct line_t;
@ -634,7 +634,7 @@ public:
AInventory *FindInventory (FName type);
template<class T> T *FindInventory ()
{
return static_cast<T *> (FindInventory (RUNTIME_CLASS(T)));
return static_cast<T *> (FindInventory (RUNTIME_TEMPLATE_CLASS(T)));
}
// Adds one item of a particular type. Returns NULL if it could not be added.
@ -1018,7 +1018,7 @@ public:
do
{
actor = FActorIterator::Next ();
} while (actor && !actor->IsKindOf (RUNTIME_CLASS(T)));
} while (actor && !actor->IsKindOf (RUNTIME_TEMPLATE_CLASS(T)));
return static_cast<T *>(actor);
}
};
@ -1055,7 +1055,7 @@ AActor *Spawn (FName classname, fixed_t x, fixed_t y, fixed_t z, replace_t allow
template<class T>
inline T *Spawn (fixed_t x, fixed_t y, fixed_t z, replace_t allowreplacement)
{
return static_cast<T *>(AActor::StaticSpawn (RUNTIME_CLASS(T), x, y, z, allowreplacement));
return static_cast<T *>(AActor::StaticSpawn (RUNTIME_TEMPLATE_CLASS(T), x, y, z, allowreplacement));
}

View File

@ -2040,7 +2040,7 @@ static int PatchCodePtrs (int dummy)
if (!symname.CompareNoCase(MBFCodePointers[i].alias))
{
symname = MBFCodePointers[i].name;
Printf("%s --> %s\n", MBFCodePointers[i].alias, MBFCodePointers[i].name);
Printf("%s --> %s\n", MBFCodePointers[i].alias, MBFCodePointers[i].name.GetChars());
}
}

View File

@ -82,6 +82,7 @@ class PClassActor;
#define RUNTIME_CLASS_CASTLESS(cls) (cls::RegistrationInfo.MyClass) // Passed a native class name, returns a PClass representing that class
#define RUNTIME_CLASS(cls) ((cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // Like above, but returns the true type of the meta object
#define RUNTIME_TEMPLATE_CLASS(cls) ((class cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // RUNTIME_CLASS, but works with templated parameters on GCC
#define NATIVE_TYPE(object) (object->StaticType()) // Passed an object, returns the type of the C++ class representing the object
// Enumerations for the meta classes created by ClassReg::RegisterClass()

View File

@ -103,7 +103,7 @@ void DumpTypeTable()
if (len > max)
max = len;
}
if (len < countof(lens))
if (len < (int)countof(lens))
{
lens[len]++;
}
@ -114,7 +114,7 @@ void DumpTypeTable()
Printf("Max bucket size: %d\n", max);
Printf("Avg bucket size: %.2f\n", double(all) / used);
int j,k;
for (k = k = countof(lens)-1; k > 0; --k)
for (k = countof(lens)-1; k > 0; --k)
if (lens[k])
break;
for (j = 0; j <= k; ++j)
@ -224,8 +224,8 @@ bool PType::IsMatch(intptr_t id1, intptr_t id2) const
void PType::GetTypeIDs(intptr_t &id1, intptr_t &id2) const
{
id1 = NULL;
id2 = NULL;
id1 = 0;
id2 = 0;
}
//==========================================================================
@ -486,7 +486,7 @@ PPointer::PPointer(PType *pointsat)
bool PPointer::IsMatch(intptr_t id1, intptr_t id2) const
{
assert(id2 == NULL);
assert(id2 == 0);
PType *pointat = (PType *)id1;
return pointat == PointedType;
@ -733,7 +733,7 @@ PDynArray::PDynArray(PType *etype)
bool PDynArray::IsMatch(intptr_t id1, intptr_t id2) const
{
assert(id2 == NULL);
assert(id2 == 0);
const PType *elemtype = (const PType *)id1;
return elemtype == ElementType;

View File

@ -121,10 +121,10 @@ public:
template <class T> class TThinkerIterator : public FThinkerIterator
{
public:
TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_CLASS(T), statnum)
TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_TEMPLATE_CLASS(T), statnum)
{
}
TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_CLASS(T), statnum, prev)
TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_TEMPLATE_CLASS(T), statnum, prev)
{
}
TThinkerIterator (const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(subclass, statnum)

View File

@ -272,7 +272,7 @@ inline FArchive &operator<< (FArchive &arc, PalEntry &p)
template<class T>
inline FArchive &operator<< (FArchive &arc, T* &object)
{
return arc.SerializeObject ((DObject*&)object, RUNTIME_CLASS(T));
return arc.SerializeObject ((DObject*&)object, RUNTIME_TEMPLATE_CLASS(T));
}
FArchive &operator<< (FArchive &arc, PClass * &info);

View File

@ -1273,7 +1273,7 @@ bool AInventory::DoRespawn ()
void AInventory::GiveQuest (AActor *toucher)
{
int quest = GetClass()->GiveQuest;
if (quest > 0 && quest <= countof(QuestItemClasses))
if (quest > 0 && quest <= (int)countof(QuestItemClasses))
{
toucher->GiveInventoryType (QuestItemClasses[quest-1]);
}

View File

@ -240,7 +240,7 @@ DBaseStatusBar::DBaseStatusBar (int reltop, int hres, int vres)
void DBaseStatusBar::Destroy ()
{
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
DHUDMessage *msg = Messages[i];
while (msg)
@ -342,7 +342,7 @@ void DBaseStatusBar::MultiplayerChanged ()
void DBaseStatusBar::Tick ()
{
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
DHUDMessage *msg = Messages[i];
DHUDMessage **prev = &Messages[i];
@ -424,7 +424,7 @@ void DBaseStatusBar::AttachMessage (DHUDMessage *msg, DWORD id, int layer)
DHUDMessage *DBaseStatusBar::DetachMessage (DHUDMessage *msg)
{
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
DHUDMessage *probe = Messages[i];
DHUDMessage **prev = &Messages[i];
@ -451,7 +451,7 @@ DHUDMessage *DBaseStatusBar::DetachMessage (DHUDMessage *msg)
DHUDMessage *DBaseStatusBar::DetachMessage (DWORD id)
{
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
DHUDMessage *probe = Messages[i];
DHUDMessage **prev = &Messages[i];
@ -484,7 +484,7 @@ DHUDMessage *DBaseStatusBar::DetachMessage (DWORD id)
void DBaseStatusBar::DetachAllMessages ()
{
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
DHUDMessage *probe = Messages[i];
@ -1627,7 +1627,7 @@ void DBaseStatusBar::Serialize (FArchive &arc)
}
else
{
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
arc << Messages[i];
}
@ -1639,7 +1639,7 @@ void DBaseStatusBar::ScreenSizeChanged ()
st_scale.Callback ();
SB_state = screen->GetPageCount ();
for (int i = 0; i < countof(Messages); ++i)
for (size_t i = 0; i < countof(Messages); ++i)
{
DHUDMessage *message = Messages[i];
while (message != NULL)

View File

@ -35,7 +35,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveQuestItem)
PARAM_INT(questitem);
// Give one of these quest items to every player in the game
if (questitem >= 0 && questitem < countof(QuestItemClasses))
if (questitem >= 0 && questitem < (int)countof(QuestItemClasses))
{
for (int i = 0; i < MAXPLAYERS; ++i)
{

View File

@ -352,7 +352,7 @@ void M_SetMenu(FName menu, int param)
GameStartupInfo.Episode = -1;
GameStartupInfo.PlayerClass =
param == -1000? NULL :
param == -1? "Random" : GetPrintableDisplayName(PlayerClasses[param].Type);
param == -1? "Random" : GetPrintableDisplayName(PlayerClasses[param].Type).GetChars();
break;
case NAME_Skillmenu:

View File

@ -2621,7 +2621,7 @@ AActor *AActor::TIDHash[128];
void AActor::ClearTIDHashes ()
{
memset(TIDHash, NULL, sizeof(TIDHash));
memset(TIDHash, 0, sizeof(TIDHash));
}
//

View File

@ -420,7 +420,7 @@ IMPLEMENT_CLASS(PClassPlayerPawn)
PClassPlayerPawn::PClassPlayerPawn()
{
for (int i = 0; i < countof(HexenArmor); ++i)
for (size_t i = 0; i < countof(HexenArmor); ++i)
{
HexenArmor[i] = 0;
}
@ -433,7 +433,7 @@ void PClassPlayerPawn::Derive(PClass *newclass)
assert(newclass->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn)));
Super::Derive(newclass);
PClassPlayerPawn *newp = static_cast<PClassPlayerPawn *>(newclass);
int i;
size_t i;
newp->DisplayName = DisplayName;
newp->SoundClass = SoundClass;

View File

@ -952,7 +952,7 @@ void R_InitSprites ()
FString classface = basetype->Face;
strcpy (skins[i].name, "Base");
if (classface.IsEmpty() == NULL || strcmp(classface, "None") == 0)
if (classface.IsEmpty() || strcmp(classface, "None") == 0)
{
skins[i].face[0] = 'S';
skins[i].face[1] = 'T';

View File

@ -779,7 +779,7 @@ void R_SetupFrame (AActor *actor)
{
iview->nviewx = camera->x;
iview->nviewy = camera->y;
iview->nviewz = camera->player ? camera->player->viewz : camera->z + camera->GetClass()->CameraHeight;
iview->nviewz = camera->player ? camera->player->viewz : camera->z + camera->GetCameraHeight();
viewsector = camera->Sector;
r_showviewer = false;
}

View File

@ -2280,7 +2280,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Log)
{
PARAM_ACTION_PROLOGUE;
PARAM_STRING(text);
Printf("%s\n", text);
Printf("%s\n", text.GetChars());
ACTION_SET_RESULT(false); // Prints should never set the result for inventory state chains!
return numret;
}
@ -2737,7 +2737,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CountdownArg)
PARAM_INT(argnum);
PARAM_STATE_OPT(state) { state = self->FindState(NAME_Death); }
if (argnum > 0 && argnum < countof(self->args))
if (argnum > 0 && argnum < (int)countof(self->args))
{
if (!self->args[argnum]--)
{
@ -3542,7 +3542,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_ChangeFlag)
}
else
{
Printf("Unknown flag '%s' in '%s'\n", flagname, cls->TypeName.GetChars());
Printf("Unknown flag '%s' in '%s'\n", flagname.GetChars(), cls->TypeName.GetChars());
}
return 0;
}
@ -3598,7 +3598,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckFlag)
}
else
{
Printf("Unknown flag '%s' in '%s'\n", flagname, cls->TypeName.GetChars());
Printf("Unknown flag '%s' in '%s'\n", flagname.GetChars(), cls->TypeName.GetChars());
}
return numret;
}
@ -4092,7 +4092,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Teleport)
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Turn)
{
PARAM_ACTION_PROLOGUE;
PARAM_ANGLE_OPT(angle);
PARAM_ANGLE_OPT(angle) { angle = 0; }
self->angle += angle;
return 0;
}

View File

@ -831,7 +831,7 @@ ExpEmit FxMinusSign::Emit(VMFunctionBuilder *build)
{
assert(ValueType.Type == Operand->ValueType.Type);
ExpEmit from = Operand->Emit(build);
assert(from.Konst != 0);
assert(from.Konst == 0);
// Do it in-place.
if (ValueType == VAL_Int)
{
@ -929,7 +929,7 @@ ExpEmit FxUnaryNotBitwise::Emit(VMFunctionBuilder *build)
assert(ValueType.Type == Operand->ValueType.Type);
assert(ValueType == VAL_Int);
ExpEmit from = Operand->Emit(build);
assert(from.Konst != 0);
assert(from.Konst == 0);
// Do it in-place.
build->Emit(OP_NOT, from.RegNum, from.RegNum, 0);
return from;
@ -3507,23 +3507,32 @@ ExpEmit FxActionSpecialCall::Emit(VMFunctionBuilder *build)
assert(Self == NULL);
unsigned i = 0;
build->Emit(OP_PARAMI, Special); // pass special number
build->Emit(OP_PARAMI, abs(Special)); // pass special number
build->Emit(OP_PARAM, 0, REGT_POINTER, 0); // pass self
if (ArgList != NULL)
{
for (; i < ArgList->Size(); ++i)
{
FxExpression *argex = (*ArgList)[i];
assert(argex->ValueType == VAL_Int);
if (argex->isConstant())
if (Special < 0 && i == 0)
{
EmitConstantInt(build, argex->EvalExpression(NULL).GetInt());
assert(argex->ValueType == VAL_Name);
assert(argex->isConstant());
EmitConstantInt(build, -argex->EvalExpression(NULL).GetName());
}
else
{
ExpEmit arg(argex->Emit(build));
build->Emit(OP_PARAM, 0, arg.RegType, arg.RegNum);
arg.Free(build);
assert(argex->ValueType == VAL_Int);
if (argex->isConstant())
{
EmitConstantInt(build, argex->EvalExpression(NULL).GetInt());
}
else
{
ExpEmit arg(argex->Emit(build));
build->Emit(OP_PARAM, 0, arg.RegType, arg.RegNum);
arg.Free(build);
}
}
}
}
@ -3995,11 +4004,11 @@ ExpEmit FxMultiNameState::Emit(VMFunctionBuilder *build)
// Find the DecoFindMultiNameState function. If not found, create it and install it
// in Actor.
VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoNameToClass, false);
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoFindMultiNameState, false);
if (sym == NULL)
{
PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoNameToClass);
VMNativeFunction *calldec = new VMNativeFunction(DecoFindMultiNameState, NAME_DecoNameToClass);
PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoFindMultiNameState);
VMNativeFunction *calldec = new VMNativeFunction(DecoFindMultiNameState, NAME_DecoFindMultiNameState);
symfunc->Function = calldec;
sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);

View File

@ -88,7 +88,7 @@ static PClassActor *FindClassTentative(const char *name, PClass *ancestor)
assert(cls != NULL); // cls can not be NULL here
if (!cls->IsDescendantOf(ancestor))
{
I_Error("%s does not inherit from %s\n", name, ancestor);
I_Error("%s does not inherit from %s\n", name, ancestor->TypeName.GetChars());
}
return static_cast<PClassActor *>(cls);
}

View File

@ -446,7 +446,7 @@ size_t VMFunctionBuilder::Emit(int opcode, int opa, VM_SHALF opbc)
{
assert(opcode >= 0 && opcode < NUM_OPS);
assert(opa >= 0 && opa <= 255);
assert(opbc >= -32768 && opbc <= 32767);
//assert(opbc >= -32768 && opbc <= 32767); always true due to parameter's width
VMOP op;
op.op = opcode;
op.a = opa;

View File

@ -157,7 +157,7 @@ void VMDumpConstants(FILE *out, const VMScriptFunction *func)
{
for (j = 0, k = i; j < 4 && k < func->NumKonstA; j++, k += kk)
{
mysnprintf(tmp, countof(tmp), "%3d. %p:%d", k, func->KonstA[k], func->KonstATags()[k]);
mysnprintf(tmp, countof(tmp), "%3d. %p:%d", k, func->KonstA[k].v, func->KonstATags()[k]);
printf_wrapper(out, "%-20s", tmp);
}
printf_wrapper(out, "\n");

View File

@ -1264,7 +1264,7 @@ begin:
c = 0;
}
reg.a[a] = (VM_UBYTE *)reg.a[B] + c;
reg.atag[a] = c == 0 ? reg.atag[B] : ATAG_GENERIC;
reg.atag[a] = c == 0 ? reg.atag[B] : (int)ATAG_GENERIC;
NEXTOP;
OP(ADDA_RK):
ASSERTA(a); ASSERTA(B); ASSERTKD(C);

View File

@ -168,7 +168,8 @@ static void DoParse(const char *filename)
failed = false;
#ifdef _DEBUG
FILE *f = fopen("trace.txt", "w");
ZCCParseTrace(f, "");
char prompt = '\0';
ZCCParseTrace(f, &prompt);
#endif
ZCCParseState state(sc);
@ -232,12 +233,14 @@ static void DoParse(const char *filename)
FString ast = ZCC_PrintAST(state.TopNode);
FString astfile = ExtractFileBase(filename, false);
astfile << ".ast";
#ifdef _DEBUG
f = fopen(astfile, "w");
if (f != NULL)
{
fputs(ast.GetChars(), f);
fclose(f);
}
#endif
}
CCMD(parse)
@ -255,7 +258,7 @@ static FString ZCCTokenName(int terminal)
return "end of file";
}
int sc_token;
if (terminal > 0 && terminal < countof(BackTokenMap))
if (terminal > 0 && terminal < (int)countof(BackTokenMap))
{
sc_token = BackTokenMap[terminal];
if (sc_token == 0)

View File

@ -300,13 +300,13 @@ ACTOR Actor native //: Thinker
action native A_TransferPointer(int ptr_source, int ptr_recepient, int sourcefield, int recepientfield=AAPTR_DEFAULT, int flags=0);
action native A_CopyFriendliness(int ptr_source = AAPTR_MASTER);
action native ACS_NamedExecute(string script, int mapnum=0, int arg1=0, int arg2=0, int arg3=0);
action native ACS_NamedSuspend(string script, int mapnum=0);
action native ACS_NamedTerminate(string script, int mapnum=0);
action native ACS_NamedLockedExecute(string script, int mapnum=0, int arg1=0, int arg2=0, int lock=0);
action native ACS_NamedLockedExecuteDoor(string script, int mapnum=0, int arg1=0, int arg2=0, int lock=0);
action native ACS_NamedExecuteWithResult(string script, int arg1=0, int arg2=0, int arg3=0, int arg4=0);
action native ACS_NamedExecuteAlways(string script, int mapnum=0, int arg1=0, int arg2=0, int arg3=0);
action native ACS_NamedExecute(name script, int mapnum=0, int arg1=0, int arg2=0, int arg3=0);
action native ACS_NamedSuspend(name script, int mapnum=0);
action native ACS_NamedTerminate(name script, int mapnum=0);
action native ACS_NamedLockedExecute(name script, int mapnum=0, int arg1=0, int arg2=0, int lock=0);
action native ACS_NamedLockedExecuteDoor(name script, int mapnum=0, int arg1=0, int arg2=0, int lock=0);
action native ACS_NamedExecuteWithResult(name script, int arg1=0, int arg2=0, int arg3=0, int arg4=0);
action native ACS_NamedExecuteAlways(name script, int mapnum=0, int arg1=0, int arg2=0, int arg3=0);
States
{