- marked all places where an incomplete parameter list may be passed to the VM by a native call by redirecting VMCall to an intermediate VMCallWithDefaults. This function must later fill in the missing arguments from the default.

This commit is contained in:
Christoph Oelckers 2018-11-16 18:41:27 +01:00
parent acbdfddb26
commit c24da62cdd
6 changed files with 16 additions and 11 deletions

View file

@ -175,13 +175,13 @@ bool FState::CallAction(AActor *self, AActor *stateowner, FStateParamInfo *info,
if (stateret == nullptr) if (stateret == nullptr)
{ {
VMCall(ActionFunc, params, ActionFunc->ImplicitArgs, nullptr, 0); VMCallWithDefaults(ActionFunc, params, ActionFunc->ImplicitArgs, nullptr, 0);
} }
else else
{ {
VMReturn ret; VMReturn ret;
ret.PointerAt((void **)stateret); ret.PointerAt((void **)stateret);
VMCall(ActionFunc, params, ActionFunc->ImplicitArgs, &ret, 1); VMCallWithDefaults(ActionFunc, params, ActionFunc->ImplicitArgs, &ret, 1);
} }
} }
catch (CVMAbortException &err) catch (CVMAbortException &err)

View file

@ -1211,7 +1211,7 @@ DMenuItemBase * CreateOptionMenuItemSubmenu(const char *label, FName cmd, int ce
auto c = PClass::FindClass("OptionMenuItemSubmenu"); auto c = PClass::FindClass("OptionMenuItemSubmenu");
auto p = c->CreateNew(); auto p = c->CreateNew();
FString namestr = label; FString namestr = label;
VMValue params[] = { p, &namestr, cmd.GetIndex(), center }; VMValue params[] = { p, &namestr, cmd.GetIndex(), center, false };
auto f = dyn_cast<PFunction>(c->FindSymbol("Init", false)); auto f = dyn_cast<PFunction>(c->FindSymbol("Init", false));
VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0); VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0);
return (DMenuItemBase*)p; return (DMenuItemBase*)p;
@ -1233,7 +1233,7 @@ DMenuItemBase * CreateOptionMenuItemCommand(const char *label, FName cmd, bool c
auto c = PClass::FindClass("OptionMenuItemCommand"); auto c = PClass::FindClass("OptionMenuItemCommand");
auto p = c->CreateNew(); auto p = c->CreateNew();
FString namestr = label; FString namestr = label;
VMValue params[] = { p, &namestr, cmd.GetIndex(), centered }; VMValue params[] = { p, &namestr, cmd.GetIndex(), centered, false };
auto f = dyn_cast<PFunction>(c->FindSymbol("Init", false)); auto f = dyn_cast<PFunction>(c->FindSymbol("Init", false));
VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0); VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0);
auto unsafe = dyn_cast<PField>(c->FindSymbol("mUnsafe", false)); auto unsafe = dyn_cast<PField>(c->FindSymbol("mUnsafe", false));

View file

@ -477,7 +477,7 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc)
} }
DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew();
params[0] = item; params[0] = item;
VMCall(func->Variants[0].Implementation, &params[0], params.Size(), nullptr, 0); VMCallWithDefaults(func->Variants[0].Implementation, &params[0], params.Size(), nullptr, 0);
desc->mItems.Push((DMenuItemBase*)item); desc->mItems.Push((DMenuItemBase*)item);
if (cls->IsDescendantOf("ListMenuItemSelectable")) if (cls->IsDescendantOf("ListMenuItemSelectable"))
@ -917,7 +917,7 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc)
DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew();
params[0] = item; params[0] = item;
VMCall(func->Variants[0].Implementation, &params[0], params.Size(), nullptr, 0); VMCallWithDefaults(func->Variants[0].Implementation, &params[0], params.Size(), nullptr, 0);
desc->mItems.Push((DMenuItemBase*)item); desc->mItems.Push((DMenuItemBase*)item);
success = true; success = true;

View file

@ -5448,7 +5448,7 @@ static int ScriptCall(AActor *activator, unsigned argc, int32_t *args)
// The return value can be the same types as the parameter types, plus void // The return value can be the same types as the parameter types, plus void
if (func->Proto->ReturnTypes.Size() == 0) if (func->Proto->ReturnTypes.Size() == 0)
{ {
VMCall(func, &params[0], params.Size(), nullptr, 0); VMCallWithDefaults(func, &params[0], params.Size(), nullptr, 0);
} }
else else
{ {
@ -5470,20 +5470,20 @@ static int ScriptCall(AActor *activator, unsigned argc, int32_t *args)
{ {
double d; double d;
VMReturn ret(&d); VMReturn ret(&d);
VMCall(func, &params[0], params.Size(), &ret, 1); VMCallWithDefaults(func, &params[0], params.Size(), &ret, 1);
retval = DoubleToACS(d); retval = DoubleToACS(d);
} }
else if (rettype == TypeString) else if (rettype == TypeString)
{ {
FString d; FString d;
VMReturn ret(&d); VMReturn ret(&d);
VMCall(func, &params[0], params.Size(), &ret, 1); VMCallWithDefaults(func, &params[0], params.Size(), &ret, 1);
retval = GlobalACSStrings.AddString(d); retval = GlobalACSStrings.AddString(d);
} }
else else
{ {
// All other return values can not be handled so ignore them. // All other return values can not be handled so ignore them.
VMCall(func, &params[0], params.Size(), nullptr, 0); VMCallWithDefaults(func, &params[0], params.Size(), nullptr, 0);
} }
} }
} }

View file

@ -170,7 +170,7 @@ bool AStateProvider::CallStateChain (AActor *actor, FState *state)
try try
{ {
state->CheckCallerType(actor, this); state->CheckCallerType(actor, this);
VMCall(state->ActionFunc, params, state->ActionFunc->ImplicitArgs, wantret, numret); VMCallWithDefaults(state->ActionFunc, params, state->ActionFunc->ImplicitArgs, wantret, numret);
} }
catch (CVMAbortException &err) catch (CVMAbortException &err)
{ {

View file

@ -377,6 +377,11 @@ private:
int VMCall(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults/*, VMException **trap = NULL*/); int VMCall(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults/*, VMException **trap = NULL*/);
inline int VMCallWithDefaults(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults/*, VMException **trap = NULL*/)
{
VMCall(func, params, numparams, results, numresults);
}
// Use this in the prototype for a native function. // Use this in the prototype for a native function.
#define VM_ARGS VMValue *param, TArray<VMValue> &defaultparam, int numparam, VMReturn *ret, int numret #define VM_ARGS VMValue *param, TArray<VMValue> &defaultparam, int numparam, VMReturn *ret, int numret
#define VM_ARGS_NAMES param, defaultparam, numparam, ret, numret #define VM_ARGS_NAMES param, defaultparam, numparam, ret, numret