Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Fixing interpreter for Increment and Decrement nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed Oct 10, 2015
1 parent daa6140 commit 7f5d923
Showing 1 changed file with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public override string ToString()

internal abstract class IncrementInstruction : Instruction
{
private static Instruction s_int16, s_int32, s_int64, s_UInt16, s_UInt32, s_single, s_double;
private static Instruction s_int16, s_int32, s_int64, s_UInt16, s_UInt32, s_UInt64, s_single, s_double;

public override int ConsumedStack { get { return 1; } }
public override int ProducedStack { get { return 1; } }
Expand Down Expand Up @@ -763,7 +763,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int16)unchecked(1 + (Int16)obj));
frame.Push(unchecked((Int16)(1 + (Int16)obj)));
}
return +1;
}
Expand All @@ -780,7 +780,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int64)unchecked(1 + (Int64)obj));
frame.Push(unchecked((Int64)(1 + (Int64)obj)));
}
return +1;
}
Expand All @@ -797,7 +797,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int16)unchecked(1 + (UInt16)obj));
frame.Push(unchecked((UInt16)(1 + (UInt16)obj)));
}
return +1;
}
Expand All @@ -814,7 +814,24 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int32)unchecked(1 + (UInt32)obj));
frame.Push(unchecked((UInt32)(1 + (UInt32)obj)));
}
return +1;
}
}

internal sealed class IncrementUInt64 : IncrementInstruction
{
public override int Run(InterpretedFrame frame)
{
object obj = frame.Pop();
if (obj == null)
{
frame.Push(null);
}
else
{
frame.Push(unchecked((UInt64)(1 + (UInt64)obj)));
}
return +1;
}
Expand All @@ -831,7 +848,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Single)unchecked(1 + (Single)obj));
frame.Push(unchecked((Single)(1 + (Single)obj)));
}
return +1;
}
Expand All @@ -848,7 +865,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Double)unchecked(1 + (Double)obj));
frame.Push(unchecked((Double)(1 + (Double)obj)));
}
return +1;
}
Expand All @@ -857,13 +874,14 @@ public override int Run(InterpretedFrame frame)
public static Instruction Create(Type type)
{
Debug.Assert(!type.GetTypeInfo().IsEnum);
switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(type))
switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
{
case TypeCode.Int16: return s_int16 ?? (s_int16 = new IncrementInt16());
case TypeCode.Int32: return s_int32 ?? (s_int32 = new IncrementInt32());
case TypeCode.Int64: return s_int64 ?? (s_int64 = new IncrementInt64());
case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new IncrementUInt16());
case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new IncrementUInt32());
case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new IncrementUInt64());
case TypeCode.Single: return s_single ?? (s_single = new IncrementSingle());
case TypeCode.Double: return s_double ?? (s_double = new IncrementDouble());

Expand All @@ -880,7 +898,7 @@ public override string ToString()

internal abstract class DecrementInstruction : Instruction
{
private static Instruction s_int16, s_int32, s_int64, s_UInt16, s_UInt32, s_single, s_double;
private static Instruction s_int16, s_int32, s_int64, s_UInt16, s_UInt32, s_UInt64, s_single, s_double;

public override int ConsumedStack { get { return 1; } }
public override int ProducedStack { get { return 1; } }
Expand Down Expand Up @@ -920,7 +938,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int16)unchecked((Int16)obj - 1));
frame.Push(unchecked((Int16)((Int16)obj - 1)));
}
return +1;
}
Expand All @@ -937,7 +955,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int64)unchecked((Int64)obj - 1));
frame.Push(unchecked((Int64)((Int64)obj - 1)));
}
return +1;
}
Expand All @@ -954,7 +972,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Int16)unchecked((UInt16)obj - 1));
frame.Push(unchecked((UInt16)((UInt16)obj - 1)));
}
return +1;
}
Expand All @@ -971,7 +989,24 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push(unchecked((UInt32)obj - 1));
frame.Push(unchecked((UInt32)((UInt32)obj - 1)));
}
return +1;
}
}

internal sealed class DecrementUInt64 : DecrementInstruction
{
public override int Run(InterpretedFrame frame)
{
object obj = frame.Pop();
if (obj == null)
{
frame.Push(null);
}
else
{
frame.Push(unchecked((UInt64)((UInt64)obj - 1)));
}
return +1;
}
Expand All @@ -988,7 +1023,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push(unchecked((Single)obj - 1));
frame.Push(unchecked((Single)((Single)obj - 1)));
}
return +1;
}
Expand All @@ -1005,7 +1040,7 @@ public override int Run(InterpretedFrame frame)
}
else
{
frame.Push((Double)unchecked((Double)obj - 1));
frame.Push(unchecked((Double)((Double)obj - 1)));
}
return +1;
}
Expand All @@ -1014,13 +1049,14 @@ public override int Run(InterpretedFrame frame)
public static Instruction Create(Type type)
{
Debug.Assert(!type.GetTypeInfo().IsEnum);
switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(type))
switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
{
case TypeCode.Int16: return s_int16 ?? (s_int16 = new DecrementInt16());
case TypeCode.Int32: return s_int32 ?? (s_int32 = new DecrementInt32());
case TypeCode.Int64: return s_int64 ?? (s_int64 = new DecrementInt64());
case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new DecrementUInt16());
case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new DecrementUInt32());
case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new DecrementUInt64());
case TypeCode.Single: return s_single ?? (s_single = new DecrementSingle());
case TypeCode.Double: return s_double ?? (s_double = new DecrementDouble());

Expand Down

0 comments on commit 7f5d923

Please sign in to comment.