/// Base class for constants and literals.
/// </summary>
public abstract class Constant : Expression {
-
- protected Constant ()
- {
- eclass = ExprClass.Value;
- }
-
/// <remarks>
/// This is different from ToString in that ToString
/// is supposed to be there for debugging purposes,
public BoolConstant (bool val)
{
type = TypeManager.bool_type;
+ eclass = ExprClass.Value;
Value = val;
}
public ByteConstant (byte v)
{
type = TypeManager.byte_type;
+ eclass = ExprClass.Value;
Value = v;
}
public CharConstant (char v)
{
type = TypeManager.char_type;
+ eclass = ExprClass.Value;
Value = v;
}
public SByteConstant (sbyte v)
{
type = TypeManager.sbyte_type;
+ eclass = ExprClass.Value;
Value = v;
}
public ShortConstant (short v)
{
type = TypeManager.short_type;
+ eclass = ExprClass.Value;
Value = v;
}
public UShortConstant (ushort v)
{
type = TypeManager.ushort_type;
+ eclass = ExprClass.Value;
Value = v;
}
public IntConstant (int v)
{
type = TypeManager.int32_type;
+ eclass = ExprClass.Value;
Value = v;
}
public UIntConstant (uint v)
{
type = TypeManager.uint32_type;
+ eclass = ExprClass.Value;
Value = v;
}
public LongConstant (long v)
{
type = TypeManager.int64_type;
+ eclass = ExprClass.Value;
Value = v;
}
public ULongConstant (ulong v)
{
type = TypeManager.uint64_type;
+ eclass = ExprClass.Value;
Value = v;
}
public FloatConstant (float v)
{
type = TypeManager.float_type;
+ eclass = ExprClass.Value;
Value = v;
}
public DoubleConstant (double v)
{
type = TypeManager.double_type;
+ eclass = ExprClass.Value;
Value = v;
}
public DecimalConstant (decimal d)
{
type = TypeManager.decimal_type;
+ eclass = ExprClass.Value;
Value = d;
}
public override void Emit (EmitContext ec)
{
- throw new Exception ("Implement me");
+ int [] words = Decimal.GetBits (Value);
+
+ //
+ // FIXME: we could optimize this, and call a better
+ // constructor
+ //
+
+ ILGenerator ig = ec.ig;
+
+ IntConstant.EmitInt (ig, words [0]);
+ IntConstant.EmitInt (ig, words [1]);
+ IntConstant.EmitInt (ig, words [2]);
+
+ // sign
+ IntConstant.EmitInt (ig, words [3] >> 31);
+
+ // power
+ IntConstant.EmitInt (ig, (words [3] >> 16) & 0xff);
+
+ ig.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_five_args);
}
}
public StringConstant (string s)
{
type = TypeManager.string_type;
+ eclass = ExprClass.Value;
Value = s;
}