/// <summary> /// Schedules the condition for this effect to a gate converter. /// </summary> /// <param name="gc"></param> public void Schedule(GateConverter gc) { foreach (var entry in _map.Values) { if (entry.PreCondition.IsFalse()) { // never reached continue; } var result = Gate.Constant(false); //entry.ConditionLabel = pre; foreach (var element in entry.Elements) { var pre = gc.ConvertToGate(0, element.PreCondition); var post = gc.ConvertToGate(1, element.PostCondition); // in code label space now var product = Gate.ComposeAND(pre, post); result = Gate.ComposeOR(result, product); } gc.Schedule(result); // assigning a code label makes this entry part of the game entry.ConditionLabel = gc.ConvertToGate(1, result); } }
public void SMG_04_03_CodeLabels() { GateCache.Instance.Purge(); var cc = new StateMachineCompiler(); var sm = cc.CompileString( "SMG test " + "DECLARE State (a, b, c) s, t " + "TRIGGER e WHEN s(a => b) AND t(b) " + "GUARD WHEN s(* => b) AND t(b) CALL m1 " + "" ); sm.Calculate(); PrintEventEffectConditions(sm); var ev = sm.Events.Where(e => e.Name == "e").First(); using (var gc = new GateConverter()) { ev.EffectsAfter.Schedule(gc); var cle = new SimpleCodeLabelEvaluator(); // Trace("gc: \n{0}", gc.ToDebugString()); gc.Emit(cle, 0); } var eclist = ev.EffectsAfter.GetEffectConditions(); var ec = eclist.Where(a => a.Effect.UniqueID == "CALL m1").First(); Assert.AreEqual("<_c0><_c1>", ec.ConditionLabel.ToString()); /*var sb = new StringBuilder(); * using (var w = new StringWriter(sb)) * { * w.Write(sm.GenerateCode()); * } * * Trace("code:\n{0}", sb);*/ }
private IGate Convert(GateConverter gc, int stage, IGate c) { //return gc.ConvertToGate(stage, c); return(c); }
/*internal IGate EvaluateAndCompose(GateConverter gc, IGate pre, IGate post) * { * switch (GuardType) * { * case GuardType.LEAVE: * pre = Gate.ComposeAND(pre, PreCondition); * break; * * case GuardType.TRANSITION: * c = Gate.ComposeAND(c, Convert(gc, 0, PreCondition)); * c = Gate.ComposeAND(c, Convert(gc, 1, PostCondition)); * break; * * case GuardType.ENTER: * c = Gate.ComposeAND(c, Convert(gc, 1, PostCondition)); * break; * * default: * throw new ArgumentException("invalid guard type."); * } * * return c; * }*/ private IGate Compose(GateConverter gc, IGate c, IGate a) { return(Gate.ComposeAND(c, a)); //return Gate.ComposeAND(c, Convert(gc, 0, a)); }