Ejemplo n.º 1
0
        public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            if (Value is KumaInstance)
            {
                var KumaName = InteropBinder.MapExpressionType(binder.Operation);
                if (KumaName == null)
                {
                    return(InteropBinder.Binary.Bind(binder, this, arg));
                }

                if (
                    InteropBinder.InvokeMember.SearchForFunction(((KumaInstance)Value).Class, KumaName,
                                                                 (KumaInstance)Value, L(Arg(arg.Value)), true) != null)
                {
                    return
                        (InteropBinder.InvokeMember.Bind(
                             new InteropBinder.InvokeMember(KumaName, new CallInfo(0), Scope), this,
                             _DMO(DMO(Scope), DMO(Arg(arg.Value)))));
                }
                var clrName = InteropBinder.ToClrOperatorName(KumaName);
                if (
                    InteropBinder.InvokeMember.SearchForFunction(((KumaInstance)Value).Class, clrName,
                                                                 (KumaInstance)Value, L(Arg(arg.Value)), true) != null)
                {
                    return
                        (InteropBinder.InvokeMember.Bind(
                             new InteropBinder.InvokeMember(clrName, new CallInfo(0), Scope), this,
                             _DMO(DMO(Scope), DMO(Arg(arg.Value)))));
                }
                return(InteropBinder.Binary.Bind(binder, this, arg));
            }
            return(InteropBinder.Binary.Bind(binder, this, arg));
        }
Ejemplo n.º 2
0
        public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
        {
            if (Value is KumaInstance)
            {
                // Check to see which method we should try to call
                var KumaName = InteropBinder.MapExpressionType(binder.Operation);

                if (KumaName == null)
                {
                    return(InteropBinder.Unary.Bind(binder, this));
                }

                if (
                    InteropBinder.InvokeMember.SearchForFunction(((KumaInstance)Value).Class, KumaName,
                                                                 (KumaInstance)Value, L(), true) != null)
                {
                    return
                        (InteropBinder.InvokeMember.Bind(
                             new InteropBinder.InvokeMember(KumaName, new CallInfo(0), Scope), this, _DMO(DMO(Scope))));
                }
                var clrName = InteropBinder.ToClrOperatorName(KumaName);
                if (
                    InteropBinder.InvokeMember.SearchForFunction(((KumaInstance)Value).Class, clrName,
                                                                 (KumaInstance)Value, L(), true) != null)
                {
                    return(InteropBinder.Unary.Bind(binder, this));
                }

                return(new DynamicMetaObject(Expression.Constant(null),
                                             BindingRestrictions.GetExpressionRestriction(Expression.Constant(true))));
            }

            return(InteropBinder.Unary.Bind(binder, this));
        }
Ejemplo n.º 3
0
        private static dynamic Compare(object left, object right, object rawScope)
        {
            var scope = (NovaScope)rawScope;

            var NovaName = "<=>";
            var clrName  = InteropBinder.ToClrOperatorName(NovaName);

            if (left is NovaInstance)
            {
                var lo  = (NovaInstance)left;
                var dmo = lo.GetMetaObject(Expression.Constant(left));
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, NovaName, lo, L(Arg(right)), true) != null)
                {
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, clrName, lo, L(Arg(right)), true) != null)
                {
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
            }

            var Value = Nova.Box(left);

            if (Value.Class != null)
            {
                var _dmo = Value.GetMetaObject(Expression.Constant(Value));
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, NovaName, Value, L(Arg(right)), true) !=
                    null)
                {
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, clrName, Value, L(Arg(right)), true) !=
                    null)
                {
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
            }

            dynamic _left  = left;
            dynamic _right = right;

            if (_left < _right)
            {
                return(-1);
            }

            if (_left > _right)
            {
                return(1);
            }

            return(0);
        }
Ejemplo n.º 4
0
        private static dynamic Match(object rawLeft, object rawRight, NovaExpressionType novaBinaryNodeType, object rawScope)
        {
            var scope = (NovaScope)rawScope;

            var left  = CompilerServices.CompileExpression((Expression)rawLeft, scope);
            var right = CompilerServices.CompileExpression((Expression)rawRight, scope);

            var NovaName = "=~";
            var clrName  = InteropBinder.ToClrOperatorName(NovaName);

            if (left is NovaInstance)
            {
                var lo = (NovaInstance)left;
                DynamicMetaObject dmo = lo.GetMetaObject(Expression.Constant(left));
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, NovaName, lo, L(Arg(right)), true) != null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                     _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, clrName, lo, L(Arg(right)), true) != null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                     _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
            }

            var Value = Nova.Box(left);

            if (Value.Class != null)
            {
                var _dmo = Value.GetMetaObject(Expression.Constant(Value));
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, NovaName, Value, L(Arg(right)), true) !=
                    null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!_dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                      _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(NovaName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, clrName, Value, L(Arg(right)), true) !=
                    null)
                {
                    if (novaBinaryNodeType == NovaExpressionType.NotMatch)
                    {
                        return(!_dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                      _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(clrName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
            }

            if (!(left is Regex || right is Regex))
            {
                return(null);
            }

            var left1 = left as Regex;
            var regex = left1 ?? (Regex)right;

            var str = (left is Regex) ? (string)right : (string)left;

            if (!regex.Match(str).Success)
            {
                return(novaBinaryNodeType == NovaExpressionType.NotMatch);
            }
            var groups = regex.Match(str).Groups;

            foreach (var groupName in regex.GetGroupNames())
            {
                scope[groupName] = groups[groupName].Value;
            }


            return(novaBinaryNodeType == NovaExpressionType.Match);
        }
Ejemplo n.º 5
0
 public override DynamicMetaObject /*!*/ BindConvert(ConvertBinder /*!*/ binder)
 {
     return(InteropBinder.TryBindCovertToDelegate(this, binder, Methods.CreateDelegateFromProc)
            ?? base.BindConvert(binder));
 }