private dynamic ConvertElements(KumaArray res)
 {
     for (var i = 0; i < res.Count(); i++)
     {
         if (res[i] is KumaString)
         {
             res[i] = (string)res[i];
         }
         if (res[i] is KumaNumber)
         {
             res[i] = KumaNumber.Convert(res[i]);
         }
         if (res[i] is KumaArray)
         {
             res[i] = ConvertElements((KumaArray)res[i]);
         }
         if (res[i] is KumaDictionary)
         {
             res[i] = ConvertElements((KumaDictionary)res[i]);
         }
     }
     return(res);
 }
Esempio n. 2
0
        internal static dynamic ParallelAssign(
            List <ParallelAssignmentExpression.ParallelAssignmentInfo> leftHandValues,
            List <ParallelAssignmentExpression.ParallelAssignmentInfo> rightHandValues, object rawScope)
        {
            var scope   = rawScope as KumaScope;
            var rvalues = new List <object> ();
            var fval    = CompilerServices.CompileExpression(rightHandValues[0].Value as Expression, scope);

            if (fval is List <object> && !rightHandValues[0].IsWildcard)
            {
                rvalues = new List <object> (fval as List <object>);
            }
            else
            {
                foreach (var rvalue in rightHandValues)
                {
                    var val = CompilerServices.CompileExpression(rvalue.Value as Expression, scope);
                    if (rvalue.IsWildcard)
                    {
                        if (val is List <object> )
                        {
                            (val as List <object>).ForEach(value => rvalues.Add(value));
                        }
                        else
                        {
                            rvalues.Add(val);
                        }
                    }
                    else
                    {
                        rvalues.Add(val);
                    }
                }
            }

            var i      = 0;
            var k      = 0;
            var result = new KumaArray();

            foreach (var _lvalue in leftHandValues)
            {
                var lvalue = _lvalue.Value;
                if (i >= rvalues.Count)
                {
                    break;
                }
                k++;
                if (lvalue is List <ParallelAssignmentExpression.ParallelAssignmentInfo> )
                {
                    result.Add(ParallelAssign(lvalue as List <ParallelAssignmentExpression.ParallelAssignmentInfo>,
                                              new List <ParallelAssignmentExpression.ParallelAssignmentInfo> {
                        new ParallelAssignmentExpression.ParallelAssignmentInfo {
                            IsWildcard = false,
                            Value      = Expression.Constant(rvalues[i++])
                        }
                    }, scope));
                }
                else if (_lvalue.IsWildcard)
                {
                    var mvalues = new KumaArray();
                    for (var j = i; j < rvalues.Count; j++)
                    {
                        mvalues.Add(rvalues[j]);
                    }
                    result.Add(Assign(lvalue as VariableExpression, mvalues, E.Assign, false, rawScope));
                    break;
                }
                else
                {
                    result.Add(Assign(lvalue as VariableExpression, rvalues[i++], E.Assign, false, rawScope));
                }
            }

            if (k < leftHandValues.Count)
            {
                for (var j = k; j < leftHandValues.Count; j++)
                {
                    if (leftHandValues[j].Value is List <ParallelAssignmentExpression.ParallelAssignmentInfo> )
                    {
                        var lvalues =
                            leftHandValues[j].Value as List <ParallelAssignmentExpression.ParallelAssignmentInfo>;
                        for (var l = 0; l < lvalues.Count; l++)
                        {
                            result.Add(Assign(lvalues[l].Value as VariableExpression, null, E.Assign, false, scope));
                        }
                    }
                    else
                    {
                        result.Add(Assign(leftHandValues[j].Value as VariableExpression, null, E.Assign, false, scope));
                    }
                }
            }

            return(result.Count > 1 ? result : result[0]);
        }