Skip to content

Commit

Permalink
fixed Ourpalm#345
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Jul 2, 2020
1 parent c468cab commit f1935f6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
18 changes: 9 additions & 9 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public object Run(ILMethod method, object instance, object[] p)
Free(objRef);
if (obj is ILTypeInstance)
{
((ILTypeInstance)obj).PushToStack(idx, objRef, AppDomain, mStack);
((ILTypeInstance)obj).PushToStack(idx, objRef, this, mStack);
}
else
{
Expand All @@ -462,7 +462,7 @@ public object Run(ILMethod method, object instance, object[] p)
Free(objRef);
if (t is ILType)
{
((ILType)t).StaticInstance.PushToStack(idx, objRef, AppDomain, mStack);
((ILType)t).StaticInstance.PushToStack(idx, objRef, this, mStack);
}
else
{
Expand Down Expand Up @@ -2013,7 +2013,7 @@ public object Run(ILMethod method, object instance, object[] p)
if (obj is ILTypeInstance)
{
ILTypeInstance instance = obj as ILTypeInstance;
instance.PushToStack((int)ip->TokenLong, ret, AppDomain, mStack);
instance.PushToStack((int)ip->TokenLong, ret, this, mStack);
}
else
{
Expand Down Expand Up @@ -2123,7 +2123,7 @@ public object Run(ILMethod method, object instance, object[] p)
if (type is ILType)
{
ILType t = type as ILType;
t.StaticInstance.PushToStack((int)ip->TokenLong, esp, AppDomain, mStack);
t.StaticInstance.PushToStack((int)ip->TokenLong, esp, this, mStack);
esp++;
}
else
Expand Down Expand Up @@ -2166,7 +2166,7 @@ public object Run(ILMethod method, object instance, object[] p)
if (type is ILType)
{
ILType t = type as ILType;
t.StaticInstance.PushToStack((int)ip->TokenLong, esp, AppDomain, mStack);
t.StaticInstance.PushToStack((int)ip->TokenLong, esp, this, mStack);
}
else
throw new NotImplementedException();
Expand Down Expand Up @@ -2599,7 +2599,7 @@ public object Run(ILMethod method, object instance, object[] p)
var owner = mStack[objRef2->Value] as ILTypeInstance;
int idx = objRef2->ValueLow;
//Free(objRef);
owner.PushToStack(idx, objRef, AppDomain, mStack);
owner.PushToStack(idx, objRef, this, mStack);
ins.AssignFromStack(0, objRef, AppDomain, mStack);
ins.Boxed = true;
}
Expand All @@ -2609,7 +2609,7 @@ public object Run(ILMethod method, object instance, object[] p)
var st = AppDomain.GetType(objRef2->Value) as ILType;
int idx = objRef2->ValueLow;
//Free(objRef);
st.StaticInstance.PushToStack(idx, objRef, AppDomain, mStack);
st.StaticInstance.PushToStack(idx, objRef, this, mStack);
ins.AssignFromStack(0, objRef, AppDomain, mStack);
ins.Boxed = true;
}
Expand Down Expand Up @@ -3055,7 +3055,7 @@ public object Run(ILMethod method, object instance, object[] p)
var res = ((ILTypeInstance)obj);
if (res is ILEnumTypeInstance)
{
res.PushToStack(0, objRef, AppDomain, mStack);
res.PushToStack(0, objRef, this, mStack);
}
else
{
Expand Down Expand Up @@ -4881,7 +4881,7 @@ void LoadFromFieldReference(object obj, int idx, StackObject* dst, IList<object>
{
if (obj is ILTypeInstance)
{
((ILTypeInstance)obj).PushToStack(idx, dst, AppDomain, mStack);
((ILTypeInstance)obj).PushToStack(idx, dst, this, mStack);
}
else
{
Expand Down
29 changes: 24 additions & 5 deletions ILRuntime/Runtime/Intepreter/ILTypeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using ILRuntime.CLR.Method;
using ILRuntime.CLR.TypeSystem;
using ILRuntime.Runtime.Stack;
using ILRuntime.Runtime.Enviorment;

namespace ILRuntime.Runtime.Intepreter
{
public class ILTypeStaticInstance : ILTypeInstance
Expand Down Expand Up @@ -361,15 +363,17 @@ internal unsafe void PushFieldAddress(int fieldIdx, StackObject* esp, IList<obje
esp->ValueLow = fieldIdx;
}

internal unsafe void PushToStack(int fieldIdx, StackObject* esp, Enviorment.AppDomain appdomain, IList<object> managedStack)
internal unsafe void PushToStack(int fieldIdx, StackObject* esp, ILIntepreter intp, IList<object> managedStack)
{
if (fieldIdx < fields.Length && fieldIdx >= 0)
PushToStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack);
{
PushToStackSub(ref fields[fieldIdx], fieldIdx, esp, managedStack, intp);
}
else
{
if (Type.FirstCLRBaseType != null && Type.FirstCLRBaseType is Enviorment.CrossBindingAdaptor)
{
CLRType clrType = appdomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType;
CLRType clrType = intp.AppDomain.GetType(((Enviorment.CrossBindingAdaptor)Type.FirstCLRBaseType).BaseCLRType) as CLRType;
//if(!clrType.CopyFieldToStack(fieldIdx, clrInstance,))
ILIntepreter.PushObject(esp, managedStack, clrType.GetFieldValue(fieldIdx, clrInstance));
}
Expand All @@ -378,14 +382,29 @@ internal unsafe void PushToStack(int fieldIdx, StackObject* esp, Enviorment.AppD
}
}

unsafe void PushToStackSub(ref StackObject field, int fieldIdx, StackObject* esp, IList<object> managedStack)
unsafe void PushToStackSub(ref StackObject field, int fieldIdx, StackObject* esp, IList<object> managedStack, ILIntepreter intp)
{
*esp = field;
if (field.ObjectType >= ObjectTypes.Object)
{
var obj = managedObjs[fieldIdx];
if (obj != null)
{
var ot = obj.GetType();
ValueTypeBinder binder;
if (ot.IsValueType && type.AppDomain.ValueTypeBinders.TryGetValue(ot, out binder))
{
intp.AllocValueType(esp, binder.CLRType);
var dst = ILIntepreter.ResolveReference(esp);
binder.CopyValueTypeToStack(obj, dst, managedStack);
return;
}
}
*esp = field;
esp->Value = managedStack.Count;
managedStack.Add(managedObjs[fieldIdx]);
}
else
*esp = field;
}

internal unsafe void CopyValueTypeToStack(StackObject* ptr, IList<object> mStack)
Expand Down
2 changes: 2 additions & 0 deletions ILRuntimeTest/TestFramework/TestVector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ public struct TestVector3NoBinding
public float x, y, z;

static TestVector3NoBinding mZero = new TestVector3NoBinding(0, 0, 0);
static TestVector3NoBinding mOne = new TestVector3NoBinding(1, 1, 1);

public static TestVector3NoBinding zero => mZero;
public static TestVector3NoBinding one => mOne;

public TestVector3NoBinding(float x, float y, float z)
{
Expand Down
34 changes: 34 additions & 0 deletions TestCases/TestValueTypeBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,39 @@ public static void UnitTest_10038()
if(rawPos.y != 1122333)
throw new AccessViolationException();
}

public static void UnitTest_10039()
{
Test10039 obj = new Test10039();
obj.Test();
}

class Test10039
{
TestVector3 m;
TestVector3NoBinding m2;
public void Test()
{
m = new TestVector3();
m2 = TestVector3NoBinding.zero;
UnitTest_10039Sub(m);
UnitTest_10039Sub2(m2);
}
void UnitTest_10039Sub(TestVector3 arg)
{
arg = TestVector3.One2;

if (arg.X != 1)
throw new Exception();
}

void UnitTest_10039Sub2(TestVector3NoBinding arg)
{
arg = TestVector3NoBinding.one;

if (arg.x != 1)
throw new Exception();
}
}
}
}

0 comments on commit f1935f6

Please sign in to comment.