Exemple #1
0
        public TrainList Sort()
        {
            switch (fieldForCompare)
            {
            case "Ost":
            {
                cmp = ostCmp;
                break;
            }

            case "Number":
            {
                cmp = numberCmp;
                break;
            }

            case "Time":
            {
                cmp = timeCmp;
                break;
            }

            default:
                throw new ArgumentException();
            }
            return(QuickSort(trains, 0, trains.Count - 1));
        }
Exemple #2
0
        /// <summary>Populate the combo of BT radios</summary>
        private void PopulateRadios()
        {
            // Get the available radios
            var radios = Bluetooth.Radios().ToList();

            if (radios.Count != 0)
            {
                radios.Insert(0, new Bluetooth.Radio(new SafeFileHandle(IntPtr.Zero, false)));
            }

            // Update the combo of radios
            if (radios.Count == 0)
            {
                m_cb_radio.DataSource = new[] { "Bluetooth Disabled" };
                Radio = null;
            }
            else
            {
                // Compare to the existing list so the combo isn't changed unnecessarily
                var curr = m_cb_radio.DataSource as List <Bluetooth.Radio>;
                if (curr == null || !curr.SequenceEqual(radios, Cmp <Bluetooth.Radio> .From((l, r) => l.Name.CompareTo(r.Name))))
                {
                    m_cb_radio.DataSource = radios;

                    // Select the same radio again
                    var name = Radio?.Name;
                    Radio = radios.FirstOrDefault(x => x.Name == name) ?? radios[0];
                }
            }
        }
        public void Post()
        {
            //--------post
            //Prueba de creación de extintor vía HTTP POST
            string postdata = "{\"TxDescripcion\":\"Olenka Escobar\",\"TxDoc_Identidad\":\"00000000\"}";//JSON

            byte[]         data = Encoding.UTF8.GetBytes(postdata);
            HttpWebRequest req  = (HttpWebRequest)WebRequest
                                  .Create("http://localhost:1921/CMPs.svc/CMPs");

            req.Method        = "POST";
            req.ContentLength = data.Length;
            req.ContentType   = "application/json";
            var reqStream = req.GetRequestStream();

            reqStream.Write(data, 0, data.Length);
            var                  res       = (HttpWebResponse)req.GetResponse();
            StreamReader         reader    = new StreamReader(res.GetResponseStream());
            string               cmpJson   = reader.ReadToEnd();
            JavaScriptSerializer js        = new JavaScriptSerializer();
            Cmp                  cmpCreado = js.Deserialize <Cmp>(cmpJson);

            Assert.AreEqual("Olenka Escobar", cmpCreado.TxDescripcion);
            Assert.AreEqual("00000000", cmpCreado.TxDoc_Identidad);
        }
 void FixedUpdate()
 {
     foreach (var Cmp in Components)
     {
         Cmp.OnFixedUpdate();
     }
 }
Exemple #5
0
        public static void *QuickSelect(void **arr, int len, int k, Cmp cmp)
        {
            void **temp = stackalloc void *[len];

            Mem.Memcpy(temp, arr, len * sizeof(void *));
            return(QuickSelect(temp, 0, len - 1, k, cmp));
        }
Exemple #6
0
        static void QuickSort(void **arr, int low, int high, Cmp cmp)
        {
            if (low >= high)
            {
                return;
            }

            void *pivot = arr[low]; void *swap;
            int   mid = low;

            for (int j = low + 1; j <= high; j += 1)
            {
                if (cmp(swap = arr[j], pivot) < 0)
                {
                    mid     += 1;
                    arr[j]   = arr[mid];
                    arr[mid] = swap;
                }
            }
            if (mid != low)
            {
                swap     = arr[mid];
                arr[mid] = arr[low];
                arr[low] = swap;
            }

            QuickSort(arr, low, mid - 1, cmp);
            QuickSort(arr, mid + 1, high, cmp);
        }
Exemple #7
0
 public override void Register(SystemRenderer renderer)
 {
     sysr = renderer;
     sysr.Objects.Add(this);
     if (!inited)
     {
         if (Dfm != null)
         {
             Dfm.Initialize(sysr.Game.ResourceManager);
         }
         if (Model != null && Model.Levels.Length > 0)
         {
             Model.Initialize(sysr.Game.ResourceManager);
         }
         else if (Cmp != null)
         {
             Cmp.Initialize(sysr.Game.ResourceManager);
         }
         else if (Sph != null)
         {
             Sph.Initialize(sysr.Game.ResourceManager);
             if (Sph.SideMaterials.Length > 6)
             {
                 radiusAtmosphere = Sph.Radius * Sph.SideMaterials[6].Scale;
             }
             else
             {
                 radiusAtmosphere = Sph.Radius;
             }
         }
         inited = true;
     }
 }
Exemple #8
0
        public Cmp ComparisonFromOpName(Operation op)
        {
            Cmp toret = null;

            switch (op)
            {
            case Operation.EQ:
                toret = this.CmpEQ;
                break;

            case Operation.NEQ:
                toret = this.CmpNEQ;
                break;

            case Operation.GT:
                toret = this.CmpGT;
                break;

            case Operation.LT:
                toret = this.CmpLT;
                break;

            case Operation.GTE:
                toret = this.CmpGTE;
                break;

            case Operation.LTE:
                toret = this.CmpLTE;
                break;
            }

            return(toret);
        }
Exemple #9
0
        public void TryParse_AllowCustomQualifiedComparison_ForDomainSpecificSorting()
        {
            string languages = "text/*, text/plain";

            Predicate <Qualified> isSubtype = q => q.Value.EndsWith("*");

            Comparison <Qualified> subtypesComeLater = (q1, q2) =>
            {
                var quality = q1.Quality.CompareTo(q2.Quality);
                if (quality == 0)
                {
                    if (isSubtype(q1) && !isSubtype(q2))
                    {
                        return(-1);
                    }
                    if (!isSubtype(q1) && isSubtype(q2))
                    {
                        return(1);
                    }
                    return(StringComparer.Ordinal.Compare(q1.Value, q2.Value));
                }
                return(quality);
            };

            var subject = QualifiedCollection.TryParse(languages, Cmp <Qualified> .By(subtypesComeLater));

            Assert.That(subject, Is.EqualTo(new[]
            {
                new Qualified("text/plain", Quality.Default),
                new Qualified("text/*", Quality.Default)
            }).Using(_equalizer));
        }
Exemple #10
0
        public static int BinarySearchWithTimeRange(this IList <IIndexedDict> items, int[] keysNdxs, object[] keysValues, ITimedObject timeRange)
        {
            int n = items.Count;
            int ia = 0, ib = n - 1;

            while (ia <= ib)
            {
                int i = (ia + ib) / 2;
                int r = Cmp.CompareKeysWithTimeRange(items[i].ValuesList, keysNdxs, keysValues, timeRange);
                if (r > 0)
                {
                    ib = i - 1;
                    if (ib < ia)
                    {
                        return(~i);
                    }
                }
                else if (r < 0)
                {
                    ia = i + 1;
                    if (ib < ia)
                    {
                        return(~ia);
                    }
                }
                else
                {
                    return(i);
                }
            }
            return(~0);
        }
 void Init()
 {
     if (!inited)
     {
         if (Dfm != null)
         {
             Dfm.Initialize(sysr.ResourceManager);
         }
         if (Model != null && Model.Levels.Length > 0)
         {
             Model.Initialize(sysr.ResourceManager);
         }
         else if (Cmp != null)
         {
             Cmp.Initialize(sysr.ResourceManager);
         }
         else if (Sph != null)
         {
             Sph.Initialize(sysr.ResourceManager);
             if (Sph.SideMaterials.Length > 6)
             {
                 radiusAtmosphere = Sph.Radius * Math.Max(Sph.SideMaterials[6].Scale, 1f);
             }
             else
             {
                 radiusAtmosphere = Sph.Radius;
             }
         }
         inited = true;
     }
 }
 public void LargestOf3Alt()
 {
     int[] numbers = new int[3];
     numbers[0] = 8;
     numbers[1] = 9;
     numbers[2] = 7;
     Assert.That(Cmp.Largest(numbers), Is.EqualTo(9));
 }
        public Cmp consultarCmp(int intIdCMP)
        {
            Cmp cmp = null;

            cmp = CmpDAO.Obtener(intIdCMP);

            return(cmp);
        }
Exemple #14
0
 public LocalityNode(string name, AdminDistrictNode parent)
 {
     this.Children  = new Dictionary <String, LocationNode>(Cmp);
     this.Parent    = parent;
     this.Key       = name;
     this.Formatted = Helpers.FormatAddress(null, null, CityName, StateNode?.Abbreviation ?? StateNode?.Key, null, CountryName);
     unchecked { _hashcode = (typeof(LocalityNode).GetHashCode() * 397) ^ Cmp.GetHashCode(Formatted); }
 }
Exemple #15
0
        public void Clients_DoNotHaveToCareAboutNulls()
        {
            var subject = Cmp <OperatorsOnly> .FromOperators();

            Assert.That(subject.Compare(null, null), Is.EqualTo(0));
            Assert.That(subject.Compare(new OperatorsOnly(1), null), Is.GreaterThan(0));
            Assert.That(subject.Compare(null, new OperatorsOnly(1)), Is.LessThan(0));
        }
Exemple #16
0
 public static int BinarySearch(void **arr, int len, void *val, Cmp cmp)
 {
                 #if FDB
     Should.NotNull("arr", arr);
     Should.GreaterThanZero("len", len);
     Should.NotNull("cmp", cmp);
                 #endif
     return(BinarySearch(arr, 0, len - 1, val, cmp));
 }
Exemple #17
0
        internal void If(Cmp cmpOp)
        {
            IfState ifState = new IfState();

            ifState.EndIf     = DefineLabel();
            ifState.ElseBegin = DefineLabel();
            _ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
            _blockStack.Push(ifState);
        }
Exemple #18
0
 public static void QuickSort(void **arr, int len, Cmp cmp)
 {
                 #if FDB
     Should.NotNull("arr", arr);
     Should.GreaterThanZero("len", len);
     Should.NotNull("cmp", cmp);
                 #endif
     QuickSort(arr, 0, len - 1, cmp);
 }
Exemple #19
0
        public static IEnumerable <int> BinarySearchAllWithTimeRange(this IList <IIndexedDict> items, int[] keysNdxs, object[] keysValues, ITimedObject timeRange)
        {
            if (items == null)
            {
                yield break;
            }
            int n = items.Count;

            if (n == 0)
            {
                yield break;
            }
            int i = BinarySearchWithTimeRange(items, keysNdxs, keysValues, timeRange);

            if (i < 0)
            {
                i = 0; yield break;
            }
            var Imax = i;

            while (i > 0 && Cmp.CompareKeysWithTimeRange(items[i - 1].ValuesList, keysNdxs, keysValues, timeRange) == 0)
            {
                i--;
            }
            var prevEndTime = DateTime.MinValue;

            while (i <= Imax)
            {
#if CHECK_DATA_DUPS
                if (i < Imax && Cmp.CompareTimed(items[i].ValuesList, items[i + 1].ValuesList) == 0)
                {
                    DupDataError(items[i]);
                    i++; continue;
                }
#endif
                yield return(i++);
            }
            while (i < n)
            {
                if (Cmp.CompareKeysWithTimeRange(items[i].ValuesList, keysNdxs, keysValues, timeRange) == 0)
                {
#if CHECK_DATA_DUPS
                    if (Cmp.CompareTimed(items[i - 1].ValuesList, items[i].ValuesList) == 0)
                    {
                        DupDataError(items[i]);
                        i++; continue;
                    }
#endif
                    yield return(i++);
                }
                else
                {
                    yield break;
                }
            }
        }
Exemple #20
0
 public static void MergeSort(void **arr, int len, Cmp cmp)
 {
                 #if FDB
     Should.NotNull("arr", arr);
     Should.GreaterThanZero("len", len);
     Should.NotNull("cmp", cmp);
                 #endif
     void **temp = stackalloc void *[len];
     MergeSort(arr, temp, 0, len - 1, cmp);
 }
        public void MinBy_AlternativeComparer_MinimumValueAccordingToSelectorAndComparer()
        {
            var twoOne     = new OrderSubject(2, 1);
            var collection = new[] { new OrderSubject(2, -2), twoOne };

            IComparer <int> absComparer = Cmp <int>
                                          .By((one, other) => Math.Abs(one).CompareTo(Math.Abs(other)));

            Assert.That(collection.MinBy(s => s.I2, absComparer), Is.SameAs(twoOne));
        }
        public void ChainableComparer_By3Then2_FactoredWithSelectors()
        {
            _subjects.Sort(Cmp <ComparisonSubject> .By(c => c.Property3)
                           .Then(c => c.Property2, Direction.Ascending));
            Assert.That(_subjects, Must.Be.RepresentableAs("B, D, E, C, A"));

            _subjects.Sort(Cmp <ComparisonSubject> .By(c => c.Property3)
                           .Then(c => c.Property2, Direction.Descending));
            Assert.That(_subjects, Must.Be.RepresentableAs("B, D, E, C, A"));
        }
        public void MaxBy_AlternativeComparer_MinimumValueAccordingToSelectorAndComparer()
        {
            var twoMinusTwo = new OrderSubject(2, -2);
            var collection  = new[] { new OrderSubject(2, -1), twoMinusTwo };

            IComparer <int> absComparer = Cmp <int>
                                          .By((one, other) => Math.Abs(one).CompareTo(Math.Abs(other)));

            Assert.That(collection.MaxBy(s => s.I2, absComparer), Is.EqualTo(twoMinusTwo));
        }
        public Cmp actualizarCmp(int intIdCMP, string strtxDescripcion, string strtxDoc_Identidad)
        {
            Cmp asesorAModificar = new Cmp()
            {
                IdCmp           = intIdCMP,
                TxDescripcion   = strtxDescripcion,
                TxDoc_Identidad = strtxDoc_Identidad
            };

            return(CmpDAO.Modificar(asesorAModificar));
        }
        public void ChaineableComparer_CanBeUsedWithLinq()
        {
            Assert.That(_subjects.OrderBy(s => s, Cmp <ComparisonSubject>
                                          .By(s => s.Property3)
                                          .Then(s => s.Property2)),
                        Must.Be.RepresentableAs("B, D, E, C, A"));

            Assert.That(_subjects.OrderBy(s => s, Cmp <ComparisonSubject>
                                          .By(s => s.Property3)
                                          .Then(s => s.Property2, Direction.Descending)),
                        Must.Be.RepresentableAs("B, D, E, C, A"));
        }
        /// <summary>Populate the directory tree</summary>
        private void SetupTree()
        {
            // Sort directories alphabetically
            m_tree.TreeViewNodeSorter = Cmp <TreeNode> .From((l, r) => string.Compare(l.Name, r.Name));

            // Dynamically add sub directory nodes as needed
            m_tree.NodesNeeded += (s, a) =>
            {
                if (a.Node.Nodes.Count != 0)
                {
                    return;
                }
                PopulateChildNodes(a.Node);
            };

            // Populate the tree with the drives
            foreach (var dv in DriveInfo.GetDrives())
            {
                if (!dv.IsReady)
                {
                    continue;
                }
                var drive = dv.Name.TrimEnd('\\');
                var node  = new TreeNode(drive, TreeNode.ETriState.Unchecked);
                m_tree.Nodes.Add(node);
                PopulateChildNodes(node);
            }

            // Checking a node adds or removes that path from the list
            m_tree.AfterCheck += (s, a) =>
            {
                if (m_updating_check_marks != null)
                {
                    return;
                }

                // Add or remove the path
                var path = new Path(a.Node.FullPath);
                if (a.Node.Checked)
                {
                    Paths.AddOrdered(path, Path.Compare);
                }
                else
                {
                    // If 'path' is in the list, then the ListChanging handler will call HandlePathRemoved
                    // If not in the list, then we need to call it explicitly
                    if (!Paths.Remove(path))
                    {
                        HandlePathRemoved(path);
                    }
                }
            };
        }
        public void Explore()
        {
            IComparer <ComparisonSubject> subject = new SelectorComparer <ComparisonSubject, int>(s => s.Property2, Direction.Descending);

            Assert.That(subject.Compare(ComparisonSubject.One, ComparisonSubject.Two), Is.GreaterThan(0));

            IComparer <ComparisonSubject> by3Then2Desc = new SelectorComparer <ComparisonSubject, decimal>(s => s.Property3)
                                                         .Then(s => s.Property2, Direction.Descending);

            by3Then2Desc = Cmp <ComparisonSubject> .By(s => s.Property3)
                           .Then(s => s.Property2, Direction.Descending);
        }
        public Cmp crearCmp(string strtxDescripcion, string strtxDoc_Identidad)
        {
            Cmp nuevoCmp  = null;
            Cmp CmpACrear = new Cmp()
            {
                TxDescripcion   = strtxDescripcion,
                TxDoc_Identidad = strtxDoc_Identidad
            };

            nuevoCmp = CmpDAO.Crear(CmpACrear);

            return(nuevoCmp);
        }
Exemple #29
0
        static void MergeSort(void **arr, void **temp, int low, int high, Cmp cmp)
        {
            if (low >= high)
            {
                return;
            }

            void *swap;

            if (low == high - 1)
            {
                if (cmp(swap = arr[low], arr[high]) > 0)
                {
                    arr[low]  = arr[high];
                    arr[high] = swap;
                }
                return;
            }

            int mid = (low + high) >> 1;

            MergeSort(arr, temp, low, mid, cmp);
            MergeSort(arr, temp, mid + 1, high, cmp);

            int i = low, j = mid + 1, k = low;

            while (i <= mid && j <= high)
            {
                if (cmp(arr[i], arr[j]) < 0)
                {
                    temp[k++] = arr[i++];
                }
                else
                {
                    temp[k++] = arr[j++];
                }
            }
            while (i <= mid)
            {
                temp[k++] = arr[i++];
            }
            while (j <= high)
            {
                temp[k++] = arr[j++];
            }

            for (k = low; k <= high; k += 1)
            {
                arr[k] = temp[k];
            }
        }
        public void get()
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:1921/CMPs.svc/CMPs/1");

            req.Method      = "GET";
            req.ContentType = "application/json";
            var                  res       = (HttpWebResponse)req.GetResponse();
            StreamReader         reader    = new StreamReader(res.GetResponseStream());
            string               CmpJson   = reader.ReadToEnd();
            JavaScriptSerializer js        = new JavaScriptSerializer();
            Cmp                  CmpCreado = js.Deserialize <Cmp>(CmpJson);

            Assert.AreEqual(1, CmpCreado.IdCmp);
        }
Exemple #31
0
 private OpCode GetBranchCode(Cmp cmp)
 {
     switch (cmp)
     {
         case Cmp.LessThan:
             return OpCodes.Bge;
         case Cmp.EqualTo:
             return OpCodes.Bne_Un;
         case Cmp.LessThanOrEqualTo:
             return OpCodes.Bgt;
         case Cmp.GreaterThan:
             return OpCodes.Ble;
         case Cmp.NotEqualTo:
             return OpCodes.Beq;
         default:
             DiagnosticUtility.DebugAssert(cmp == Cmp.GreaterThanOrEqualTo, "Unexpected cmp");
             return OpCodes.Blt;
     }
 }
 internal void AndIf(Cmp cmpOp) {
     if (initIfStack == blockStack.Count) {
         initIfStack = -1;
         If(cmpOp);
         return;
     }
     if (initElseIfStack == blockStack.Count) {
         initElseIfStack = -1;
         elseIfState.ElseBegin = DefineLabel();
         ilGen.Emit(GetBranchCode(cmpOp), elseIfState.ElseBegin);
         blockStack.Push(elseIfState);
         return;
     }
     Debug.Assert(initIfStack == -1 && initElseIfStack == -1);
     IfState ifState = (IfState)blockStack.Peek();
     ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
 }
Exemple #33
0
 internal void AndIf(Cmp cmpOp)
 {
     if (_initIfStack == _blockStack.Count)
     {
         _initIfStack = -1;
         If(cmpOp);
         return;
     }
     if (_initElseIfStack == _blockStack.Count)
     {
         _initElseIfStack = -1;
         _elseIfState.ElseBegin = DefineLabel();
         _ilGen.Emit(GetBranchCode(cmpOp), _elseIfState.ElseBegin);
         _blockStack.Push(_elseIfState);
         return;
     }
     Debug.Assert(_initIfStack == -1 && _initElseIfStack == -1);
     IfState ifState = (IfState)_blockStack.Peek();
     _ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
 }
Exemple #34
0
 private OpCode GetBranchCode(Cmp cmp)
 {
     return s_branchCodes[(int)cmp];
 }
Exemple #35
0
 /// <summary>
 /// ElseIf
 /// </summary>
 /// <param name="value1"></param>
 /// <param name="cmpOp"></param>
 /// <param name="value2"></param>
 public void ElseIf(object value1, Cmp cmpOp, object value2)
 {
     IfState state = (IfState)this.blockStack.Pop();
     this.Br(state.EndIf);
     this.MarkLabel(state.ElseBegin);
     this.Load(value1);
     this.Load(value2);
     state.ElseBegin = this.DefineLabel();
     this.ilGen.Emit(this.GetBranchCode(cmpOp), state.ElseBegin);
     this.blockStack.Push(state);
 }
 internal void ElseIf(object value1, Cmp cmpOp, object value2)
 {
     IfState state = (IfState) this.blockStack.Pop();
     this.Br(state.EndIf);
     this.MarkLabel(state.ElseBegin);
     this.Load(value1);
     this.Load(value2);
     state.ElseBegin = this.DefineLabel();
     if (this.codeGenTrace != CodeGenTrace.None)
     {
         this.EmitSourceInstruction("Branch if " + this.GetCmpInverse(cmpOp).ToString() + " to " + state.ElseBegin.GetHashCode().ToString(NumberFormatInfo.InvariantInfo));
     }
     this.ilGen.Emit(this.GetBranchCode(cmpOp), state.ElseBegin);
     this.blockStack.Push(state);
 }
 internal void BeginWhileBody(Cmp cmpOp)
 {
     Label startWhile = (Label) blockStack.Pop();
     If(cmpOp);
     blockStack.Push(startWhile);
 }
 internal void If(Cmp cmpOp)
 {
     IfState ifState = new IfState();
     ifState.EndIf = DefineLabel();
     ifState.ElseBegin = DefineLabel();
     if (codeGenTrace != CodeGenTrace.None)
         EmitSourceInstruction("Branch if " + GetCmpInverse(cmpOp).ToString() + " to " + ifState.ElseBegin.GetHashCode().ToString(NumberFormatInfo.InvariantInfo));
     ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
     blockStack.Push(ifState);
 }
 internal void If(object value1, Cmp cmpOp, object value2) {
     Load(value1);
     Load(value2);
     If(cmpOp);
 }
 internal void While(object value1, Cmp cmpOp, object value2)
 {
     IfState ifState = new IfState();
     ifState.EndIf = DefineLabel();
     ifState.ElseBegin = DefineLabel();
     ilGen.MarkLabel(ifState.ElseBegin);
     Load(value1);
     Load(value2);
     if (codeGenTrace != CodeGenTrace.None)
         EmitSourceInstruction("Branch if " + CmpInverse[(int) cmpOp].ToString() + " to " + ifState.ElseBegin.GetHashCode().ToString());
     ilGen.Emit(BranchCode[(int)cmpOp], ifState.EndIf);
     blockStack.Push(ifState);
 }
 Cmp GetCmpInverse(Cmp cmp)
 {
     switch (cmp) {
         case Cmp.LessThan:
             return Cmp.GreaterThanOrEqualTo;
         case Cmp.EqualTo:
             return Cmp.NotEqualTo;
         case Cmp.LessThanOrEqualTo:
             return Cmp.GreaterThan;
         case Cmp.GreaterThan:
             return Cmp.LessThanOrEqualTo;
         case Cmp.NotEqualTo:
             return Cmp.EqualTo;
         default:
             Debug.Assert(cmp == Cmp.GreaterThanOrEqualTo, "Unexpected cmp");
             return Cmp.LessThan;
     }
 }
 internal void AndIf(Cmp cmpOp)
 {
     IfState ifState = (IfState) blockStack.Peek();
     if (codeGenTrace != CodeGenTrace.None)
         EmitSourceInstruction("Branch if " + CmpInverse[(int) cmpOp].ToString() + " to " + ifState.ElseBegin.GetHashCode().ToString());
     ilGen.Emit(BranchCode[(int)cmpOp], ifState.ElseBegin);
 }
 internal void If(Cmp cmpOp)
 {
     IfState state = new IfState {
         EndIf = this.DefineLabel(),
         ElseBegin = this.DefineLabel()
     };
     if (this.codeGenTrace != CodeGenTrace.None)
     {
         this.EmitSourceInstruction("Branch if " + this.GetCmpInverse(cmpOp).ToString() + " to " + state.ElseBegin.GetHashCode().ToString(NumberFormatInfo.InvariantInfo));
     }
     this.ilGen.Emit(this.GetBranchCode(cmpOp), state.ElseBegin);
     this.blockStack.Push(state);
 }
 internal void IfString(object s1, Cmp cmpOp, object s2)
 {
     Load(s1);
     Load(s2);
     Call(stringCompare);
     Load(0);
     If(cmpOp);
 }
 public static IEnumerable<Rectangle> Sort(List<Rectangle> list, Cmp compare)
 {
     var sortList = list
         .OrderBy(x => compare(x));
     return sortList;
 }
        internal void ElseIfString(object s1, Cmp cmpOp, object s2)
        {
            IfState ifState = (IfState)blockStack.Pop();
            Br(ifState.EndIf);
            MarkLabel(ifState.ElseBegin);

            Load(s1);
            Load(s2);
            Call(stringCompare);
            Load(0);
            ifState.ElseBegin = DefineLabel();

            if (codeGenTrace != CodeGenTrace.None)
                EmitSourceInstruction("Branch if " + CmpInverse[(int) cmpOp].ToString() + " to " + ifState.ElseBegin.GetHashCode().ToString(NumberFormatInfo.InvariantInfo));

            ilGen.Emit(BranchCode[(int)cmpOp], ifState.ElseBegin);
            blockStack.Push(ifState);
        }
        internal void ElseIf(object value1, Cmp cmpOp, object value2)
        {
            IfState ifState = (IfState)blockStack.Pop();
            Br(ifState.EndIf);
            MarkLabel(ifState.ElseBegin);

            Load(value1);
            Load(value2);
            ifState.ElseBegin = DefineLabel();

            if (codeGenTrace != CodeGenTrace.None)
                EmitSourceInstruction("Branch if " + GetCmpInverse(cmpOp).ToString() + " to " + ifState.ElseBegin.GetHashCode().ToString(NumberFormatInfo.InvariantInfo));

            ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
            blockStack.Push(ifState);
        }
 internal void AndWhile(Cmp cmpOp)
 {
     object startWhile = blockStack.Pop();
     AndIf(cmpOp);
     blockStack.Push(startWhile);
 }
Exemple #49
0
        private OpCode GetBranchCode(Cmp cmp)
        {
            switch (cmp)
            {
                case Cmp.LessThan:
                    return OpCodes.Bge;

                case Cmp.EqualTo:
                    return OpCodes.Bne_Un;

                case Cmp.LessThanOrEqualTo:
                    return OpCodes.Bgt;

                case Cmp.GreaterThan:
                    return OpCodes.Ble;

                case Cmp.NotEqualTo:
                    return OpCodes.Beq;
            }
            return OpCodes.Blt;
        }
 OpCode GetBranchCode(Cmp cmp) {
     return BranchCodes[(int)cmp];
 }
Exemple #51
0
        private Cmp GetCmpInverse(Cmp cmp)
        {
            switch (cmp)
            {
                case Cmp.LessThan:
                    return Cmp.GreaterThanOrEqualTo;

                case Cmp.EqualTo:
                    return Cmp.NotEqualTo;

                case Cmp.LessThanOrEqualTo:
                    return Cmp.GreaterThan;

                case Cmp.GreaterThan:
                    return Cmp.LessThanOrEqualTo;

                case Cmp.NotEqualTo:
                    return Cmp.EqualTo;
            }
            return Cmp.LessThan;
        }
 internal void If(Cmp cmpOp) {
     IfState ifState = new IfState();
     ifState.EndIf = DefineLabel();
     ifState.ElseBegin = DefineLabel();
     ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
     blockStack.Push(ifState);
 }
Exemple #53
0
 /// <summary>
 /// If
 /// </summary>
 /// <param name="cmpOp"></param>
 public void If(Cmp cmpOp)
 {
     IfState state = new IfState();
     state.EndIf = this.DefineLabel();
     state.ElseBegin = this.DefineLabel();
     this.ilGen.Emit(this.GetBranchCode(cmpOp), state.ElseBegin);
     this.blockStack.Push(state);
 }
        internal void ElseIf(object value1, Cmp cmpOp, object value2)
        {
            IfState ifState = (IfState)blockStack.Pop();
            Br(ifState.EndIf);
            MarkLabel(ifState.ElseBegin);

            Load(value1);
            Load(value2);
            ifState.ElseBegin = DefineLabel();
            ilGen.Emit(GetBranchCode(cmpOp), ifState.ElseBegin);
            blockStack.Push(ifState);
        }
Exemple #55
0
 /// <summary>
 /// If
 /// </summary>
 /// <param name="value1"></param>
 /// <param name="cmpOp"></param>
 /// <param name="value2"></param>
 public void If(object value1, Cmp cmpOp, object value2)
 {
     this.Load(value1);
     this.Load(value2);
     this.If(cmpOp);
 }