Exemplo 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));
        }
Exemplo 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;
        }
Exemplo 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;
 }
Exemplo 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;
        }
Exemplo n.º 6
0
 public virtual System.Dynamic.DynamicMetaObject BindBinaryOperation(System.Dynamic.BinaryOperationBinder binder, System.Dynamic.DynamicMetaObject arg)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 7
0
 public System.Dynamic.DynamicMetaObject FallbackDeleteMember(System.Dynamic.DynamicMetaObject target)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 8
0
 public System.Dynamic.DynamicMetaObject FallbackDeleteIndex(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] indexes)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 9
0
 public System.Dynamic.DynamicMetaObject FallbackCreateInstance(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 10
0
 public System.Dynamic.DynamicMetaObject FallbackConvert(System.Dynamic.DynamicMetaObject target)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo 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;
 }
Exemplo 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));
        }
Exemplo 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;
 }
Exemplo 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;
 }
Exemplo 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;
 }
Exemplo n.º 23
0
 public abstract System.Dynamic.DynamicMetaObject FallbackConvert(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject errorSuggestion);
Exemplo n.º 24
0
 public override System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion)
 {
     return(null);
 }
Exemplo n.º 25
0
 public abstract System.Dynamic.DynamicMetaObject FallbackCreateInstance(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion);
Exemplo n.º 26
0
 public override System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value, System.Dynamic.DynamicMetaObject errorSuggestion)
 {
     return(null);
 }
Exemplo n.º 27
0
 public abstract System.Dynamic.DynamicMetaObject FallbackDeleteIndex(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] indexes, System.Dynamic.DynamicMetaObject errorSuggestion);
Exemplo n.º 28
0
 public System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 29
0
 public abstract System.Dynamic.DynamicMetaObject FallbackDeleteMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject errorSuggestion);
Exemplo n.º 30
0
 public abstract System.Dynamic.DynamicMetaObject FallbackInvokeMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject errorSuggestion);
Exemplo n.º 31
0
 public System.Dynamic.DynamicMetaObject FallbackBinaryOperation(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject arg)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo 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));
 }
Exemplo n.º 33
0
 public virtual System.Dynamic.DynamicMetaObject BindSetMember(System.Dynamic.SetMemberBinder binder, System.Dynamic.DynamicMetaObject value)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 34
0
 public System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 35
0
 public System.Dynamic.DynamicMetaObject Defer(System.Dynamic.DynamicMetaObject target, params System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo n.º 36
0
 public abstract System.Dynamic.DynamicMetaObject FallbackSetMember(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject value, System.Dynamic.DynamicMetaObject errorSuggestion);
Exemplo n.º 37
0
 public sealed override System.Dynamic.DynamicMetaObject Bind(System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args)
 {
     return(default(System.Dynamic.DynamicMetaObject));
 }
Exemplo 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;
        }