示例#1
0
        public override void Compile(ILProcessor processor, AstListInitializer initializer, CilCompilationContext context)
        {
            var temporaryVariable = context.DefineVariable("temp", initializer.ExpressionType);
            var elementType       = context.ConvertReference(initializer.Elements[0].ExpressionType); // temporary cheating

            processor.EmitLdcI4(initializer.Elements.Count);
            processor.Emit(OpCodes.Newarr, elementType);
            processor.Emit(OpCodes.Stloc, temporaryVariable);
            for (var i = 0; i < initializer.Elements.Count; i++)
            {
                processor.Emit(OpCodes.Ldloc, temporaryVariable);
                processor.EmitLdcI4(i);
                EmitStelem(processor, elementType, initializer.Elements[i], context);
            }

            processor.Emit(OpCodes.Ldloc, temporaryVariable);
        }
示例#2
0
        private static void EmitBigIntegerBytes(ILProcessor processor, BigInteger value, CilCompilationContext context)
        {
            var bytes         = value.ToByteArray();
            var bytesVariable = context.DefineVariable("t", ByteArray); // temporary cheating

            processor.EmitLdcI4(bytes.Length);
            processor.Emit(OpCodes.Newarr, context.ConvertReference(Byte));
            processor.Emit(OpCodes.Stloc, bytesVariable);
            for (var i = 0; i < bytes.Length; i++)
            {
                processor.Emit(OpCodes.Ldloc, bytesVariable);
                processor.EmitLdcI4(i);
                processor.EmitLdcI4(bytes[i]);
                processor.Emit(OpCodes.Stelem_I1);
            }

            processor.Emit(OpCodes.Ldloc, bytesVariable);
        }
示例#3
0
        private static void CompileDecimal(ILProcessor processor, PrimitiveValue value, CilCompilationContext context)
        {
            var @decimal = (Decimal)value.Value;
            var bits     = @decimal.GetBits();

            var bitsVariable = context.DefineVariable("t", Int32Array); // temporary cheating

            processor.EmitLdcI4(bits.Length);
            processor.Emit(OpCodes.Newarr, context.ConvertReference(Int32));
            processor.Emit(OpCodes.Stloc, bitsVariable);
            for (var i = 0; i < bits.Length; i++)
            {
                processor.Emit(OpCodes.Ldloc, bitsVariable);
                processor.EmitLdcI4(i);
                processor.EmitLdcI4(bits[i]);
                processor.Emit(OpCodes.Stelem_I4);
            }
            processor.Emit(OpCodes.Ldloc, bitsVariable);
            processor.Emit(OpCodes.Newobj, context.ConvertReference(NewDecimalFromBits));
        }
示例#4
0
        private static void CompileInteger(ILProcessor processor, PrimitiveValue value, CilCompilationContext context)
        {
            var integer = (Integer)value.Value;

            if (integer.Kind == IntegerKind.Int32)
            {
                processor.EmitLdcI4(integer.Int32Value);
                processor.Emit(OpCodes.Newobj, context.ConvertReference(NewIntegerFromInt32));
            }
            else
            {
                EmitBigIntegerBytes(processor, integer.BigIntegerValue, context);
                processor.Emit(OpCodes.Newobj, context.ConvertReference(NewIntegerFromBytes));
            }
        }