예제 #1
0
        private void EmitConstant(object value, Type type)
        {
            // Try to emit the constant directly into IL
            if (ILGen.CanEmitConstant(value, type))
            {
                _ilg.EmitConstant(value, type);
                return;
            }

            _boundConstants.EmitConstant(this, value, type);
        }
예제 #2
0
        protected internal override Expression VisitConstant(ConstantExpression node)
        {
            // If we're in Quote, we can ignore constants completely
            if (_inQuote)
            {
                return(node);
            }

            // Constants that can be emitted into IL don't need to be stored on
            // the delegate
            if (ILGen.CanEmitConstant(node.Value, node.Type))
            {
                return(node);
            }

            _constants.Peek().AddReference(node.Value, node.Type);
            return(node);
        }
        internal void EmitConstant(LambdaCompiler lc, object value, Type type)
        {
            Debug.Assert(!ILGen.CanEmitConstant(value, type));

            if (!lc.CanEmitBoundConstants)
            {
                throw Error.CannotCompileConstant(value);
            }

            LocalBuilder local;

            if (_cache.TryGetValue(new TypedConstant(value, type), out local))
            {
                lc.IL.Emit(OpCodes.Ldloc, local);
                return;
            }
            EmitConstantsArray(lc);
            EmitConstantFromArray(lc, value, type);
        }