From c569029b1d9ca16e35cd6d9692d3f6a4131ce668 Mon Sep 17 00:00:00 2001 From: Player701 Date: Thu, 15 Nov 2018 23:39:13 +0300 Subject: [PATCH 1/5] - Readonly pointer casting now works in ZScript. --- src/scripting/backend/codegen.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 8576bcae18..015bae2d0d 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -4691,14 +4691,7 @@ FxExpression *FxDynamicCast::Resolve(FCompileContext& ctx) { CHECKRESOLVED(); SAFE_RESOLVE(expr, ctx); - bool constflag = expr->ValueType->isPointer() && expr->ValueType->toPointer()->IsConst; - if (constflag) - { - // readonly pointers are normally only used for class defaults which lack type information to be cast properly, so we have to error out here. - ScriptPosition.Message(MSG_ERROR, "Cannot cast a readonly pointer"); - delete this; - return nullptr; - } + bool constflag = expr->ValueType->isPointer() && expr->ValueType->toPointer()->IsConst; expr = new FxTypeCast(expr, NewPointer(RUNTIME_CLASS(DObject), constflag), true, true); expr = expr->Resolve(ctx); if (expr == nullptr) From 1250eb5323751f69124bc1c24e2ef33e4c7e4ea3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 08:06:01 +0100 Subject: [PATCH 2/5] - fixed: AActor' friction field was not saved --- src/p_mobj.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 8f2cf64fff..a02ea40647 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // // Copyright 1993-1996 id Software // Copyright 1994-1996 Raven Software @@ -533,7 +533,8 @@ void AActor::Serialize(FSerializer &arc) A("renderhidden", RenderHidden) A("renderrequired", RenderRequired) A("friendlyseeblocks", friendlyseeblocks) - A("spawntime", SpawnTime); + A("spawntime", SpawnTime) + A("friction", Friction); } #undef A From 7cd89fe07b5511bdc2798681291ccc54f71bc9f4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 11:21:51 +0100 Subject: [PATCH 3/5] - fixed: FxUnaryNotBitwise modified the source operand instead of allocating a new one. --- src/scripting/backend/codegen.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 015bae2d0d..921a438ed8 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -2058,10 +2058,12 @@ ExpEmit FxUnaryNotBitwise::Emit(VMFunctionBuilder *build) { assert(Operand->ValueType->GetRegType() == REGT_INT); ExpEmit from = Operand->Emit(build); + from.Free(build); + ExpEmit to(build, REGT_INT); assert(!from.Konst); - // Do it in-place. - build->Emit(OP_NOT, from.RegNum, from.RegNum, 0); - return from; + + build->Emit(OP_NOT, to.RegNum, from.RegNum, 0); + return to; } //========================================================================== From 358001c3069bbb745a53389539ba907a9213f80d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 11:32:24 +0100 Subject: [PATCH 4/5] fixed right shift operator for unsigned values This is version protected to avoid breaking old code. --- src/scripting/backend/codegen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 921a438ed8..6d06f22f9f 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -4011,7 +4011,7 @@ FxExpression *FxShift::Resolve(FCompileContext& ctx) if (left->IsNumeric() && right->IsNumeric()) { if (!Promote(ctx, true)) return nullptr; - if (ValueType == TypeUInt32 && Operator == TK_RShift) Operator = TK_URShift; + if ((left->ValueType == TypeUInt32 && ctx.Version >= MakeVersion(3, 7)) && Operator == TK_RShift) Operator = TK_URShift; } else { From 8c574471088ee9615a905b7b563c890e83760acd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 12:28:24 +0100 Subject: [PATCH 5/5] - Restricted argument count check to the void return case. There were some issues here: * a check for mismatching count is too strict because it is legal to omit return values * it failed to detect returning multiple values in a single expression. --- src/scripting/backend/codegen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 6d06f22f9f..039a21dabf 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -10640,7 +10640,7 @@ FxExpression *FxReturnStatement::Resolve(FCompileContext &ctx) PPrototype *retproto; - if (ctx.ReturnProto != nullptr && ctx.ReturnProto->ReturnTypes.Size() != Args.Size()) + if (ctx.ReturnProto != nullptr && ctx.ReturnProto->ReturnTypes.Size() == 0 && ctx.ReturnProto->ReturnTypes.Size() != Args.Size()) { int severity = ctx.Version >= MakeVersion(3, 7) ? MSG_ERROR : MSG_WARNING; ScriptPosition.Message(severity, "Incorrect number of return values. Got %u, but expected %u", Args.Size(), ctx.ReturnProto->ReturnTypes.Size());