Actually pass PFunction to OP_NEW

This commit is contained in:
ZZYZX 2017-02-16 04:14:21 +02:00
parent 7d3663500f
commit 0819dd8d89
3 changed files with 6 additions and 6 deletions

View file

@ -5023,7 +5023,7 @@ FxNew::FxNew(FxExpression *v)
{
val = new FxClassTypeCast(NewClassPointer(RUNTIME_CLASS(DObject)), v, false);
ValueType = NewPointer(RUNTIME_CLASS(DObject));
CallingClass = nullptr;
CallingFunction = nullptr;
}
//==========================================================================
@ -5048,7 +5048,7 @@ FxExpression *FxNew::Resolve(FCompileContext &ctx)
CHECKRESOLVED();
SAFE_RESOLVE(val, ctx);
CallingClass = (PClass*)ctx.Class;
CallingFunction = ctx.Function;
if (!val->ValueType->IsKindOf(RUNTIME_CLASS(PClassPointer)))
{
ScriptPosition.Message(MSG_ERROR, "Class type expected");
@ -5075,7 +5075,7 @@ ExpEmit FxNew::Emit(VMFunctionBuilder *build)
ExpEmit from = val->Emit(build);
from.Free(build);
ExpEmit to(build, REGT_POINTER);
build->Emit(from.Konst ? OP_NEW_K : OP_NEW, to.RegNum, from.RegNum, build->GetConstantAddress(CallingClass, ATAG_OBJECT));
build->Emit(from.Konst ? OP_NEW_K : OP_NEW, to.RegNum, from.RegNum, build->GetConstantAddress(CallingFunction, ATAG_OBJECT));
return to;
}

View file

@ -1208,7 +1208,7 @@ private:
class FxNew : public FxExpression
{
FxExpression *val;
PClass *CallingClass;
PFunction *CallingFunction;
public:

View file

@ -787,8 +787,8 @@ begin:
{
b = B;
PClass *cls = (PClass*)(pc->op == OP_NEW ? reg.a[b] : konsta[b].v);
PClass *callingcls = (PClass*)konsta[C].o; // [ZZ] due to how this is set, it's always const
if ((cls->ObjectFlags & OF_Abstract) && callingcls != cls) ThrowAbortException(X_OTHER, "Cannot instantiate abstract class %s outside of that class", cls->TypeName.GetChars());
PFunction *callingfunc = (PFunction*)konsta[C].o; // [ZZ] due to how this is set, it's always const
if ((cls->ObjectFlags & OF_Abstract) && (!callingfunc || callingfunc->OwningClass != cls)) ThrowAbortException(X_OTHER, "Cannot instantiate abstract class %s outside of that class", cls->TypeName.GetChars());
reg.a[a] = cls->CreateNew();
reg.atag[a] = ATAG_OBJECT;
NEXTOP;