From 4fa6678fc50f64a71daf7895d13bb3108977d421 Mon Sep 17 00:00:00 2001 From: Chronos Ouroboros Date: Mon, 21 Oct 2019 16:29:54 -0300 Subject: [PATCH] Fixed Vector2/3 out parameters in the ZScript compiler. --- src/scripting/backend/codegen.cpp | 10 +++++++++- src/scripting/backend/codegen.h | 1 + src/scripting/backend/vmbuilder.cpp | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 10c2632af0..c49902fc0c 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -7129,7 +7129,15 @@ FxExpression *FxStructMember::Resolve(FCompileContext &ctx) { // since this is a vector, all potential things that may get here are single float or an xy-vector. auto locvar = static_cast(classx); - locvar->RegOffset = int(membervar->Offset / 8); + if (!(locvar->Variable->VarFlags & VARF_Out)) + { + locvar->RegOffset = int(membervar->Offset / 8); + } + else + { + locvar->RegOffset = int(membervar->Offset); + } + locvar->ValueType = membervar->Type; classx = nullptr; delete this; diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 26f2011b28..fdd44cfc09 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -2126,6 +2126,7 @@ class FxLocalVariableDeclaration : public FxExpression friend class FxLocalVariable; friend class FxStaticArrayVariable; friend class FxLocalArrayDeclaration; + friend class FxStructMember; FName Name; FxExpression *Init; diff --git a/src/scripting/backend/vmbuilder.cpp b/src/scripting/backend/vmbuilder.cpp index 1c27a597e6..b787f8b587 100644 --- a/src/scripting/backend/vmbuilder.cpp +++ b/src/scripting/backend/vmbuilder.cpp @@ -884,9 +884,20 @@ void FFunctionBuildList::Build() sfunc->NumArgs = 0; // NumArgs for the VMFunction must be the amount of stack elements, which can differ from the amount of logical function arguments if vectors are in the list. // For the VM a vector is 2 or 3 args, depending on size. - for (auto s : item.Func->Variants[0].Proto->ArgumentTypes) + auto funcVariant = item.Func->Variants[0]; + for (unsigned int i = 0; i < funcVariant.Proto->ArgumentTypes.Size(); i++) { - sfunc->NumArgs += s->GetRegCount(); + auto argType = funcVariant.Proto->ArgumentTypes[i]; + auto argFlags = funcVariant.ArgFlags[i]; + if (argFlags & VARF_Out) + { + auto argPointer = NewPointer(argType); + sfunc->NumArgs += argPointer->GetRegCount(); + } + else + { + sfunc->NumArgs += argType->GetRegCount(); + } } if (dump != nullptr)