Beispiel #1
0
 public static MSAst Convert(BinderState binder, Type type, ConversionResultKind resultKind, MSAst target, OverloadResolverFactory resolverFactory)
 {
     return(MSAst.Dynamic(
                binder.Convert(type, resultKind, resolverFactory),
                type,
                target));
 }
 public MSAst Register(MSAst registeredTo)
 {
     return(MSAst.Dynamic(
                LanguageContext.CreateSetMemberBinder(Name, false, true, true),
                typeof(object),
                registeredTo,
                TransformClass()
                ));
 }
Beispiel #3
0
 public System.Linq.Expressions.Expression Register(System.Linq.Expressions.Expression registeredTo)
 {
     return(MSAst.Dynamic(
                LanguageContext.CreateSetMemberBinder(Name, false, true, true),
                typeof(object),
                registeredTo,
                TransformClass()
                ));
 }
        public MSAst TransformClass()
        {
            var defaultContext = MSAst.Constant(null);
            var classFinders   = new List <MSAst>();

            foreach (var baseClass in BaseClasses)
            {
                classFinders.Add(MSAst.Lambda <Func <Class> >(MSAst.Convert(MSAst.Dynamic(GlobalParent.LanguageContext.CreateGetMemberBinder(baseClass, false), typeof(object), GlobalParent.Context), typeof(Class))));
            }
            var members = new Dictionary <string, MSAst>();

            foreach (var func in Functions)
            {
                members[func.Name] = func.TransformFunction(defaultContext);
            }
            foreach (var prop in Properties)
            {
                members[prop.Name] = prop.TransformProperty(defaultContext);
            }
            var membersArg = MSAst.Call(
                (System.Reflection.MethodInfo)Utils.GetMember(() => Enumerable.Zip <string, object, KeyValuePair <string, object> >(null, null, null)),
                MSAst.Constant(members.Keys),
                MSAst.NewArrayInit(typeof(object), members.Values),
                (System.Linq.Expressions.Expression <Func <string, object, KeyValuePair <string, object> > >)((x, y) => new KeyValuePair <string, object>(x, y))
                );
            var fields = new Dictionary <string, System.Linq.Expressions.Expression <Func <object, object> > >();

            foreach (var vd in VariableDeclarations)
            {
                foreach (var initializer in vd.Initializers)
                {
                    if (initializer.Value != null)
                    {
                        fields[initializer.Key] = MSAst.Lambda <Func <object, object> >(initializer.Value.TransformRead(), _context);
                    }
                    else
                    {
                        fields[initializer.Key] = MSAst.Lambda <Func <object, object> >(MSAst.Constant(Builtins.Void.Value), _context);
                    }
                }
            }
            var fieldsArg = MSAst.Call(
                (System.Reflection.MethodInfo)Utils.GetMember(() => Enumerable.Zip <string, Func <object, object>, KeyValuePair <string, Func <object, object> > >(null, null, null)),
                MSAst.Constant(fields.Keys),
                MSAst.NewArrayInit(typeof(Func <object, object>), fields.Values),
                (System.Linq.Expressions.Expression <Func <string, Func <object, object>, KeyValuePair <string, Func <object, object> > > >)((x, y) => new KeyValuePair <string, Func <object, object> >(x, y))
                );

            return(MSAst.New((System.Reflection.ConstructorInfo)Utils.GetMember(() => new Class(null, null, null, null)), MSAst.Constant(Name), MSAst.NewArrayInit(typeof(Func <Class>), classFinders), membersArg, fieldsArg));
        }
        public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
        {
            var combinedArgs = new Expr[args.Length + 1];

            combinedArgs[0] = target.Expression;
            Array.Copy(args.Select(a => a.Expression).ToArray(), 0, combinedArgs, 1, args.Length);

            var restrictions = target.Restrictions.Merge(BindingRestrictions.Combine(args));
            var expression   =
                Expr.Dynamic(
                    Context.DynamicCache.GetInvokeBinder(new CallInfo(args.Length)),
                    typeof(object),
                    combinedArgs);

            return(new DynamicMetaObject(expression, restrictions));
        }
Beispiel #6
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                var expression = Expr.Dynamic(new LuaGetMemberBinder(binder.Name), typeof(object), Expression);

                return(binder.FallbackInvoke(new DynamicMetaObject(expression, Restrictions), args, null));
            }
Beispiel #7
0
        public static Expr ConvertToBoolean(Context context, Expr expression)
        {
            var convertBinder = Context.DynamicCache.GetConvertBinder(typeof(bool));

            return(Expr.Dynamic(convertBinder, typeof(bool), expression));
        }
Beispiel #8
0
        public static Expr ConvertToNumber(Context context, Expr expression)
        {
            var convertBinder = Context.DynamicCache.GetConvertBinder(typeof(double));

            return(Expr.Dynamic(convertBinder, typeof(double), expression));
        }