- scriptified the scripted marines.

- fixed symbol name generation for native functions.
- moved PrintableName to VMFunction so that native functions also have this information.
This commit is contained in:
Christoph Oelckers 2016-11-21 19:09:58 +01:00
parent 97763b5a2b
commit 360436c201
20 changed files with 658 additions and 756 deletions

View file

@ -230,6 +230,7 @@ static PSymbol *FindBuiltinFunction(FName funcname, VMNativeFunction::NativeCall
{
PSymbolVMFunction *symfunc = new PSymbolVMFunction(funcname);
VMNativeFunction *calldec = new VMNativeFunction(func, funcname);
calldec->PrintableName = funcname.GetChars();
symfunc->Function = calldec;
sym = symfunc;
GlobalSymbols.AddSymbol(sym);
@ -1428,6 +1429,14 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
delete this;
return x;
}
else if (ValueType == TypeSpriteID && basex->IsInteger())
{
basex->ValueType = TypeSpriteID;
auto x = basex;
basex = nullptr;
delete this;
return x;
}
else if (ValueType == TypeStateLabel)
{
if (basex->ValueType == TypeNullPtr)

View file

@ -581,17 +581,21 @@ AFuncDesc *FindFunction(PStruct *cls, const char * string)
{
for (int i = 0; i < 2; i++)
{
// Since many functions have been declared with Actor as owning class, despited being members of something else, let's hack around this until they have been fixed or exported.
// Since many functions have been declared with Actor as owning class, despite being members of something else, let's hack around this until they have been fixed or exported.
// Since most of these are expected to be scriptified anyway, there's no point fixing them all before they get exported.
if (i == 1 && !cls->IsKindOf(RUNTIME_CLASS(PClassActor))) break;
if (i == 1)
{
if (!cls->IsKindOf(RUNTIME_CLASS(PClassActor))) break;
cls = RUNTIME_CLASS(AActor);
}
FStringf fullname("%s_%s", i == 0 ? cls->TypeName.GetChars() : "Actor", string);
int min = 0, max = AFTable.Size() - 1;
while (min <= max)
{
int mid = (min + max) / 2;
int lexval = stricmp(fullname, AFTable[mid].Name + 1);
int lexval = stricmp(cls->TypeName.GetChars(), AFTable[mid].ClassName + 1);
if (lexval == 0) lexval = stricmp(string, AFTable[mid].FuncName);
if (lexval == 0)
{
return &AFTable[mid];
@ -641,7 +645,10 @@ static int propcmp(const void * a, const void * b)
static int funccmp(const void * a, const void * b)
{
return stricmp(((AFuncDesc*)a)->Name + 1, ((AFuncDesc*)b)->Name + 1); // +1 to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
// +1 to get past the prefix letter of the native class name, which gets omitted by the FName for the class.
int res = stricmp(((AFuncDesc*)a)->ClassName + 1, ((AFuncDesc*)b)->ClassName + 1);
if (res == 0) res = stricmp(((AFuncDesc*)a)->FuncName, ((AFuncDesc*)b)->FuncName);
return res;
}
//==========================================================================
@ -700,7 +707,8 @@ void InitThingdef()
{
AFuncDesc *afunc = (AFuncDesc *)*probe;
assert(afunc->VMPointer != NULL);
*(afunc->VMPointer) = new VMNativeFunction(afunc->Function, afunc->Name);
*(afunc->VMPointer) = new VMNativeFunction(afunc->Function, afunc->FuncName);
(*(afunc->VMPointer))->PrintableName.Format("%s.%s [Native]", afunc->ClassName+1, afunc->FuncName);
AFTable.Push(*afunc);
}
AFTable.ShrinkToFit();

View file

@ -669,6 +669,7 @@ public:
int VirtualIndex = -1;
FName Name;
TArray<VMValue> DefaultArgs;
FString PrintableName; // so that the VM can print meaningful info if something in this function goes wrong.
class PPrototype *Proto;
@ -822,7 +823,6 @@ public:
VM_UHALF NumKonstA;
VM_UHALF MaxParam; // Maximum number of parameters this function has on the stack at once
VM_UBYTE NumArgs; // Number of arguments this function takes
FString PrintableName; // so that the VM can print meaningful info if something in this function goes wrong.
TArray<FTypeAndOffset> SpecialInits; // list of all contents on the extra stack which require construction and destruction
void InitExtra(void *addr);
@ -1015,7 +1015,8 @@ typedef int(*actionf_p)(VMFrameStack *stack, VMValue *param, TArray<VMValue> &de
struct AFuncDesc
{
const char *Name;
const char *ClassName;
const char *FuncName;
actionf_p Function;
VMNativeFunction **VMPointer;
};
@ -1037,7 +1038,7 @@ struct AFuncDesc
#define DEFINE_ACTION_FUNCTION(cls, name) \
static int AF_##cls##_##name(VM_ARGS); \
VMNativeFunction *cls##_##name##_VMPtr; \
static const AFuncDesc cls##_##name##_Hook = { #cls "_" #name, AF_##cls##_##name, &cls##_##name##_VMPtr }; \
static const AFuncDesc cls##_##name##_Hook = { #cls, #name, AF_##cls##_##name, &cls##_##name##_VMPtr }; \
extern AFuncDesc const *const cls##_##name##_HookPtr; \
MSVC_ASEG AFuncDesc const *const cls##_##name##_HookPtr GCC_ASEG = &cls##_##name##_Hook; \
static int AF_##cls##_##name(VM_ARGS)

View file

@ -887,7 +887,7 @@ void FFunctionBuildList::Build()
catch (CRecoverableError &err)
{
// catch errors from the code generator and pring something meaningful.
item.Code->ScriptPosition.Message(MSG_ERROR, "%s in %s", err.GetMessage(), item.PrintableName);
item.Code->ScriptPosition.Message(MSG_ERROR, "%s in %s", err.GetMessage(), item.PrintableName.GetChars());
}
}
delete item.Code;

View file

@ -261,7 +261,6 @@ void VMDumpConstants(FILE *out, const VMScriptFunction *func)
void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction *func)
{
VMFunction *callfunc;
const char *callname;
const char *name;
int col;
int mode;
@ -497,8 +496,7 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
}
else if (code[i].op == OP_CALL_K || code[i].op == OP_TAIL_K)
{
callname = callfunc->IsKindOf(RUNTIME_CLASS(VMScriptFunction)) ? static_cast<VMScriptFunction*>(callfunc)->PrintableName : callfunc->Name != NAME_None ? callfunc->Name : "[anonfunc]";
printf_wrapper(out, " [%s]\n", callname);
printf_wrapper(out, " [%s]\n", callfunc->PrintableName.GetChars());
}
else
{

View file

@ -787,11 +787,11 @@ type_list(X) ::= type_list(A) COMMA type_or_array(B). { X = A; /*X-overwrites-A*
type_list_or_void(X) ::= VOID. { X = NULL; }
type_list_or_void(X) ::= type_list(X).
array_size_expr(X) ::= LBRACKET opt_expr(A) RBRACKET.
array_size_expr(X) ::= LBRACKET(L) opt_expr(A) RBRACKET.
{
if (A == NULL)
{
NEW_AST_NODE(Expression,nil,A);
NEW_AST_NODE(Expression,nil,L.SourceLoc);
nil->Operation = PEX_Nil;
nil->Type = NULL;
X = nil;

View file

@ -2304,14 +2304,14 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
{
if (vindex == -1)
{
Error(p, "Attempt to override non-existent virtual function %s", FName(f->Name).GetChars());
Error(f, "Attempt to override non-existent virtual function %s", FName(f->Name).GetChars());
}
else
{
auto oldfunc = clstype->Virtuals[vindex];
if (oldfunc->Final)
{
Error(p, "Attempt to override final function %s", FName(f->Name).GetChars());
Error(f, "Attempt to override final function %s", FName(f->Name).GetChars());
}
clstype->Virtuals[vindex] = sym->Variants[0].Implementation;
sym->Variants[0].Implementation->VirtualIndex = vindex;