Ejemplo n.º 1
0
 internal static Expression[] GenTypedArgs(GenContext context, ParameterInfo[] parms, IPersistentVector args)
 {
     Expression[] exprs = new Expression[parms.Length];
     for (int i = 0; i < parms.Length; i++)
         exprs[i] = GenTypedArg(context,parms[i].ParameterType, (Expr)args.nth(i));
     return exprs;
 }
Ejemplo n.º 2
0
        public override Expression GenDlr(GenContext context)
        {
            Expression fn = _fexpr.GenDlr(context);
            fn = Expression.Convert(fn, typeof(IFn));

            int argCount = _args.count();

            Expression[] args = new Expression[argCount];

            for (int i = 0; i < argCount; i++ )
                args[i] = Compiler.MaybeBox(((Expr)_args.nth(i)).GenDlr(context));

            Expression call = GenerateInvocation(fn, args);

            return call;
        }
Ejemplo n.º 3
0
        private Expression GenDlrViaReflection(GenContext context)
        {
            Expression[] parms = new Expression[_args.count()];
            for ( int i=0; i<_args.count(); i++ )
                parms[i] = Compiler.MaybeBox(((Expr)_args.nth(i)).GenDlr(context));

            Expression[] moreArgs = new Expression[3];
            moreArgs[0] = Expression.Constant(_methodName);
            moreArgs[1] = Expression.Constant(_type);
            moreArgs[2] = Expression.NewArrayInit(typeof(object), parms);

            return Expression.Call(Compiler.Method_Reflector_CallStaticMethod, moreArgs);
        }
Ejemplo n.º 4
0
        private static Expression GenerateInvocation(Type returnType, Expression fn, Expression[] args)
        {
            MethodInfo mi;
            Expression[] actualArgs;

            if (args.Length <= Compiler.MAX_POSITIONAL_ARITY)
            {
                mi = Compiler.Methods_IFn_invoke[args.Length];
                actualArgs = args;
            }
            else
            {
                // pick up the extended version.
                mi = Compiler.Methods_IFn_invoke[Compiler.MAX_POSITIONAL_ARITY + 1];
                Expression[] leftoverArgs = new Expression[args.Length - Compiler.MAX_POSITIONAL_ARITY];
                Array.ConstrainedCopy(args, Compiler.MAX_POSITIONAL_ARITY, leftoverArgs, 0, args.Length - Compiler.MAX_POSITIONAL_ARITY);

                Expression restArg = Expression.NewArrayInit(typeof(object), leftoverArgs);

                actualArgs = new Expression[Compiler.MAX_POSITIONAL_ARITY + 1];
                Array.ConstrainedCopy(args, 0, actualArgs, 0, Compiler.MAX_POSITIONAL_ARITY);
                actualArgs[Compiler.MAX_POSITIONAL_ARITY] = restArg;
            }

            Expression call = Expression.Call(fn, mi, actualArgs);
            // Java version doesn't seem to do this.  Instead, its InvokeExpression carries the type information so someone else can use it.
            // Not sure if this is useful here.
            if (returnType != null)
                call = Expression.Convert(call, returnType);

            return call;
        }
Ejemplo n.º 5
0
        private static Expression GenerateInvocation(Expression fn, Expression[] args)
        {
            MethodInfo mi;
            Expression[] actualArgs;

            if (args.Length <= Compiler.MAX_POSITIONAL_ARITY)
            {
                mi = Compiler.Methods_IFn_invoke[args.Length];
                actualArgs = args;
            }
            else
            {
                // pick up the extended version.
                mi = Compiler.Methods_IFn_invoke[Compiler.MAX_POSITIONAL_ARITY + 1];
                Expression[] leftoverArgs = new Expression[args.Length - Compiler.MAX_POSITIONAL_ARITY];
                Array.Copy(args, Compiler.MAX_POSITIONAL_ARITY, leftoverArgs, 0, args.Length - Compiler.MAX_POSITIONAL_ARITY);

                Expression restArg = Expression.NewArrayInit(typeof(object), leftoverArgs);

                actualArgs = new Expression[Compiler.MAX_POSITIONAL_ARITY + 1];
                Array.Copy(args, 0, actualArgs, 0, Compiler.MAX_POSITIONAL_ARITY);
                actualArgs[Compiler.MAX_POSITIONAL_ARITY] = restArg;
            }

            Expression call = Expression.Call(fn, mi, actualArgs);

            return call;
        }
Ejemplo n.º 6
0
        internal static Expression MaybeBox(Expression expr)
        {
            if (expr.Type == typeof(void))
                // I guess we'll pass a void.  This happens when we have a throw, for example.
                return Expression.Block(expr, Expression.Default(typeof(object)));

            return expr.Type.IsValueType
                ? Expression.Convert(expr, typeof(object))
                : expr;
        }
Ejemplo n.º 7
0
        internal static Expression[] GenTypedArgArray(GenContext context, ParameterInfo[] infos, IPersistentVector args)
        {
            Expression[] exprs = new Expression[args.count()];

            for (int i = 0; i < infos.Length; i++)
            {
                Expr e = (Expr)args.nth(i);
                // Java: this is in a try/catch, where the catch prints a stack trace
                if (MaybePrimitiveType(e) == infos[i].ParameterType)
                    exprs[i] = ((MaybePrimitiveExpr)e).GenDlrUnboxed(context);
                else
                    // Java follows this with: HostExpr.emitUnboxArg(fn, gen, parameterTypes[i]);
                    //exprs[i] = e.GenDlr(context);
                    exprs[i] = Expression.Convert(e.GenDlr(context), infos[i].ParameterType); ;
            }
            return exprs;
        }
Ejemplo n.º 8
0
        internal static Expression GenArgArray(GenContext context, IPersistentVector args)
        {
            Expression[] exprs = new Expression[args.count()];

            for (int i = 0; i < args.count(); i++)
            {
                Expr arg = (Expr)args.nth(i);
                exprs[i] = Compiler.MaybeBox(arg.GenDlr(context));
            }

            Expression argArray = Expression.NewArrayInit(typeof(object), exprs);
            return argArray;
        }
Ejemplo n.º 9
0
 static Expression[] MaybeBox(Expression[] args)
 {
     // TODO: avoid copying array if not necessary
     Expression[] boxedArgs = new Expression[args.Length];
     for (int i1 = 0; i1 < args.Length; ++i1)
         boxedArgs[i1] = MaybeBox(args[i1]);
     return boxedArgs;
 }