From 92f74634d6bbe961dbd795216134c12680bf88b1 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 29 Feb 2016 22:08:06 -0600 Subject: [PATCH] Remove FxParameter and use a single function instead --- src/thingdef/thingdef_exp.h | 11 ----- src/thingdef/thingdef_expression.cpp | 60 ++++++---------------------- src/thingdef/thingdef_states.cpp | 6 +-- 3 files changed, 16 insertions(+), 61 deletions(-) diff --git a/src/thingdef/thingdef_exp.h b/src/thingdef/thingdef_exp.h index b5ab642d0..74ccf1ba2 100644 --- a/src/thingdef/thingdef_exp.h +++ b/src/thingdef/thingdef_exp.h @@ -219,17 +219,6 @@ public: bool isresolved; }; -class FxParameter : public FxExpression -{ - FxExpression *Operand; - -public: - FxParameter(FxExpression*); - ~FxParameter(); - FxExpression *Resolve(FCompileContext&); - ExpEmit Emit(VMFunctionBuilder *build); -}; - //========================================================================== // // FxIdentifier diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index 41c95379c..bacb83e0f 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -225,45 +225,13 @@ void FxExpression::RequestAddress() // //========================================================================== -FxParameter::FxParameter(FxExpression *operand) -: FxExpression(operand->ScriptPosition) +static void EmitParameter(VMFunctionBuilder *build, FxExpression *operand, const FScriptPosition &pos) { - Operand = operand; - ValueType = operand->ValueType; -} - -//========================================================================== -// -// -// -//========================================================================== - -FxParameter::~FxParameter() -{ - SAFE_DELETE(Operand); -} - -//========================================================================== -// -// -// -//========================================================================== - -FxExpression *FxParameter::Resolve(FCompileContext& ctx) -{ - CHECKRESOLVED(); - SAFE_RESOLVE(Operand, ctx); - ValueType = Operand->ValueType; - return this; -} - -ExpEmit FxParameter::Emit(VMFunctionBuilder *build) -{ - ExpEmit where = Operand->Emit(build); + ExpEmit where = operand->Emit(build); if (where.RegType == REGT_NIL) { - ScriptPosition.Message(MSG_ERROR, "Attempted to pass a non-value"); + pos.Message(MSG_ERROR, "Attempted to pass a non-value"); build->Emit(OP_PARAM, 0, where.RegType, where.RegNum); } else @@ -276,7 +244,6 @@ ExpEmit FxParameter::Emit(VMFunctionBuilder *build) build->Emit(OP_PARAM, 0, regtype, where.RegNum); where.Free(build); } - return ExpEmit(); } //========================================================================== @@ -2251,8 +2218,8 @@ FxRandom::FxRandom(FRandom * r, FxExpression *mi, FxExpression *ma, const FScrip { if (mi != NULL && ma != NULL) { - min = new FxParameter(new FxIntCast(mi)); - max = new FxParameter(new FxIntCast(ma)); + min = new FxIntCast(mi); + max = new FxIntCast(ma); } else min = max = NULL; rng = r; @@ -2336,8 +2303,8 @@ ExpEmit FxRandom::Emit(VMFunctionBuilder *build) build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(rng, ATAG_RNG)); if (min != NULL && max != NULL) { - min->Emit(build); - max->Emit(build); + EmitParameter(build, min, ScriptPosition); + EmitParameter(build, max, ScriptPosition); build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 3, 1); } else @@ -2523,8 +2490,8 @@ FxFRandom::FxFRandom(FRandom *r, FxExpression *mi, FxExpression *ma, const FScri { if (mi != NULL && ma != NULL) { - min = new FxParameter(new FxFloatCast(mi)); - max = new FxParameter(new FxFloatCast(ma)); + min = new FxFloatCast(mi); + max = new FxFloatCast(ma); } ValueType = TypeFloat64; } @@ -2572,8 +2539,8 @@ ExpEmit FxFRandom::Emit(VMFunctionBuilder *build) build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(rng, ATAG_RNG)); if (min != NULL && max != NULL) { - min->Emit(build); - max->Emit(build); + EmitParameter(build, min, ScriptPosition); + EmitParameter(build, max, ScriptPosition); build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 3, 1); } else @@ -2597,7 +2564,6 @@ FxRandom2::FxRandom2(FRandom *r, FxExpression *m, const FScriptPosition &pos) rng = r; if (m) mask = new FxIntCast(m); else mask = new FxConstant(-1, pos); - mask = new FxParameter(mask); ValueType = TypeSInt32; } @@ -2642,7 +2608,7 @@ ExpEmit FxRandom2::Emit(VMFunctionBuilder *build) callfunc = ((PSymbolVMFunction *)sym)->Function; build->Emit(OP_PARAM, 0, REGT_POINTER | REGT_KONST, build->GetConstantAddress(rng, ATAG_RNG)); - mask->Emit(build); + EmitParameter(build, mask, ScriptPosition); build->Emit(OP_CALL_K, build->GetConstantAddress(callfunc, ATAG_OBJECT), 2, 1); ExpEmit out(build, REGT_INT); build->Emit(OP_RESULT, 0, REGT_INT, out.RegNum); @@ -3407,7 +3373,7 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build, bool tailcall) { for (unsigned i = 0; i < ArgList->Size(); ++i) { - (*ArgList)[i]->Emit(build); + EmitParameter(build, (*ArgList)[i], ScriptPosition); } } // Get a constant register for this function diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index 4df275921..702758eb7 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -77,7 +77,7 @@ FxVMFunctionCall *DoActionSpecials(FScanner &sc, FState & state, Baggage &bag) if (special > 0 && min_args >= 0) { FArgumentList *args = new FArgumentList; - args->Push(new FxParameter(new FxConstant(special, sc))); + args->Push(new FxConstant(special, sc)); i = 0; // Make this consistent with all other parameter parsing @@ -85,7 +85,7 @@ FxVMFunctionCall *DoActionSpecials(FScanner &sc, FState & state, Baggage &bag) { while (i < 5) { - args->Push(new FxParameter(new FxIntCast(ParseExpression(sc, bag.Info)))); + args->Push(new FxIntCast(ParseExpression(sc, bag.Info))); i++; if (!sc.CheckToken (',')) break; } @@ -661,7 +661,7 @@ void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray 0)