Example #1
0
        private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g)
        {
            if (g.Type == GateType.Input)
            {
                if (g is LabelGate)
                {
                    var lg = (LabelGate)g;
                    lg.Label.Evaluate(cg);
                }
            }
            else
            {
                var list = new List <IGate>();
                foreach (var i in g.GetInputs())
                {
                    var u = i;
                    var l = _gc.GetScheduledLabel(u);
                    if (null != l)
                    {
                        u = l;
                    }
                    else
                    {
                        u = EvaluateRecurse(cg, u);
                    }

                    list.Add(u);
                }

                g = SMG.Common.Gate.Compose(g.Type, list);
            }

            return(g);
        }
Example #2
0
 /// <summary>
 /// Evaluates the label into a code generator, once.
 /// </summary>
 /// <param name="cg">The code writer.</param>
 public void Evaluate(ICodeLabelEvaluator cg)
 {
     if (!IsEvaluated)
     {
         EvaluateOnce(cg);
         IsEvaluated = true;
     }
 }
Example #3
0
        /// <summary>
        /// Emits code to initialize labels up to the given stage.
        /// </summary>
        /// <param name="writer">To code writer where to evaluate the labels to.</param>
        /// <param name="stage">Evaluate variables scheduled up to this stage.</param>
        public void Emit(ICodeLabelEvaluator cg, int stage)
        {
            var labels = _queue.Where(l => l.Stage <= stage).ToList();

            foreach (var label in labels)
            {
                Gate.TraceLabel(label.Gate, label.OriginalGate, "emit");
                label.Evaluate(cg);
                _queue.Remove(label);
            }
        }
Example #4
0
        private IGate EvaluateRecurse(ICodeLabelEvaluator cg, IGate g)
        {
            if (g.Type == GateType.Input)
            {
                if (g is LabelGate)
                {
                    var lg = (LabelGate)g;
                    lg.Label.Evaluate(cg);
                }
            }
            else
            {
                var list = new List<IGate>();
                foreach (var i in g.GetInputs())
                {
                    var u = i;
                    var l = _gc.GetScheduledLabel(u);
                    if (null != l)
                    {
                        u = l;
                    }
                    else
                    {
                        u = EvaluateRecurse(cg, u);
                    }

                    list.Add(u);
                }

                g = SMG.Common.Gate.Compose(g.Type, list);
            }

            return g;
        }
Example #5
0
 private void EvaluateOnce(ICodeLabelEvaluator cg)
 {
     var g = EvaluateRecurse(cg, _originalgate);
     cg.EmitCodeLabelAssignment(Name, g);
 }
Example #6
0
 /// <summary>
 /// Evaluates the label into a code generator, once.
 /// </summary>
 /// <param name="cg">The code writer.</param>
 public void Evaluate(ICodeLabelEvaluator cg)
 {
     if (!IsEvaluated)
     {
         EvaluateOnce(cg);
         IsEvaluated = true;
     }
 }
Example #7
0
 /// <summary>
 /// Emits code to initialize labels up to the given stage.
 /// </summary>
 /// <param name="writer">To code writer where to evaluate the labels to.</param>
 /// <param name="stage">Evaluate variables scheduled up to this stage.</param>
 public void Emit(ICodeLabelEvaluator cg, int stage)
 {
     var labels = _queue.Where(l => l.Stage <= stage).ToList();
     foreach(var label in labels)
     {
         Gate.TraceLabel(label.Gate, label.OriginalGate, "emit");
         label.Evaluate(cg);
         _queue.Remove(label);
     }
 }
Example #8
0
        private void EvaluateOnce(ICodeLabelEvaluator cg)
        {
            var g = EvaluateRecurse(cg, _originalgate);

            cg.EmitCodeLabelAssignment(Name, g);
        }