void EmitObjectInteger (EmitContext ec, object k)
{
if (k is int)
ec.EmitInt ((int) k);
else if (k is Constant) {
EmitObjectInteger (ec, ((Constant) k).GetValue ());
}
else if (k is uint)
ec.EmitInt (unchecked ((int) (uint) k));
else if (k is long)
{
if ((long) k >= int.MinValue && (long) k <= int.MaxValue)
{
ec.EmitInt ((int) (long) k);
ec.Emit (OpCodes.Conv_I8);
}
else
ec.EmitLong ((long) k);
}
else if (k is ulong)
{
ulong ul = (ulong) k;
if (ul < (1L<<32))
{
ec.EmitInt (unchecked ((int) ul));
ec.Emit (OpCodes.Conv_U8);
}
else
{
ec.EmitLong (unchecked ((long) ul));
}
}
else if (k is char)
ec.EmitInt ((int) ((char) k));
else if (k is sbyte)
ec.EmitInt ((int) ((sbyte) k));
else if (k is byte)
ec.EmitInt ((int) ((byte) k));
else if (k is short)
ec.EmitInt ((int) ((short) k));
else if (k is ushort)
ec.EmitInt ((int) ((ushort) k));
else if (k is bool)
ec.EmitInt (((bool) k) ? 1 : 0);
else
throw new Exception ("Unhandled case");
}