Esempio n. 1
0
        public static Et EtToBoolean(Meta obj)
        {
            if (obj.HasValue && obj.Value == null)
                return Et.Constant(false, typeof(bool));

            if (obj.LimitType == typeof(bool))
                return Et.Convert(obj.Expression, typeof(bool));

            if (obj.LimitType == typeof(double))
                return Et.GreaterThan(
                    Et.Convert(obj.Expression, typeof(double)),
                    Et.Constant(0.0, typeof(double))
                );

            if (obj.LimitType == typeof(Js.Undefined))
                return Et.Constant(false, typeof(bool));

            if (obj.LimitType == typeof(string))
                return Et.GreaterThan(
                    Et.Property(
                        Et.Convert(
                            obj.Expression,
                            typeof(string)
                        ),
                        "Length"
                    ),
                    Et.Constant(0, typeof(int))
                );

            // last step
            return Et.Constant(true, typeof(bool));
        }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="target"></param>
        /// <param name="args"></param>
        /// <param name="instanceRestrict"></param>
        /// <returns></returns>
        internal static Restrict2 BuildCallRestrictions(Meta2 target, Meta2[] args, RestrictFlag flag)
        {
            var restrictions =
                target.Restrictions.Merge(
                    Restrict2.Combine(args)
                );

            if (flag == RestrictFlag.Instance)
            {
                restrictions =
                    restrictions.Merge(
                        Restrict2.GetInstanceRestriction(
                            target.Expression,
                            target.Value
                        )
                    );
            }
            else
            {
                restrictions =
                    restrictions.Merge(
                        Restrict2.GetTypeRestriction(
                            target.Expression,
                            target.LimitType
                        )
                    );
            }

            for (var i = 0; i < args.Length; ++i)
            {
                Restrict2 restr;

                // HasValue and Value == null, means we have a null value
                if (args[i].HasValue && args[i].Value == null)
                {
                    restr =
                        Restrict2.GetInstanceRestriction(
                            args[i].Expression,
                            null
                        );
                }
                else
                {
                    restr =
                        Restrict2.GetTypeRestriction(
                            args[i].Expression,
                            args[i].LimitType
                        );
                }

                restrictions = restrictions.Merge(restr);
            }

            return restrictions;
        }
Esempio n. 3
0
        internal static Restrict2 GetNullHandledTypeRestriction(Meta2 target)
        {
            if (target.HasValue && target.Value == null)
                return Restrict2.GetInstanceRestriction(
                        target.Expression,
                        null
                    );

            return Restrict2.GetTypeRestriction(
                    target.Expression,
                    target.LimitType
                );
        }
 System.Dynamic.DynamicMetaObject CallMethod(
     MethodInfo method,
     System.Linq.Expressions.Expression[] parameters
     )
 {
     var callMethod = new System.Dynamic.DynamicMetaObject(
         System.Linq.Expressions.Expression.Call(
             System.Linq.Expressions.Expression.Convert(Expression, LimitType),
             method,
             parameters),
         System.Dynamic.BindingRestrictions.GetTypeRestriction(Expression, LimitType)
         );
     return callMethod;
 }
Esempio n. 5
0
        public static bool NeedsToDefer(Meta target, Meta[] args, out Meta[] result)
        {
            if (!target.HasValue)
                goto Defer;

            for (int i = 0; i < args.Length; ++i)
            {
                if (!args[i].HasValue)
                    goto Defer;
            }

            result = null;
            return false;

            Defer:
                result = ArrayUtils.Insert(target, args);
                return true;
        }
Esempio n. 6
0
 public virtual System.Dynamic.DynamicMetaObject BindBinaryOperation(System.Dynamic.BinaryOperationBinder binder, System.Dynamic.DynamicMetaObject arg)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 7
0
 public System.Dynamic.DynamicMetaObject FallbackDeleteMember(System.Dynamic.DynamicMetaObject target)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 8
0
 public System.Dynamic.DynamicMetaObject FallbackDeleteIndex(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] indexes)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 9
0
 public System.Dynamic.DynamicMetaObject FallbackCreateInstance(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 10
0
 public System.Dynamic.DynamicMetaObject FallbackConvert(System.Dynamic.DynamicMetaObject target)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 11
0
 public abstract System.Dynamic.DynamicMetaObject FallbackBinaryOperation(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject arg, System.Dynamic.DynamicMetaObject errorSuggestion);
 public System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     throw null;
 }
 public System.Dynamic.DynamicMetaObject FallbackGetMember(System.Dynamic.DynamicMetaObject target)
 {
     throw null;
 }
Esempio n. 14
0
        public static Et EtToNumber(Meta obj)
        {
            if (obj.HasValue == true & obj.Value == null)
                return Et.Constant(0.0D, typeof(double));

            //TODO: handle all .NET number types
            if (obj.LimitType == typeof(double))
                return Et.Convert(obj.Expression, typeof(double));

            if (obj.LimitType == typeof(Js.Undefined))
                return Et.Constant(double.NaN, typeof(double));

            if (obj.LimitType == typeof(bool))
                return Et.Condition(
                    Et.Convert(obj.Expression, typeof(bool)),
                    Et.Constant(1.0, typeof(double)),
                    Et.Constant(0.0, typeof(double)),
                    typeof(double)
                );

            if (obj.LimitType == typeof(string))
            {
                var tmp = Et.Parameter(typeof(double), "#tmp");

                var method = typeof(double).GetMethod(
                        "TryParse",
                        new[] {
                            typeof(string),
                            typeof(NumberStyles),
                            typeof(IFormatProvider),
                            typeof(double).MakeByRefType()
                        }
                    );

                return Et.Block(
                    new[] { tmp },
                    Et.Condition(
                        Et.Call(
                            method,
                            Et.Convert(obj.Expression, typeof(string)),
                            Et.Constant(NumberStyles.Any, typeof(NumberStyles)),
                            Et.Constant(CultureInfo.InvariantCulture, typeof(IFormatProvider)),
                            tmp
                        ),
                        tmp,
                        Et.Constant(double.NaN, typeof(double))
                    )
                );
            }

            if (typeof(IObj).IsAssignableFrom(obj.LimitType))
                return EtUtils.Cast<double>(
                    Et.Call(
                        Et.Convert(obj.Expression, typeof(Js.IObj)),
                        IObjMethods.MiDefaultValue,
                        Et.Constant(ValueHint.Number)
                    )
                );

            return Et.Constant(1.0, typeof(double));
        }
Esempio n. 15
0
 public virtual System.Dynamic.DynamicMetaObject BindSetIndex(System.Dynamic.SetIndexBinder binder, System.Dynamic.DynamicMetaObject[] indexes, System.Dynamic.DynamicMetaObject value)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
 public System.Dynamic.DynamicMetaObject FallbackSetIndex(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] indexes, System.Dynamic.DynamicMetaObject value)
 {
     throw null;
 }
Esempio n. 17
0
 public abstract System.Dynamic.DynamicMetaObject Bind(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args);
 public System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value)
 {
     throw null;
 }
Esempio n. 19
0
        public static Et EtToString(Meta obj)
        {
            if (obj.LimitType == typeof(string))
                return Et.Convert(obj.Expression, typeof(string));

            if (obj.LimitType == typeof(double))
                return Et.Condition(
                    Et.Call(
                        typeof(double).GetMethod("IsInfinity"),
                        Et.Convert(obj.Expression, typeof(double))
                    ),
                    Et.Constant("Infinity", typeof(string)),
                    Et.Call(
                        obj.Expression,
                        typeof(object).GetMethod("ToString")
                    ),
                    typeof(string)
                );

            if (obj.LimitType == typeof(Js.Undefined))
                return Et.Constant("undefined", typeof(string));

            if (obj.Value == null)
                return Et.Constant("null", typeof(string));

            if (obj.LimitType == typeof(bool))
                return Et.Condition(
                    Et.Convert(obj.Expression, typeof(bool)),
                    Et.Constant("true", typeof(string)),
                    Et.Constant("false", typeof(string)),
                    typeof(string)
                );

            if (typeof(IObj).IsAssignableFrom(obj.LimitType))
                return EtUtils.Cast<string>(
                    Et.Call(
                        Et.Convert(obj.Expression, typeof(Js.IObj)),
                        IObjMethods.MiDefaultValue,
                        Et.Constant(ValueHint.String)
                    )
                );

            // last step, just ToString
            return Et.Call(
                obj.Expression,
                typeof(object).GetMethod("ToString")
            );
        }
 public sealed override System.Dynamic.DynamicMetaObject Bind(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     throw null;
 }
            public override System.Dynamic.DynamicMetaObject BindSetMember(System.Dynamic.SetMemberBinder binder, System.Dynamic.DynamicMetaObject value)
            {
                var parameters = new System.Linq.Expressions.Expression[]
                {
                    System.Linq.Expressions.Expression.Constant(binder.Name),
                    value.Expression,
                };

                var callMethod = CallMethod(setValueMethod, parameters);

                return(callMethod);
            }
 public System.Dynamic.DynamicMetaObject FallbackUnaryOperation(System.Dynamic.DynamicMetaObject target)
 {
     throw null;
 }
Esempio n. 23
0
 public abstract System.Dynamic.DynamicMetaObject FallbackConvert(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject errorSuggestion);
Esempio n. 24
0
 public override System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion)
 {
     return(null);
 }
Esempio n. 25
0
 public abstract System.Dynamic.DynamicMetaObject FallbackCreateInstance(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion);
Esempio n. 26
0
 public override System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value, System.Dynamic.DynamicMetaObject errorSuggestion)
 {
     return(null);
 }
Esempio n. 27
0
 public abstract System.Dynamic.DynamicMetaObject FallbackDeleteIndex(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] indexes, System.Dynamic.DynamicMetaObject errorSuggestion);
Esempio n. 28
0
 public System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 29
0
 public abstract System.Dynamic.DynamicMetaObject FallbackDeleteMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject errorSuggestion);
Esempio n. 30
0
 public abstract System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion);
Esempio n. 31
0
 public System.Dynamic.DynamicMetaObject FallbackBinaryOperation(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject arg)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 32
0
 public System.Dynamic.DynamicMetaObject FallbackSetIndex(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] indexes, System.Dynamic.DynamicMetaObject value)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 33
0
 public virtual System.Dynamic.DynamicMetaObject BindSetMember(System.Dynamic.SetMemberBinder binder, System.Dynamic.DynamicMetaObject value)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 34
0
 public System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 35
0
 public System.Dynamic.DynamicMetaObject Defer(System.Dynamic.DynamicMetaObject target, params System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 36
0
 public abstract System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value, System.Dynamic.DynamicMetaObject errorSuggestion);
Esempio n. 37
0
 public sealed override System.Dynamic.DynamicMetaObject Bind(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Esempio n. 38
0
        public static Et EtToObject(Meta obj, Context context)
        {
            if (obj.LimitType == typeof(Js.Undefined) || (obj.HasValue && obj.Value == null))
                throw new ShouldThrowTypeError();

            if (obj.LimitType == typeof(double))
                return Et.Call(
                    Et.Constant(context, typeof(Context)),
                    Context.MiCreateNumber,
                    Et.Convert(obj.Expression, typeof(object))
                );

            if (obj.LimitType == typeof(string))
                return Et.Call(
                    Et.Constant(context, typeof(Context)),
                    Context.MiCreateString,
                    Et.Convert(obj.Expression, typeof(object))
                );

            if (obj.LimitType == typeof(bool))
                return Et.Call(
                    Et.Constant(context, typeof(Context)),
                    Context.MiCreateBoolean,
                    Et.Convert(obj.Expression, typeof(object))
                );

            return obj.Expression;
        }