示例#1
0
        private IEnumerable <TurtleData> CompileQueue(List <ParsedData> data, CancellationToken token)
        {
            List <TurtleData> interData = new List <TurtleData>();
            ParsedData        current;

            UpdateVars(From);
            UpdateVars(To);

            int FromInt   = From.Evaluate();
            int ToInt     = To.Evaluate();
            int ChangeInt = 1;

            if (Operator == OperatorType.MinusEquals || Operator == OperatorType.PlusEquals)
            {
                UpdateVars(Change);
                ChangeInt = Change.Evaluate();
            }

            void Exec(int i)
            {
                token.ThrowIfCancellationRequested();
                for (int counter = 0; counter < data.Count; counter++)
                {
                    current = data[counter];

                    current.Variables[LoopVariable] = i;
                    foreach (var item in Variables)
                    {
                        current.Variables[item.Key] = item.Value;
                    }

                    if (current.IsBlock)
                    {
                        interData.AddRange(current.CompileBlock(token));
                    }
                    else if (current is VariableData variableChange)
                    {
                        current.UpdateVars(variableChange.Value);
                        Variables[variableChange.VariableName] = variableChange.Value.Evaluate();
                    }
                    else
                    {
                        interData.Add(current.Compile(token));
                    }
                }
            }

            switch (Condition)
            {
            case ConditionType.Greater: {
                if (Operator == OperatorType.PlusPlus)
                {
                    for (int i = FromInt; i > ToInt; i++)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.PlusEquals)
                {
                    for (int i = FromInt; i > ToInt; i += ChangeInt)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinMin)
                {
                    for (int i = FromInt; i > ToInt; i--)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinusEquals)
                {
                    for (int i = FromInt; i > ToInt; i -= ChangeInt)
                    {
                        Exec(i);
                    }
                }
                break;
            }

            case ConditionType.Less: {
                if (Operator == OperatorType.PlusPlus)
                {
                    for (int i = FromInt; i < ToInt; i++)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.PlusEquals)
                {
                    for (int i = FromInt; i < ToInt; i += ChangeInt)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinMin)
                {
                    for (int i = FromInt; i < ToInt; i--)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinusEquals)
                {
                    for (int i = FromInt; i < ToInt; i -= ChangeInt)
                    {
                        Exec(i);
                    }
                }
                break;
            }

            case ConditionType.GreaterOrEqual: {
                if (Operator == OperatorType.PlusPlus)
                {
                    for (int i = FromInt; i >= ToInt; i++)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.PlusEquals)
                {
                    for (int i = FromInt; i >= ToInt; i += ChangeInt)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinMin)
                {
                    for (int i = FromInt; i >= ToInt; i--)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinusEquals)
                {
                    for (int i = FromInt; i >= ToInt; i -= ChangeInt)
                    {
                        Exec(i);
                    }
                }
                break;
            }

            case ConditionType.LessOrEqual: {
                if (Operator == OperatorType.PlusPlus)
                {
                    for (int i = FromInt; i <= ToInt; i++)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.PlusEquals)
                {
                    for (int i = FromInt; i <= ToInt; i += ChangeInt)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinMin)
                {
                    for (int i = FromInt; i <= ToInt; i--)
                    {
                        Exec(i);
                    }
                }
                if (Operator == OperatorType.MinusEquals)
                {
                    for (int i = FromInt; i <= ToInt; i -= ChangeInt)
                    {
                        Exec(i);
                    }
                }
                break;
            }
            }
            return(interData);
        }