/// <summary>The method was already called in the stack.</summary>
        private IWorkshopTree RecursiveCall(ActionSet actionSet, MethodCall methodCall)
        {
            // Push new parameters.
            for (int i = 0; i < method.ParameterVars.Length; i++)
            {
                var varReference = actionSet.IndexAssigner[method.ParameterVars[i]];
                if (varReference is RecursiveIndexReference)
                {
                    actionSet.AddAction(((RecursiveIndexReference)varReference).Push(
                                            (Element)methodCall.ParameterValues[i]
                                            ));
                }
            }

            // Add to the continue skip array.
            V_Number skipLength = new V_Number();

            actionSet.AddAction(continueArray.ModifyVariable(
                                    Operation.AppendToArray,
                                    skipLength
                                    ));

            // Restart the method.
            SkipStartMarker resetSkip = new SkipStartMarker(actionSet);

            resetSkip.SetEndMarker(endOfMethod);
            actionSet.AddAction(resetSkip);

            SkipEndMarker continueAtMarker = new SkipEndMarker();

            actionSet.AddAction(continueAtMarker);
            skipLength.Value = continueAt.NumberOfActionsToMarker(continueAtMarker);

            return(returnHandler.GetReturnedValue());
        }
Ejemplo n.º 2
0
        public void NextCase(IWorkshopTree value)
        {
            // If the state is on a case and the action count was changed, create new skip that will skip to the end of the switch.
            if (AutoBreak && State == SwitchBuilderState.OnCase && actionSet.ActionCount != LastCaseStart)
            {
                // Create the skip and add it to the actionset.
                SkipStartMarker skipToEnd = new SkipStartMarker(actionSet);
                actionSet.AddAction(skipToEnd);

                // Add it to the list of skips that need to skip to the end.
                SkipToEnd.Add(skipToEnd);
            }

            // Update the state.
            State = SwitchBuilderState.OnCase;

            // Mark the start of the case.
            SkipEndMarker startCase = new SkipEndMarker();

            actionSet.AddAction(startCase);

            // Add the skip length to the start of the case to the skipCounts.
            skipCounts.Add(Skipper.GetSkipCount(startCase));

            // Add the skip value.
            skipValues.Add(value);

            // Update the number of actions.
            LastCaseStart = actionSet.ActionCount;
        }
        public void AddBreak(ActionSet actionSet, string comment)
        {
            SkipStartMarker breaker = new SkipStartMarker(actionSet, comment);

            actionSet.AddAction(breaker);
            switchBuilder.SkipToEnd.Add(breaker);
        }
        public void Translate(ActionSet actionSet)
        {
            SkipStartMarker breaker = new SkipStartMarker(actionSet);

            actionSet.AddAction(breaker);
            BreakContainer.AddBreak(breaker);
        }
        public void Translate(ActionSet actionSet)
        {
            SkipStartMarker continuer = new SkipStartMarker(actionSet);

            actionSet.AddAction(continuer);
            Loop.AddContinue(continuer);
        }
Ejemplo n.º 6
0
        public void Setup(ActionSet actionSet)
        {
            if (IsSetup)
            {
                return;
            }
            IsSetup = true;

            SkipCount  = Rule.DeltinScript.VarCollection.Assign("continueSkip", Rule.IsGlobal, true);
            TempHolder = Rule.DeltinScript.VarCollection.Assign("continueSkipTemp", Rule.IsGlobal, true);

            A_SkipIf skipAction = Element.Part <A_SkipIf>
                                  (
                // Condition
                Element.Part <V_Compare>(SkipCount.GetVariable(), EnumData.GetEnumValue(Operators.Equal), new V_Number(0)),
                // Number of actions
                new V_Number(3)
                                  );

            Skipper           = new SkipStartMarker(actionSet);
            Skipper.SkipCount = TempHolder.GetVariable();

            IActionList[] actions = ArrayBuilder <IActionList> .Build(
                new ALAction(A_Wait.MinimumWait),
                new ALAction(skipAction),
                new ALAction(TempHolder.SetVariable((Element)SkipCount.GetVariable())[0]),
                new ALAction(SkipCount.SetVariable(0)[0]),
                Skipper
                );

            Rule.Actions.InsertRange(0, actions);
        }
Ejemplo n.º 7
0
        public SwitchBuilder(ActionSet actionSet)
        {
            this.actionSet = actionSet;

            // Create the switch skipper.
            Skipper = new SkipStartMarker(actionSet);
            actionSet.AddAction(Skipper);
        }
        public void Translate(ActionSet actionSet)
        {
            SkipStartMarker ifStart = new SkipStartMarker(actionSet, Expression.Parse(actionSet));

            actionSet.AddAction(ifStart);

            Block.Translate(actionSet);

            List <SkipStartMarker> blockCaps = new List <SkipStartMarker>();

            if (ElseBlock != null || ElseIfs.Length > 0)
            {
                SkipStartMarker ifCap = new SkipStartMarker(actionSet);
                actionSet.AddAction(ifCap);
                blockCaps.Add(ifCap);
            }

            SkipEndMarker ifEnd = new SkipEndMarker();

            actionSet.AddAction(ifEnd);
            ifStart.SkipCount = ifStart.GetSkipCount(ifEnd);

            // Get the else-ifs.
            for (int i = 0; i < ElseIfs.Length; i++)
            {
                bool isLast = i == ElseIfs.Length - 1 && ElseBlock == null;

                SkipStartMarker elseIfStart = new SkipStartMarker(actionSet, ElseIfs[i].Expression.Parse(actionSet));
                actionSet.AddAction(elseIfStart);

                ElseIfs[i].Block.Translate(actionSet);

                if (!isLast)
                {
                    SkipStartMarker elseIfCap = new SkipStartMarker(actionSet);
                    actionSet.AddAction(elseIfCap);
                    blockCaps.Add(elseIfCap);
                }

                SkipEndMarker elseIfEnd = new SkipEndMarker();
                actionSet.AddAction(elseIfEnd);
                elseIfStart.SkipCount = elseIfStart.GetSkipCount(elseIfEnd);
            }

            if (ElseBlock != null)
            {
                ElseBlock.Translate(actionSet);
            }

            SkipEndMarker contextCap = new SkipEndMarker();

            actionSet.AddAction(contextCap);
            foreach (var blockCap in blockCaps)
            {
                blockCap.SkipCount = blockCap.GetSkipCount(contextCap);
            }
        }
Ejemplo n.º 9
0
        public virtual void Return()
        {
            SkipStartMarker returnSkipStart = new SkipStartMarker(ActionSet);

            ActionSet.AddAction(returnSkipStart);

            // 0 skip workaround.
            // ActionSet.AddAction(new A_Abort() { Disabled = true });

            skips.Add(returnSkipStart);
        }
Ejemplo n.º 10
0
        public void Setup()
        {
            if (WasSetup)
            {
                throw new Exception("Pattern builder already set up.");
            }
            WasSetup = true;

            SkipMarker = new SkipStartMarker(ActionSet, Condition);
            ActionSet.AddAction(SkipMarker);
        }
Ejemplo n.º 11
0
 public void AddContinue(ActionSet actionSet)
 {
     if (RawContinue)
     {
         actionSet.AddAction(new A_Continue());
     }
     else
     {
         SkipStartMarker continuer = new SkipStartMarker(actionSet);
         actionSet.AddAction(continuer);
         Continue.Add(continuer);
     }
 }
Ejemplo n.º 12
0
 public void AddBreak(ActionSet actionSet)
 {
     if (RawBreak)
     {
         actionSet.AddAction(new A_Break());
     }
     else
     {
         SkipStartMarker breaker = new SkipStartMarker(actionSet);
         actionSet.AddAction(breaker);
         Break.Add(breaker);
     }
 }
Ejemplo n.º 13
0
        public override void Translate(ActionSet actionSet)
        {
            int actionCountPreCondition = actionSet.ActionCount;

            Element condition    = (Element)Condition.Parse(actionSet);
            bool    actionsAdded = actionSet.ActionCount > actionCountPreCondition;

            if (!actionsAdded)
            {
                // Create a normal while loop.
                actionSet.AddAction(Element.Part <A_While>(condition));

                // Translate the block.
                Block.Translate(actionSet.Indent());

                // Resolve continues.
                ResolveContinues(actionSet);

                // Cap the block.
                actionSet.AddAction(new A_End());

                // Resolve breaks.
                ResolveBreaks(actionSet);
            }
            else
            {
                // The while condition requires actions to get the value.
                actionSet.ActionList.Insert(actionCountPreCondition, new ALAction(Element.Part <A_While>(new V_True())));

                SkipStartMarker whileEndSkip = new SkipStartMarker(actionSet, condition);
                actionSet.Indent().AddAction(whileEndSkip);

                // Translate the block.
                Block.Translate(actionSet.Indent());

                // Resolve continues.
                ResolveContinues(actionSet);

                // Cap the block.
                actionSet.AddAction(new A_End());

                // Skip to the end when the condition is false.
                SkipEndMarker whileEnd = new SkipEndMarker();
                whileEndSkip.SetEndMarker(whileEnd);
                actionSet.AddAction(whileEnd);

                // Resolve breaks.
                ResolveBreaks(actionSet);
            }
        }
 public void AddBreak(ActionSet actionSet, string comment)
 {
     if (RawBreak)
     {
         Element brk = Element.Part("Break");
         brk.Comment = comment;
         actionSet.AddAction(brk);
     }
     else
     {
         SkipStartMarker breaker = new SkipStartMarker(actionSet, comment);
         actionSet.AddAction(breaker);
         Break.Add(breaker);
     }
 }
 public void AddContinue(ActionSet actionSet, string comment)
 {
     if (RawContinue)
     {
         Element con = Element.Part("Continue");
         con.Comment = comment;
         actionSet.AddAction(con);
     }
     else
     {
         SkipStartMarker continuer = new SkipStartMarker(actionSet, comment);
         actionSet.AddAction(continuer);
         Continue.Add(continuer);
     }
 }
Ejemplo n.º 16
0
 public void AddBreak(ActionSet actionSet, string comment)
 {
     if (RawBreak)
     {
         actionSet.AddAction(new A_Break()
         {
             Comment = comment
         });
     }
     else
     {
         SkipStartMarker breaker = new SkipStartMarker(actionSet, comment);
         actionSet.AddAction(breaker);
         Break.Add(breaker);
     }
 }
Ejemplo n.º 17
0
 public void AddContinue(ActionSet actionSet, string comment)
 {
     if (RawContinue)
     {
         actionSet.AddAction(new A_Continue()
         {
             Comment = comment
         });
     }
     else
     {
         SkipStartMarker continuer = new SkipStartMarker(actionSet, comment);
         actionSet.AddAction(continuer);
         Continue.Add(continuer);
     }
 }
Ejemplo n.º 18
0
        public virtual void Return(Scope returningFromScope, ActionSet returningSet)
        {
            if (returningSet.IsRecursive)
            {
                returningFromScope.EndScope(returningSet, true);

                foreach (var recursiveIndexReference in AdditionalPopOnReturn)
                {
                    returningSet.AddAction(recursiveIndexReference.Pop());
                }
            }

            SkipStartMarker returnSkipStart = new SkipStartMarker(returningSet);

            returningSet.AddAction(returnSkipStart);
            _skips.Add(returnSkipStart);
        }
Ejemplo n.º 19
0
        public virtual void Return(ActionSet returningSet)
        {
            if (returningSet.IsRecursive)
            {
                returningSet.RecursiveVariableTracker.PopAll();

                foreach (var recursiveIndexReference in AdditionalPopOnReturn)
                {
                    returningSet.AddAction(recursiveIndexReference.Pop());
                }
            }

            SkipStartMarker returnSkipStart = new SkipStartMarker(returningSet);

            returningSet.AddAction(returnSkipStart);
            _skips.Add(returnSkipStart);
        }
Ejemplo n.º 20
0
        public virtual void Setup()
        {
            if (WasSetup)
            {
                throw new Exception("Pattern builder already set up.");
            }
            WasSetup = true;
            ActionSet.ContinueSkip.Setup(ActionSet);

            LoopStart = new SkipEndMarker();
            ActionSet.AddAction(LoopStart);

            if (GetCondition != null)
            {
                Condition = GetCondition();
            }

            LoopSkipStart = new SkipStartMarker(ActionSet, Condition);
            ActionSet.AddAction(LoopSkipStart);
        }
        /// <summary>Calls the method.</summary>
        private IWorkshopTree ParseCall(ActionSet actionSet, MethodCall methodCall)
        {
            // Create the array used for continuing after a recursive call.
            continueArray = actionSet.VarCollection.Assign("_" + method.Name + "_recursiveContinue", actionSet.IsGlobal, false);
            nextContinue  = actionSet.VarCollection.Assign("_" + method.Name + "_nextContinue", actionSet.IsGlobal, true);
            actionSet.InitialSet().AddAction(continueArray.SetVariable(new V_EmptyArray()));

            ReturnHandler returnHandler = methodCall.ReturnHandler ?? new ReturnHandler(actionSet, method.Name, method.multiplePaths);

            this.returnHandler = returnHandler;

            DefinedMethod.AssignParameters(actionSet, method.ParameterVars, methodCall.ParameterValues, true);

            actionSet.AddAction(Element.Part <A_While>(new V_True()));

            continueAt = new SkipStartMarker(actionSet);
            continueAt.SetSkipCount((Element)nextContinue.GetVariable());
            actionSet.AddAction(continueAt);

            method.block.Translate(actionSet);

            PopParameterStacks(actionSet);

            // Pop the continueArray.
            actionSet.AddAction(Element.Part <A_SkipIf>(new V_Compare(
                                                            Element.Part <V_CountOf>(continueArray.GetVariable()),
                                                            Operators.Equal,
                                                            new V_Number(0)
                                                            ), new V_Number(3)));

            actionSet.AddAction(nextContinue.SetVariable(Element.Part <V_LastOf>(continueArray.GetVariable())));
            actionSet.AddAction(continueArray.ModifyVariable(Operation.RemoveFromArrayByIndex, Element.Part <V_CountOf>(continueArray.GetVariable()) - 1));

            actionSet.AddAction(endOfMethod);
            actionSet.AddAction(new A_End());

            actionSet.AddAction(nextContinue.SetVariable(0));

            return(returnHandler.GetReturnedValue());
        }
Ejemplo n.º 22
0
 public void AddBreak(SkipStartMarker continueMarker)
 {
     switchBuilder.SkipToEnd.Add(continueMarker);
 }
Ejemplo n.º 23
0
        public void TranslateSkip(ActionSet actionSet)
        {
            // Create the skip for the start of the if statement.
            SkipStartMarker ifStart = new SkipStartMarker(actionSet, Expression.Parse(actionSet));

            actionSet.AddAction(ifStart);

            // Translate the if block.
            Block.Translate(actionSet);

            // 'block caps' are skips that are added to the end of the if block and each else-if block.
            // The skips skip to the end of the entire if/else-if/else.
            List <SkipStartMarker> blockCaps = new List <SkipStartMarker>();

            // Add the if cap if there is an else block or there is an else-if block.
            if (ElseBlock != null || ElseIfs.Length > 0)
            {
                SkipStartMarker ifCap = new SkipStartMarker(actionSet);
                actionSet.AddAction(ifCap);
                blockCaps.Add(ifCap);
            }

            // Marks the end of the if statement. If the if-condition is false, `ifStart` will skip to here.
            SkipEndMarker ifEnd = new SkipEndMarker();

            actionSet.AddAction(ifEnd);

            // Set the if-skip's count.
            ifStart.SetEndMarker(ifEnd);

            // Get the else-ifs.
            for (int i = 0; i < ElseIfs.Length; i++)
            {
                // This will equal true if this is at the last else-if and there is no else.
                bool isLast = i == ElseIfs.Length - 1 && ElseBlock == null;

                // Create the skip for the start of the else-if.
                SkipStartMarker elseIfStart = new SkipStartMarker(actionSet, ElseIfs[i].Expression.Parse(actionSet));
                actionSet.AddAction(elseIfStart);

                // Translate the else-if block.
                ElseIfs[i].Block.Translate(actionSet);

                // If this is not the last block in the entire if/else-if/else list, add the 'block cap'.
                if (!isLast)
                {
                    SkipStartMarker elseIfCap = new SkipStartMarker(actionSet);
                    actionSet.AddAction(elseIfCap);
                    blockCaps.Add(elseIfCap);
                }

                // Marks the end of the else-if statement. If the condition is false, `elseIfStart` will skip to here.
                SkipEndMarker elseIfEnd = new SkipEndMarker();
                actionSet.AddAction(elseIfEnd);
                elseIfStart.SetEndMarker(elseIfEnd);
            }

            // If there is an else block, translate it.
            if (ElseBlock != null)
            {
                ElseBlock.Translate(actionSet);
            }

            // contextCap marks the end of the entire if/else-if/list.
            SkipEndMarker contextCap = new SkipEndMarker();

            actionSet.AddAction(contextCap);

            // Set all the block caps so they skip to the end of the list.
            foreach (var blockCap in blockCaps)
            {
                blockCap.SetEndMarker(contextCap);
            }
        }
Ejemplo n.º 24
0
 public DynamicSkip(SkipStartMarker startMarker, SkipEndMarker endMarker)
 {
     StartMarker = startMarker;
     EndMarker   = endMarker;
 }
 public void AddBreak(SkipStartMarker breakMarker)
 {
     Break.Add(breakMarker);
 }
 public void AddContinue(SkipStartMarker continueMarker)
 {
     Continue.Add(continueMarker);
 }