Пример #1
0
        public static Expression CompileMac(object stuff, Environment environment)
        {
            object args = ((Pair)stuff).First();
            Pair   body = (Pair)((Pair)stuff).Rest();

            string doc = "";

            if ((body.Length() > 1) && (body.First() is string))
            {
                doc  = (string)body.First();
                body = (Pair)body.Rest();
            }

            Pair implicitProgn = new Pair(PROGN, body); // Dangerous if it gets redefined

            object v = Compile(implicitProgn, environment);

            return(Expression.Call(null, makeMacroMethodInfo, Expression.Constant(args), Expression.Constant(v), Expression.Constant(doc), environmentParameter));
        }
Пример #2
0
        public static Expression CompileCall(Pair c, Environment environment)
        {
            string dotNetExpression = ((Symbol)c.First()).Name;

            int n = dotNetExpression.LastIndexOf('.');

            string typeName = dotNetExpression.Substring(0, n);
            string methodName = dotNetExpression.Substring(n + 1);

            Type t = ClrGlue.FindType(typeName, Runtime.Namespaces);

            MemberInfo m = ClrGlue.FindUnambiguousMember(methodName, t, c.Length() - 1);

            if (m == null)
            {
                // If we cant find an unambiguos MemberInfo then we'll
                // have to compile a call to CallStaticMethod instead.
                // This will look for a method again reflectively at
                // runtime, so this will be a performance hit
                Expression[] es = CompileArgs1(c.Rest(), environment);

                Expression[] ees = new Expression[3];

                ees[0] = Expression.Constant(methodName);
                ees[1] = Expression.Constant(t, typeof(Type));
                ees[2] = Expression.NewArrayInit(typeof(object), es);

                return Expression.Call(null, callStaticMethodMethodInfo, ees);
            }
            else
            {
                // We know what we're doing at compile time, so lets compile
                // up the call now.
                // No need for runtime reflection = better performance !!

                if (m is MethodInfo)
                {

                    if (((MethodInfo)m).IsStatic)
                    {
                        Expression[] es = CompileArgsX(c.Rest(), ((MethodInfo)m).GetParameters(), environment);
                        return Expression.Call(null, (MethodInfo)m, es);
                    }
                    else
                    {
                        // Its a virtual call
                        Expression[] es = CompileArgsX(c.Rest().Rest(), ((MethodInfo)m).GetParameters(), environment);
                        Expression o = Compile1(c.Rest().First(),environment);
                        return Expression.Call(o, (MethodInfo)m, es);
                    }
                }

                if (m is PropertyInfo)
                        return Expression.Property(null, (PropertyInfo)m);

                if (m is FieldInfo)
                    return Expression.Field(null, (FieldInfo)m);

                return null;
            }
        }
Пример #3
0
        public static Expression CompileCall(Pair c, Environment environment)
        {
            string dotNetExpression = ((Symbol)c.First()).Name;

            int n = dotNetExpression.LastIndexOf('.');

            string typeName   = dotNetExpression.Substring(0, n);
            string methodName = dotNetExpression.Substring(n + 1);

            Type t = ClrGlue.FindType(typeName, Runtime.Namespaces);

            MemberInfo m = ClrGlue.FindUnambiguousMember(methodName, t, c.Length() - 1);

            if (m == null)
            {
                // If we cant find an unambiguos MemberInfo then we'll
                // have to compile a call to CallStaticMethod instead.
                // This will look for a method again reflectively at
                // runtime, so this will be a performance hit
                Expression[] es = CompileArgs1(c.Rest(), environment);

                Expression[] ees = new Expression[3];

                ees[0] = Expression.Constant(methodName);
                ees[1] = Expression.Constant(t, typeof(Type));
                ees[2] = Expression.NewArrayInit(typeof(object), es);

                return(Expression.Call(null, callStaticMethodMethodInfo, ees));
            }
            else
            {
                // We know what we're doing at compile time, so lets compile
                // up the call now.
                // No need for runtime reflection = better performance !!


                if (m is MethodInfo)
                {
                    if (((MethodInfo)m).IsStatic)
                    {
                        Expression[] es = CompileArgsX(c.Rest(), ((MethodInfo)m).GetParameters(), environment);
                        return(Expression.Call(null, (MethodInfo)m, es));
                    }
                    else
                    {
                        // Its a virtual call
                        Expression[] es = CompileArgsX(c.Rest().Rest(), ((MethodInfo)m).GetParameters(), environment);
                        Expression   o  = Compile1(c.Rest().First(), environment);
                        return(Expression.Call(o, (MethodInfo)m, es));
                    }
                }

                if (m is PropertyInfo)
                {
                    return(Expression.Property(null, (PropertyInfo)m));
                }

                if (m is FieldInfo)
                {
                    return(Expression.Field(null, (FieldInfo)m));
                }

                return(null);
            }
        }