Skip to content

Commit

Permalink
当值类型无override方法时,一些编译器仍然生成Constrained,这种情况下之前的处理在函数含参数时处理不当,fix Tence…
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Dec 12, 2019
1 parent 5ac9693 commit 1f73995
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
13 changes: 12 additions & 1 deletion Source/VSProj/Src/Core/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,18 @@ AnonymousStorey anonyObj
evaluationStackPointer = rhs;
}
break;
//Constrained//0.04714472% delete
case Code.Constrained://0.04714472%
{
var lastInstruction = pc - 1;
var type = externTypes[pc->Operand];
var ptr = evaluationStackPointer - 1 - lastInstruction->Operand;
var obj = EvaluationStackOperation.ToObject(evaluationStackBase, ptr, managedStack, type, this);
var pos = (int)(ptr - evaluationStackBase);
managedStack[pos] = obj;
ptr->Value1 = pos;
ptr->Type = ValueType.Object;
}
break;
case Code.Switch://0.04518777%
{
int val = (evaluationStackPointer - 1)->Value1;
Expand Down
19 changes: 7 additions & 12 deletions Source/VSProj/Src/Tools/CodeTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ bool checkILAndGetOffset(MethodDefinition method,
isCompilerGeneratedPlainObject(mr.DeclaringType)))
{
var md = mr as MethodDefinition;
if (md == null)//闭包中调用一个泛型,在unity2018的.net 3.5设置下,编译器是先生成一个泛型的闭包实现,然后实例化,很奇怪的做法,老版本unity,新unity的.net 4.0设置都不会这样,先返回false,不支持这种编译器
{
return false;
if (md == null)//闭包中调用一个泛型,在unity2018的.net 3.5设置下,编译器是先生成一个泛型的闭包实现,然后实例化,很奇怪的做法,老版本unity,新unity的.net 4.0设置都不会这样,先返回false,不支持这种编译器
{
return false;
}
if (md.Body != null && !checkILAndGetOffset(md, md.Body.Instructions))
{
Expand Down Expand Up @@ -1407,15 +1407,10 @@ unsafe MethodIdInfo getMethodId(MethodReference callee, MethodDefinition caller,
}
if (constrainedType.IsValueType && !hasOverrideMethod)
{
code[code.Count - 2] = new Core.Instruction
{
Code = Core.Code.Ldobj,
Operand = lastInstruction.Operand,
};
code[code.Count - 1] = new Core.Instruction
{
Code = Core.Code.Box,
Operand = lastInstruction.Operand,
code[code.Count - 2] = new Core.Instruction
{
Code = Core.Code.Nop,
Operand = methodToCall.Parameters.Count,
};
}
//code.RemoveAt(code.Count - 1);
Expand Down

0 comments on commit 1f73995

Please sign in to comment.