Skip to content

Commit

Permalink
Fixed a bug with constrained instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Mar 7, 2017
1 parent 02e8afc commit a36831f
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,8 @@ public object Run(ILMethod method, object instance, object[] p)
break;
case OpCodeEnum.Constrained:
{
var obj = GetObjectAndResolveReference(esp - 1);
var objRef = esp - 1;
var obj = GetObjectAndResolveReference(objRef);
var type = domain.GetType(ip->TokenInteger);
if (type != null)
{
Expand All @@ -2469,8 +2470,43 @@ public object Run(ILMethod method, object instance, object[] p)
if (t.IsEnum)
{
ILEnumTypeInstance ins = new ILEnumTypeInstance(t);
ins.AssignFromStack(0, obj, AppDomain, mStack);
ins.Boxed = true;
switch (obj->ObjectType)
{
case ObjectTypes.FieldReference:
{
var owner = mStack[obj->Value] as ILTypeInstance;
int idx = obj->ValueLow;
Free(objRef);
owner.PushToStack(idx, objRef, AppDomain, mStack);
ins.AssignFromStack(0, objRef, AppDomain, mStack);
ins.Boxed = true;
}
break;
case ObjectTypes.StaticFieldReference:
{
var st = AppDomain.GetType(obj->Value) as ILType;
int idx = obj->ValueLow;
Free(objRef);
st.StaticInstance.PushToStack(idx, objRef, AppDomain, mStack);
ins.AssignFromStack(0, objRef, AppDomain, mStack);
ins.Boxed = true;
}
break;
case ObjectTypes.ArrayReference:
{
var arr = mStack[obj->Value];
var idx = obj->ValueLow;
Free(objRef);
LoadFromArrayReference(arr, idx, objRef, t, mStack);
ins.AssignFromStack(0, objRef, AppDomain, mStack);
ins.Boxed = true;
}
break;
default:
ins.AssignFromStack(0, obj, AppDomain, mStack);
ins.Boxed = true;
break;
}
esp = PushObject(esp - 1, mStack, ins);
}
else
Expand Down

0 comments on commit a36831f

Please sign in to comment.