Exemplo n.º 1
0
 internal BinaryExpression(Expression left, Expression right, KumaExpressionType type)
 {
     Left  = left;
     Right = right;
     KumaBinaryNodeType = type;
     _isKumaBinary      = true;
 }
Exemplo n.º 2
0
        internal static dynamic ConditionalAccessSet(object container, List <FunctionArgument> args, object value,
                                                     KumaExpressionType conditionalAssignmentType, object rawScope)
        {
            var scope = rawScope as KumaScope;
            var v     = Access(container, args, scope);

            if (Boolean(v))
            {
                if (conditionalAssignmentType == KumaExpressionType.IfNotNullAssign)
                {
                    return(AccessSet(container, args, value, E.Assign, scope));
                }
            }
            else
            {
                if (conditionalAssignmentType == KumaExpressionType.IfNullAssign)
                {
                    return(AccessSet(container, args, value, E.Assign, scope));
                }
            }
            return(v);
        }
Exemplo n.º 3
0
        private static dynamic Match(object rawLeft, object rawRight, KumaExpressionType kumaBinaryNodeType, object rawScope)
        {
            var scope = (KumaScope)rawScope;

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

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

            if (left is KumaInstance)
            {
                var lo = (KumaInstance)left;
                DynamicMetaObject dmo = lo.GetMetaObject(Expression.Constant(left));
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, KumaName, lo, L(Arg(right)), true) != null)
                {
                    if (kumaBinaryNodeType == KumaExpressionType.NotMatch)
                    {
                        return(!dmo.BindInvokeMember(new InteropBinder.InvokeMember(KumaName, new CallInfo(1), scope),
                                                     _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(dmo.BindInvokeMember(new InteropBinder.InvokeMember(KumaName, new CallInfo(1), scope),
                                                _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(lo.Class, clrName, lo, L(Arg(right)), true) != null)
                {
                    if (kumaBinaryNodeType == KumaExpressionType.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 = Kuma.Box(left);

            if (Value.Class != null)
            {
                var _dmo = Value.GetMetaObject(Expression.Constant(Value));
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, KumaName, Value, L(Arg(right)), true) !=
                    null)
                {
                    if (kumaBinaryNodeType == KumaExpressionType.NotMatch)
                    {
                        return(!_dmo.BindInvokeMember(new InteropBinder.InvokeMember(KumaName, new CallInfo(1), scope),
                                                      _DMO(DMO(scope), DMO(Arg(right)))));
                    }
                    return(_dmo.BindInvokeMember(new InteropBinder.InvokeMember(KumaName, new CallInfo(1), scope),
                                                 _DMO(DMO(scope), DMO(Arg(right)))));
                }
                if (InteropBinder.InvokeMember.SearchForFunction(Value.Class, clrName, Value, L(Arg(right)), true) !=
                    null)
                {
                    if (kumaBinaryNodeType == KumaExpressionType.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(kumaBinaryNodeType == KumaExpressionType.NotMatch);
            }
            var groups = regex.Match(str).Groups;

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


            return(kumaBinaryNodeType == KumaExpressionType.Match);
        }
 internal ConditionalAccessSetExpression(Expression container, List <FunctionArgument> arguments, Expression value,
                                         KumaExpressionType conditionalAssignmentType)
     : base(container, arguments, value, ExpressionType.Assign)
 {
     ConditionalAssignmentType = conditionalAssignmentType;
 }
Exemplo n.º 5
0
        internal static dynamic Call(object func, List <FunctionArgument> args, object scope, KumaExpressionType pipeType, bool isOp, bool isPostfix)
        {
            if (func == null)
            {
                if (((KumaScope)scope).GlobalScope["Kernel"] == null)
                {
                    // map and check Kernel
                }
                throw new NotImplementedException();
            }
            var realArgs    = new List <object>();
            var names       = new List <string>();
            var offsetCount = 0;

            if (func is KumaFunction && !(func is KumaPartialFunction))
            {
                args.ForEach(realArgs.Add);
                realArgs.Insert(0, scope);
                if (realArgs.Count() - 1 < names.Count())
                {
                    (func as KumaFunction).Arguments.ForEach(arg => {
                        if (arg.HasDefault)
                        {
                            realArgs.Add(new FunctionArgument(arg.Name, arg.DefaultValue));
                        }
                    });
                }
                offsetCount = 1;
                if (pipeType != KumaExpressionType.Empty)
                {
                    realArgs.Add(pipeType);
                    offsetCount = 2;
                }
                (func as KumaFunction).SetScope(scope as KumaScope);
            }
            else if (func.GetType() == typeof(InstanceReference))
            {
                args.ForEach(realArgs.Add);
                realArgs.Insert(0, scope);
                offsetCount = 1;
                if (pipeType != KumaExpressionType.Empty)
                {
                    realArgs.Add(pipeType);
                    offsetCount = 2;
                }
                var iref   = (InstanceReference)func;
                var lval   = CompilerServices.CompileExpression(iref.LValue, (KumaScope)scope);
                var imArgs = new List <Expression>();
                realArgs.ForEach(arg => imArgs.Add(Expression.Constant(arg)));
                imArgs.Insert(0, Expression.Constant(lval, typeof(object)));
                if (isOp)
                {
                    imArgs.Add(Expression.Constant(new KumaUnaryBoolean(isPostfix)));
                }
                if (iref.LValue is VariableExpression &&
                    CompilerServices.CompileExpression((iref.LValue as VariableExpression).Name, (KumaScope)scope) ==
                    "super")
                {
                    imArgs.Add(Expression.Constant(new KumaDoNotWrapBoolean(true)));
                }
                return(Dynamic(typeof(object),
                               new InteropBinder.InvokeMember(iref.Key, new CallInfo(realArgs.Count - offsetCount, names),
                                                              (KumaScope)scope), imArgs));
            }
            else
            {
                // Kuma name logic does not work here
                args.ForEach(arg => realArgs.Add(CompilerServices.CompileExpression(arg.Value, scope as KumaScope)));
            }

            var bArgs = new List <Expression>();

            realArgs.ForEach(arg => bArgs.Add(Expression.Constant(ConvertIfNumber(arg))));
            bArgs.Insert(0, Expression.Constant(func, typeof(object)));
            return(Dynamic(typeof(object),
                           new InteropBinder.Invoke(scope as KumaScope,
                                                    new CallInfo(realArgs.Count - offsetCount, names)), bArgs));
        }
Exemplo n.º 6
0
        internal static dynamic ConditionalAssign(VariableExpression @var, dynamic value, KumaExpressionType conditionalAssignmentType, bool isConst,
                                                  object rawScope)
        {
            var scope = rawScope as KumaScope;
            var v     = Resolve(CompilerServices.CompileExpression(@var.Name, scope), scope);

            if (Boolean(v))
            {
                if (conditionalAssignmentType == KumaExpressionType.IfNotNullAssign)
                {
                    return(Assign(@var, value, E.Assign, isConst, scope));
                }
            }
            else
            {
                if (conditionalAssignmentType == KumaExpressionType.IfNullAssign)
                {
                    return(Assign(@var, value, E.Assign, isConst, scope));
                }
            }
            return(v);
        }
 internal ConditionalAssignmentExpression(LeftHandValueExpression left, Expression right, KumaExpressionType conditionalAssignmentType)
     : base(left, right, ExpressionType.Assign)
 {
     ConditionalAssignmentType = conditionalAssignmentType;
 }
Exemplo n.º 8
0
 public static ConditionalAssignmentExpression ConditionalAssign(LeftHandValueExpression left, Expression right,
                                                                 KumaExpressionType conditionalAssignmentType)
 {
     return(new ConditionalAssignmentExpression(left, right, conditionalAssignmentType));
 }
Exemplo n.º 9
0
 public static Expression CallWithPipe(Expression func, List <FunctionArgument> args, KumaExpressionType pipeType)
 {
     return(new FunctionCallExpression(func, args, pipeType));
 }
Exemplo n.º 10
0
 public static ConditionalAccessSetExpression ConditionalAccessSet(Expression container,
                                                                   List <FunctionArgument> args, Expression value,
                                                                   KumaExpressionType conditionalAssignmentType)
 {
     return(new ConditionalAccessSetExpression(container, args, value, conditionalAssignmentType));
 }
Exemplo n.º 11
0
 internal FunctionCallExpression(Expression func, List <FunctionArgument> arguments, KumaExpressionType pipeType)
 {
     Function  = func;
     Arguments = arguments;
     PipeType  = pipeType;
 }