Ejemplo n.º 1
0
        private Expression RewriteCallSite(CallSite site, TypeGen tg)
        {
            IExpressionSerializable serializer = site.Binder as IExpressionSerializable;

            if (serializer == null)
            {
                throw new ArgumentException("Generating code from non-serializable CallSiteBinder.");
            }

            Type siteType = site.GetType();

            FieldBuilder fb   = tg.AddStaticField(siteType, "sf" + (_id++).ToString());
            Expression   init = Expression.Call(siteType.GetMethod("Create"), serializer.CreateExpression());

            _fieldBuilders.Add(fb);
            _fieldInits.Add(init);


            //Type t = init.Type;
            //if (t.IsGenericType)
            //{
            //    Type[] args = t.GetGenericArguments()[0].GetGenericArguments(); ;
            //    // skip the first one, it is the site.
            //    for (int k = 1; k < args.Length; k++)
            //    {
            //        Type p = args[k];
            //        //if (!p.Assembly.GetName().Name.Equals("mscorlib") && !p.Assembly.GetName().Name.Equals("Clojure"))
            //        //    Console.WriteLine("Found {0}", p.ToString());
            //    }
            //}

            // rewrite the node...
            return(Expression.Field(null, fb));
        }
Ejemplo n.º 2
0
        private Expression RewriteCallSite(CallSite site)
        {
            IExpressionSerializable serializer = site.Binder as IExpressionSerializable;

            if (serializer == null)
            {
                throw Error.GenNonSerializableBinder();
            }

            // add the initialization code that we'll generate later into the outermost
            // lambda and then return an index into the array we'll be creating.
            if (_constantPool == null)
            {
                _constantPool = Expression.Variable(typeof(object[]), "$constantPool");
                _constants    = new List <Expression>();
            }

            Type siteType = site.GetType();

            _constants.Add(Expression.Call(siteType.GetMethod("Create"), serializer.CreateExpression()));

            // rewrite the node...
            return(Visit(
                       AstUtils.Convert(
                           Expression.ArrayAccess(_constantPool, Expression.Constant(_constants.Count - 1)),
                           siteType
                           )
                       ));
        }
Ejemplo n.º 3
0
        private Expression RewriteCallSite(CallSite site, TypeGen tg)
        {
            IExpressionSerializable serializer = site.Binder as IExpressionSerializable;

            if (serializer == null)
            {
                throw new ArgumentException("Generating code from non-serializable CallSiteBinder.");
            }

            Type siteType = site.GetType();

            FieldBuilder fb   = tg.AddStaticField(siteType, "sf" + (_id++).ToString());
            Expression   init = Expression.Call(siteType.GetMethod("Create"), serializer.CreateExpression());

            _fieldBuilders.Add(fb);
            _fieldInits.Add(init);

            // rewrite the node...
            return(Expression.Field(null, fb));
        }
Ejemplo n.º 4
0
        private Expression RewriteCallSite(CallSite site)
        {
            IExpressionSerializable serializer = site.Binder as IExpressionSerializable;

            if (serializer == null)
            {
                throw Error.GenNonSerializableBinder();
            }

            EnsureConstantPool();

            Type siteType = site.GetType();

            _constants.Add(Expression.Call(siteType.GetMethod("Create"), serializer.CreateExpression()));

            // rewrite the node...
            return(Visit(
                       AstUtils.Convert(
                           Expression.ArrayAccess(_constantPool, AstUtils.Constant(_constants.Count - 1)),
                           siteType
                           )
                       ));
        }