Skip to content

Commit

Permalink
显示push装箱null的话,把null放进mStack中
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed May 2, 2020
1 parent 12d4b59 commit dbe831e
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public object Run(ILMethod method, object instance, object[] p)
}

stack.PushFrame(ref frame);

int locBase = mStack.Count;
//Managed Stack reserved for local variable
for (int i = 0; i < method.LocalVariableCount; i++)
Expand Down Expand Up @@ -1773,7 +1773,7 @@ public object Run(ILMethod method, object instance, object[] p)
if (obj == null)
throw new NullReferenceException();
ilm = ((ILTypeInstance)obj).Type.GetVirtualMethod(ilm) as ILMethod;
}
}
}
esp = Execute(ilm, esp, out unhandledException);
ValueTypeBasePointer = bp;
Expand Down Expand Up @@ -2042,15 +2042,15 @@ public object Run(ILMethod method, object instance, object[] p)
StackObject* fieldAddr;
if (ft is ILType)
{
fieldAddr = Minus(ILIntepreter.ResolveReference(objRef), (int)ip->TokenLong + 1);
fieldAddr = Minus(ILIntepreter.ResolveReference(objRef), (int)ip->TokenLong + 1);
}
else
{
fieldAddr = Minus(ILIntepreter.ResolveReference(objRef), ((CLRType)ft).FieldIndexMapping[(int)ip->TokenLong] + 1);
}
StackObject valRef = *dst;
dst->ObjectType = ObjectTypes.StackObjectReference;
*(long*)&dst->Value = (long) fieldAddr;
*(long*)&dst->Value = (long)fieldAddr;
FreeStackValueType(&valRef);
}
else
Expand Down Expand Up @@ -2438,7 +2438,7 @@ public object Run(ILMethod method, object instance, object[] p)
stack.AllocValueType(esp, type);
objRef = esp + 1;
objRef->ObjectType = ObjectTypes.StackObjectReference;
*(long*)&objRef->Value = (long)esp;
*(long*)&objRef->Value = (long)esp;
objRef++;
}
else
Expand Down Expand Up @@ -2930,7 +2930,7 @@ public object Run(ILMethod method, object instance, object[] p)
}
else
{
if(objRef->ObjectType== ObjectTypes.ValueTypeObjectReference)
if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference)
{
dst = ILIntepreter.ResolveReference(objRef);
var vt = domain.GetType(dst->Value);
Expand Down Expand Up @@ -3210,7 +3210,7 @@ public object Run(ILMethod method, object instance, object[] p)
{
stack.ClearValueTypeObject(type, ILIntepreter.ResolveReference(objRef));
}
else if(type.IsPrimitive)
else if (type.IsPrimitive)
StackObject.Initialized(objRef, type);
}

Expand All @@ -3233,7 +3233,7 @@ public object Run(ILMethod method, object instance, object[] p)
{
case ObjectTypes.Integer:
{
if (tclr != typeof(int) && tclr != typeof(bool) && tclr != typeof(short) && tclr != typeof(byte) && tclr != typeof(ushort) && tclr !=typeof(uint))
if (tclr != typeof(int) && tclr != typeof(bool) && tclr != typeof(short) && tclr != typeof(byte) && tclr != typeof(ushort) && tclr != typeof(uint))
{
oriRef->ObjectType = ObjectTypes.Null;
oriRef->Value = -1;
Expand Down Expand Up @@ -3360,7 +3360,7 @@ public object Run(ILMethod method, object instance, object[] p)
ILTypeInstance[] ilArr = (ILTypeInstance[])arr;
if (type.IsValueType)
{
for(int i = 0; i < cnt->Value; i++)
for (int i = 0; i < cnt->Value; i++)
{
ilArr[i] = ((ILType)type).Instantiate(true);
}
Expand Down Expand Up @@ -4240,7 +4240,7 @@ void CloneStackValueType(StackObject* src, StackObject* dst, IList<object> mStac
stack.AllocValueType(dst, AppDomain.GetType(descriptor->Value));
StackObject* dstDescriptor = ILIntepreter.ResolveReference(dst);
int cnt = descriptor->ValueLow;
for(int i = 0; i < cnt; i++)
for (int i = 0; i < cnt; i++)
{
StackObject* val = Minus(descriptor, i + 1);
CopyToValueTypeField(dstDescriptor, i, val, mStack);
Expand All @@ -4262,7 +4262,7 @@ void CopyStackValueType(StackObject* src, StackObject* dst, IList<object> mStack
if (!CanCastTo(descriptor, dstDescriptor))
throw new InvalidCastException();
int cnt = descriptor->ValueLow;
for(int i = 0; i < cnt; i++)
for (int i = 0; i < cnt; i++)
{
StackObject* srcVal = Minus(descriptor, i + 1);
StackObject* dstVal = Minus(dstDescriptor, i + 1);
Expand All @@ -4285,7 +4285,7 @@ void CopyStackValueType(StackObject* src, StackObject* dst, IList<object> mStack
}
}

void CopyValueTypeToStack(StackObject*dst, object ins, IList<object> mStack)
void CopyValueTypeToStack(StackObject* dst, object ins, IList<object> mStack)
{
if (ins is ILTypeInstance)
{
Expand Down Expand Up @@ -4328,7 +4328,7 @@ void CopyToValueTypeField(StackObject* obj, int idx, StackObject* val, IList<obj
}
else
{
mStack[dst->Value] = CheckAndCloneValueType(mStack[val->Value], domain);
mStack[dst->Value] = CheckAndCloneValueType(mStack[val->Value], domain);
}
}
break;
Expand Down Expand Up @@ -4374,7 +4374,7 @@ void StLocSub(StackObject* esp, StackObject* v, StackObject* bp, int idx, IList<
var ct = domain.GetType(dst->Value) as CLRType;
var binder = ct.ValueTypeBinder;
binder.CopyValueTypeToStack(obj, dst, mStack);
}
}
}
else
{
Expand Down Expand Up @@ -4422,7 +4422,7 @@ public object RetriveObject(StackObject* esp, IList<object> mStack)
else
{
var t = AppDomain.GetType(obj.GetType());
obj = ((CLRType) t).GetFieldValue(idx, obj);
obj = ((CLRType)t).GetFieldValue(idx, obj);
}
}
break;
Expand Down Expand Up @@ -5275,7 +5275,7 @@ public static void UnboxObject(StackObject* esp, object obj, IList<object> mStac
{
esp->ObjectType = ObjectTypes.Integer;
esp->Value = (sbyte)obj;
}
}
else
throw new NotImplementedException();
}
Expand Down Expand Up @@ -5313,7 +5313,14 @@ public static void UnboxObject(StackObject* esp, object obj, IList<object> mStac
}
else
{
return PushNull(esp);
if (isBox)
{
esp->ObjectType = ObjectTypes.Object;
esp->Value = mStack.Count;
mStack.Add(obj);
}
else
return PushNull(esp);
}
return esp + 1;
}
Expand Down

0 comments on commit dbe831e

Please sign in to comment.