From 95ab1da6a05eb9c0f526c052d848662d07bb830b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 22:43:12 +0100 Subject: [PATCH] - always pass complete argument lists in the VM. --- src/scripting/backend/codegen.cpp | 25 +++++++++++++++++++++++++ src/scripting/backend/codegen.h | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 039a21dabf..9baf61bbcf 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -9127,6 +9127,31 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build) { count += EmitParameter(build, ArgList[i], ScriptPosition, &tempstrings); } + // Complete the parameter list from the defaults. + auto &defaults = Function->Variants[0].Implementation->DefaultArgs; + for (unsigned i = count; i < defaults.Size(); i++) + { + FxConstant *constant; + switch (defaults[i].Type) + { + default: + case REGT_INT: + constant = new FxConstant(defaults[i].i, ScriptPosition); + break; + case REGT_FLOAT: + constant = new FxConstant(defaults[i].f, ScriptPosition); + break; + case REGT_POINTER: + constant = new FxConstant(defaults[i].a, ScriptPosition); + break; + case REGT_STRING: + constant = new FxConstant(defaults[i].s(), ScriptPosition); + break; + } + count += EmitParameter(build, constant, ScriptPosition, &tempstrings); + delete constant; + } + ArgList.DeleteAndClear(); ArgList.ShrinkToFit(); diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 0925032820..87084596c3 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -501,6 +501,13 @@ public: isresolved = true; } + FxConstant(void *state, const FScriptPosition &pos) : FxExpression(EFX_Constant, pos) + { + value.pointer = state; + ValueType = value.Type = TypeVoidPtr; + isresolved = true; + } + FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos) { value.pointer = nullptr;