diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 4cb03111b..7d6fb9769 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -277,7 +277,7 @@ static void FinishThingdef() // Can we call this function directly without wrapping it in an // anonymous function? e.g. Are we passing any parameters to it? - func = NULL;//tcall->Code->GetDirectFunction(); + func = tcall->Code->GetDirectFunction(); if (func == NULL) { FCompileContext ctx(tcall->ActorClass); diff --git a/src/thingdef/thingdef_exp.h b/src/thingdef/thingdef_exp.h index 0ec4c95d7..d78638815 100644 --- a/src/thingdef/thingdef_exp.h +++ b/src/thingdef/thingdef_exp.h @@ -835,9 +835,9 @@ public: FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); ExpEmit Emit(VMFunctionBuilder *build, bool tailcall); - unsigned GetArgCount() { return ArgList == NULL ? 0 : ArgList->Size(); } - VMFunction *GetVMFunction() { return Function->Variants[0].Implementation; } - VMFunction *GetDirectFunction(); + unsigned GetArgCount() const { return ArgList == NULL ? 0 : ArgList->Size(); } + VMFunction *GetVMFunction() const { return Function->Variants[0].Implementation; } + bool IsDirectFunction(); }; //========================================================================== @@ -891,6 +891,7 @@ public: FxReturnStatement(FxVMFunctionCall *call, const FScriptPosition &pos); FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); + VMFunction *GetDirectFunction(); }; //========================================================================== diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index c94d6840d..742f5b52d 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -3202,24 +3202,6 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build, bool tailcall) } } -//========================================================================== -// -// FxVMFunctionCall :: GetDirectFunction -// -// If the function is not passed any explicit arguments, returns the -// function. Otherwise returns NULL. -// -//========================================================================== - -VMFunction *FxVMFunctionCall::GetDirectFunction() -{ - if (GetArgCount() == 0) - { - return GetVMFunction(); - } - return NULL; -} - //========================================================================== // // @@ -3505,6 +3487,19 @@ ExpEmit FxReturnStatement::Emit(VMFunctionBuilder *build) return ExpEmit(); } +VMFunction *FxReturnStatement::GetDirectFunction() +{ + // If this return statement calls a function with no arguments, + // then it can be a "direct" function. That is, the DECORATE + // definition can call that function directly without wrapping + // it inside VM code. + if (Call != NULL && Call->GetArgCount() == 0) + { + return Call->GetVMFunction(); + } + return NULL; +} + //========================================================================== // //==========================================================================