public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues) { // Setup the continue skip. ContinueSkip continueSkip = actionSet.ContinueSkip; continueSkip.Setup(actionSet); IndexReference result = actionSet.VarCollection.Assign($"_conditionTestResult", actionSet.IsGlobal, true); continueSkip.SetSkipCount(actionSet, continueSkip.GetSkipCount(actionSet) + 3); actionSet.AddAction(ArrayBuilder <Element> .Build( // This will continue at (0) if the rule loops. new A_LoopIfConditionIsFalse(), // Set the result to true. result.SetVariable(new V_True()), Element.Part <A_Skip>(new V_Number(1)), // The rule will loop back here (0) if false. result.SetVariable(new V_False()) )); continueSkip.ResetSkipCount(actionSet); if (TestingIfTrue) { return(result.GetVariable()); } else { return(Element.Part <V_Not>(result.GetVariable())); } }
public static Element[] While(ContinueSkip continueSkip, Element condition, Element[] actions) { List <Element> result = new List <Element>(); continueSkip.Setup(); int whileStartIndex = continueSkip.GetSkipCount() + 1; A_SkipIf skipCondition = new A_SkipIf() { ParameterValues = new IWorkshopTree[2] }; skipCondition.ParameterValues[0] = Element.Part <V_Not>(condition); result.Add(skipCondition); result.AddRange(actions); result.AddRange(continueSkip.SetSkipCountActions(whileStartIndex)); skipCondition.ParameterValues[1] = new V_Number(result.Count); result.Add(new A_Loop()); result.AddRange(continueSkip.ResetSkipActions()); return(result.ToArray()); }
protected override MethodResult Get() { // Setup the continue skip. ContinueSkip continueSkip = TranslateContext.ContinueSkip; continueSkip.Setup(); IndexedVar result = TranslateContext.VarCollection.AssignVar(Scope, $"{Name} result", TranslateContext.IsGlobal, null); Element[] actions = ArrayBuilder <Element> .Build( // Set the continue skip. continueSkip.SetSkipCountActions(continueSkip.GetSkipCount() + 4), // This will continue at (0) if the rule loops. new A_LoopIfConditionIsFalse(), // Set the result to true. result.SetVariable(new V_True()), Element.Part <A_Skip>(new V_Number(1)), // The rule will loop back here (0) if false. result.SetVariable(new V_False()), // Reset the continueskip continueSkip.ResetSkipActions() ); if (TestingIfTrue) { return(new MethodResult(actions, result.GetVariable())); } else { return(new MethodResult(actions, Element.Part <V_Not>(result.GetVariable()))); } }