public override Variable Construct(ArgumentInfo passed) { if (ConstructorScopes is null) { ConstructorScopes = InnerScope.CreateChildren(1); } if (ConstructorOverloads is null) { ConstructorOverloads = new ParameterInfo[] { new ParameterInfo((true, VarSelector.StaticTypeName, "selector", ConstructorScopes[0])) } } ; (ParameterInfo match, int index) = ParameterInfo.HighestMatch(ConstructorOverloads, passed); match.Grab(passed); switch (index) { case 0: var value = new VarEntity(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope); value.Selector.InvokeOperation(Operation.Set, match[0].Value as VarSelector, Compiler.CurrentScriptTrace); value.Constructed = true; return(value); default: throw new InvalidArgumentsException("Could not find a constructor overload that matches the given arguments.", Compiler.CurrentScriptTrace); } }
public override Variable Construct(ArgumentInfo arguments) { if (ConstructorScopes is null) { ConstructorScopes = InnerScope.CreateChildren(1); } if (ConstructorOverloads is null) { ConstructorOverloads = new ParameterInfo[] { new ParameterInfo((true, VarString.StaticTypeName, "json", ConstructorScopes[0])) } } ; (ParameterInfo match, int index) = ParameterInfo.HighestMatch(ConstructorOverloads, arguments); match.Grab(arguments); switch (index) { case 0: string value = (match[0].Value as VarString).GetConstant(); VarJson json = new VarJson(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope); json.SetValue(value); return(json); default: throw new MissingOverloadException($"{TypeName} constructor", index, arguments); } }
private IEnumerator OnIteration(int index) { RockLog.InsertLine(); RockLog.WriteLine(this, LogTier.Info, string.Format("Starting iteration number: {0}", CurrentIteration)); InnerScope.Reset(); var iteratorVariable = Field <object> .Create(RepeatNumberName, index, false, true); // update the iterator job context InnerScope.ScopeContext.Add(iteratorVariable); // reset the inner scope and loop through the child steps yield return(EditorCoroutines.StartCoroutine(InnerScope.StartExecutingSteps(), this)); if (!IsSuppressed) { switch (InnerScope.Request) { case StepRequest.ExitScope: case StepRequest.RootScope: case StepRequest.TerminateJob: DoLoop = false; break; } } CurrentIteration++; }
public override Variable Construct(ArgumentInfo arguments) { if (ConstructorScopes is null) { ConstructorScopes = InnerScope.CreateChildren(1); } (ParameterInfo match, int index) = ParameterInfo.HighestMatch(new ParameterInfo[] { new (bool, string, string, Compiler.Scope)[] { (true, VarString.StaticTypeName, "value", ConstructorScopes[0]) }
/// <inheritdoc /> protected override IEnumerator OnExecute(JobContext context) { InnerScope.ScopeContext = context; yield return(EditorCoroutines.StartCoroutine(InnerScope.StartExecutingSteps(), this)); IsSuccess = true; yield return(null); }
public override Variable Construct(ArgumentInfo arguments) { if (ConstructorScopes is null) { ConstructorScopes = InnerScope.CreateChildren(3); } if (ConstructorOverloads is null) { ConstructorOverloads = new ParameterInfo[] { new ParameterInfo(), new ParameterInfo((true, VarString.StaticTypeName, "type", ConstructorScopes[0])), new ParameterInfo((true, VarString.StaticTypeName, "type", ConstructorScopes[1]), (true, VarString.StaticTypeName, "name", ConstructorScopes[1])), } } ; (ParameterInfo match, int index) = ParameterInfo.HighestMatch(ConstructorOverloads, arguments); match.Grab(arguments); string name, type; switch (index) { case 1: name = GetNextID(); type = "dummy"; goto Construct; case 2: name = GetNextID(); type = (match["type"].Value as VarString).GetConstant(); goto Construct; case 3: name = (match["name"].Value as VarString).GetConstant(); type = (match["type"].Value as VarString).GetConstant(); goto Construct; Construct: var value = new VarObjective(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope) { Type = type, ID = name }; if (ObjectiveIDs.ContainsKey(value.ID)) { throw new Compiler.InternalError($"Duplicate {StaticTypeName} ID created.", arguments.ScriptTrace); } else { ObjectiveIDs.Add(value.ID, this); } value.Constructed = true; return(value); default: throw new MissingOverloadException("Objective constructor", index, arguments); }
/// <summary> /// Resets the loop. /// </summary> protected override void OnReset() { DoLoop = true; TotalItemsCount = 0; if (ItemList != null) { TotalItemsCount = ItemList.Count(); } CurrentIteration = 0; InnerScope.Reset(); }
/// <inheritdoc /> /// <summary> /// Called when this Step gets executed. /// </summary> /// <param name="context">Current job context.</param> /// <returns></returns> protected override IEnumerator OnExecute(JobContext context) { InnerScope.ScopeContext = new JobContext(context); if (InnerScope.Steps.Count == 0) { IsSuccess = true; yield break; } foreach (var item in ItemList) { if (!DoLoop) { break; } OnIterationStart(CurrentIteration); InnerScope.Reset(); var iteratorVariable = Field <object> .Create(IteratorName.Trim('%'), item, false, true); var indexCountVariable = Field <object> .Create(IndexCountName.Trim('%'), CurrentIteration, false, true); // update the iterator job context InnerScope.ScopeContext.Add(iteratorVariable); InnerScope.ScopeContext.Add(indexCountVariable); // reset the inner scope and loop through the child steps yield return(EditorCoroutines.StartCoroutine(InnerScope.StartExecutingSteps(), this)); OnIterationEnd(CurrentIteration); if (!IsSuppressed) { switch (InnerScope.Request) { case StepRequest.ExitScope: case StepRequest.RootScope: case StepRequest.TerminateJob: DoLoop = false; break; } } CurrentIteration++; } IsSuccess = true; yield return(null); }
static void Main() { DateTime now = DateTime.UtcNow; OuterScope outer = new OuterScope(); outer.hour = now.Hour; if (outer.hour > 5) { InnerScope inner = new InnerScope(); inner.minute = now.Minute; PrintValues(ref outer, ref inner); } }
/// <inheritdoc /> /// <summary> /// Executes this step. /// </summary> /// <param name="context">Current job context.</param> /// <returns>Returns true if execution was successful.</returns> protected override IEnumerator OnExecute(JobContext context) { var isConditionTrue = ConditionCollection.EvaluateAll(context); if (isConditionTrue) { InnerScope.ScopeContext = context; yield return(EditorCoroutines.StartCoroutine(InnerScope.StartExecutingSteps(), this)); PostExecutionRequest = StepRequest.SkipNext; } else { foreach (var child in Children) { child.Status = StepStatus.Skipped; yield return(null); } } IsSuccess = true; yield return(null); }
static void Main() { List <Action> actions = new List <Action>(); for (int i = 0; i < 5; i++) { OuterScope outer = new OuterScope(); outer.copyOfI = i; for (int j = 0; j < 5; j++) { InnerScope inner = new InnerScope(); inner.outer = outer; inner.copyOfJ = j; actions.Add(inner.Action); } } foreach (Action action in actions) { action(); } }
/// <summary> /// Resets the loop. /// </summary> protected override void OnReset() { DoLoop = true; CurrentIteration = 0; InnerScope.Reset(); }
/// <inheritdoc /> protected override void OnReset() { InnerScope.Reset(); }
static void PrintValues(ref OuterScope outer, ref InnerScope inner) { Console.WriteLine($"hour = {outer.hour}; minute = {inner.minute}"); }
public VarWorld(string name) : base(Access.Public, Usage.Static, name, Compiler.RootScope) { Compiler.Scope[] scopesSetTime = InnerScope.CreateChildren(1); ParameterInfo[] infoSetTime = new ParameterInfo[] { new ParameterInfo( (true, VarString.StaticTypeName, "time", scopesSetTime[0]) ) }; Methods.Add("SetTime", arguments => { (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoSetTime, arguments); match.Grab(arguments); switch (index) { case 0: new Spy(null, $"time set {match["time"].Value.GetConstant()}", null); return(null); default: throw new MissingOverloadException($"{TypeName}.SetTime", index, arguments); } }); Compiler.Scope[] scopesAddTime = InnerScope.CreateChildren(1); ParameterInfo[] infoAddTime = new ParameterInfo[] { new ParameterInfo( (true, VarString.StaticTypeName, "time", scopesAddTime[0]) ) }; Methods.Add("AddTime", arguments => { (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoAddTime, arguments); match.Grab(arguments); string amount; switch (index) { case 0: amount = match["time"].Value.GetConstant(); goto AddTime; AddTime: new Spy(null, $"time add {amount}", null); return(null); default: throw new MissingOverloadException($"{TypeName}.AddTime", index, arguments); } }); Compiler.Scope[] scopesGetTime = InnerScope.CreateChildren(2); ParameterInfo[] infoGetTime = new ParameterInfo[] { new ParameterInfo( (true, VarString.StaticTypeName, "type", scopesGetTime[0]) ), }; Methods.Add("GetTime", arguments => { (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoGetTime, arguments); match.Grab(arguments); VarInt result = new VarInt(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope); string type; switch (index) { case 0: type = match[0].Value.GetConstant(); result.SetValue(-1); goto GetTime; case 1: type = match[0].Value.GetConstant(); result.SetValue(match[1].Value as VarSelector, match[2].Value as VarObjective); goto GetTime; GetTime: new Spy(null, $"execute store result score {result.Selector.GetConstant()} {result.Objective.GetConstant()} run time query {type}", null); return(result); default: throw new MissingOverloadException($"{TypeName}.GetTime", index, arguments); } }); }
public VarScoreboard(string name) : base(Access.Public, Usage.Static, name, Compiler.RootScope) { Compiler.Scope[] scopesGetScore = InnerScope.CreateChildren(1); ParameterInfo[] infoGetScore = new ParameterInfo[] { new ParameterInfo( (true, VarSelector.StaticTypeName, "selection", scopesGetScore[0]), (true, VarObjective.StaticTypeName, "from", scopesGetScore[0]) ) }; Methods.Add("GetScore", arguments => { (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoGetScore, arguments); match.Grab(arguments); VarInt value = new VarInt(Access.Private, Usage.Default, GetNextHiddenID(), Compiler.CurrentScope); VarSelector selector; VarObjective objective; switch (index) { case 0: selector = match[0].Value as VarSelector; objective = match[1].Value as VarObjective; goto GetScore; GetScore: value.SetValue(selector, objective); return(value); default: throw new MissingOverloadException($"{TypeName}.GetScore", index, arguments); } }); Compiler.Scope[] scopesSetScore = InnerScope.CreateChildren(2); ParameterInfo[] infoSetScore = new ParameterInfo[] { new ParameterInfo( (true, VarSelector.StaticTypeName, "targets", scopesSetScore[0]), (true, VarObjective.StaticTypeName, "storage", scopesSetScore[0]), (true, VarInt.StaticTypeName, "from", scopesSetScore[0]) ), new ParameterInfo( (true, VarSelector.StaticTypeName, "targets", scopesSetScore[1]), (true, VarObjective.StaticTypeName, "storage", scopesSetScore[1]), (true, VarSelector.StaticTypeName, "selection", scopesSetScore[1]), (true, VarObjective.StaticTypeName, "from", scopesSetScore[1]) ) }; Methods.Add("SetScore", arguments => { (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoSetScore, arguments); match.Grab(arguments); (VarSelector Selector, VarObjective Objective)to, from; int fromConst; switch (index) { case 0: { var toSel = match[0].Value as VarSelector; var toObj = match[1].Value as VarObjective; to = (toSel, toObj); var fromInt = match[2].Value as VarInt; if (fromInt.Usage == Usage.Constant) { fromConst = fromInt.Constant; goto SetScoreConst; } else { from = (fromInt.Selector, fromInt.Objective); goto SetScore; } } case 1: { var toSel = match[0].Value as VarSelector; var toObj = match[1].Value as VarObjective; to = (toSel, toObj); var fromSel = match[2].Value as VarSelector; var fromObj = match[3].Value as VarObjective; from = (fromSel, fromObj); goto SetScore; } SetScore: new Spy(null, $"scoreboard players operation " + $"{to.Selector.GetConstant()} {to.Objective.GetConstant()} = " + $"{from.Selector.GetConstant()} {from.Objective.GetConstant()}", null); return(null); SetScoreConst: new Spy(null, $"scoreboard players set " + $"{to.Selector.GetConstant()} {to.Objective.GetConstant()} " + $"{fromConst}", null); return(null); default: throw new MissingOverloadException($"{TypeName}.SetScore", index, arguments); } });