<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics;

namespace CIL
{
    /// <summary>
    /// Methods for parsing and processing CIL opcodes.
    /// </summary>
    public static partial class IL
    {
        static readonly OpCode[] oneByteOps = new OpCode[256];
        static readonly OpCode[] twoByteOps = new OpCode[256];
        static readonly MethodInfo r8IsInfinity = typeof(double).GetMethod("IsInfinity", BindingFlags.Static | BindingFlags.Public);
        static readonly MethodInfo r4IsInfinity = typeof(float).GetMethod("IsInfinity", BindingFlags.Static | BindingFlags.Public);
        //static readonly MethodInfo blockCopy = new Action<Array, Int32, Array, Int32, Int32>(Buffer.BlockCopy).Method;
        static readonly ConstructorInfo arithError = typeof(ArithmeticException).GetConstructor(new[] { typeof(string) });
        static readonly Type nativeInt = IntPtr.Size == 8 ? typeof(long) : typeof(int);

        // looks like a nice intro if I ever support more metadata:
        // http://www.codeproject.com/Articles/42649/NET-file-format-Signatures-under-the-hood-Part

        static IL()
        {
            var type = typeof(OpCodes);
            foreach (var x in type.GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                var op = (OpCode)x.GetValue(null);
                var target = 0 == (op.Value & 0xFF00) ? oneByteOps : twoByteOps;
                target[op.Value & 0xFF] = op;
            }
        }

        /// <summary>
        /// A position in the instruction stream.
        /// </summary>
        public struct Label : IEquatable<Label>, IComparable<Label>
        {
            internal int pos;
            public override bool Equals(object obj)
            {
                return obj is Label && Equals((Label)obj);
            }
            public override int GetHashCode()
            {
                return pos;
            }
            public bool Equals(Label other)
            {
                return this == other;
            }
            public int CompareTo(Label other)
            {
                return pos.CompareTo(other);
            }
            public override string ToString()
            {
                return "IL_" + pos.ToString("X4");
            }
            public static bool operator <(Label left, Label right)
            {
                return left.pos < right.pos;
            }
            public static bool operator >(Label left, Label right)
            {
                return left.pos > right.pos;
            }
            public static bool operator <=(Label left, Label right)
            {
                return left.pos <= right.pos;
            }
            public static bool operator >=(Label left, Label right)
            {
                return left.pos >= right.pos;
            }<commit_msg>properly compare against position<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics;

namespace CIL
{
    /// <summary>
    /// Methods for parsing and processing CIL opcodes.
    /// </summary>
    public static partial class IL
    {
        static readonly OpCode[] oneByteOps = new OpCode[256];
        static readonly OpCode[] twoByteOps = new OpCode[256];
        static readonly MethodInfo r8IsInfinity = typeof(double).GetMethod("IsInfinity", BindingFlags.Static | BindingFlags.Public);
        static readonly MethodInfo r4IsInfinity = typeof(float).GetMethod("IsInfinity", BindingFlags.Static | BindingFlags.Public);
        //static readonly MethodInfo blockCopy = new Action<Array, Int32, Array, Int32, Int32>(Buffer.BlockCopy).Method;
        static readonly ConstructorInfo arithError = typeof(ArithmeticException).GetConstructor(new[] { typeof(string) });
        static readonly Type nativeInt = IntPtr.Size == 8 ? typeof(long) : typeof(int);

        // looks like a nice intro if I ever support more metadata:
        // http://www.codeproject.com/Articles/42649/NET-file-format-Signatures-under-the-hood-Part

        static IL()
        {
            var type = typeof(OpCodes);
            foreach (var x in type.GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                var op = (OpCode)x.GetValue(null);
                var target = 0 == (op.Value & 0xFF00) ? oneByteOps : twoByteOps;
                target[op.Value & 0xFF] = op;
            }
        }

        /// <summary>
        /// A position in the instruction stream.
        /// </summary>
        public struct Label : IEquatable<Label>, IComparable<Label>
        {
            internal int pos;
            public override bool Equals(object obj)
            {
                return obj is Label && Equals((Label)obj);
            }
            public override int GetHashCode()
            {
                return pos;
            }
            public bool Equals(Label other)
            {
                return this == other;
            }
            public int CompareTo(Label other)
            {
                return pos.CompareTo(other.pos);
            }
            public override string ToString()
            {
                return "IL_" + pos.ToString("X4");
            }
            public static bool operator <(Label left, Label right)
            {
                return left.pos < right.pos;
            }
            public static bool operator >(Label left, Label right)
            {
                return left.pos > right.pos;
            }
            public static bool operator <=(Label left, Label right)
            {
                return left.pos <= right.pos;
            }
            public static bool operator >=(Label left, Label right)
            {
                return left.pos >= right.pos;
            }
{'fraction_non_alphanumeric': 0.09521419009370817, 'fraction_numerical': 0.008701472556894244, 'mean_word_length': 1.7404860155891793, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6041020', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1483, 'n_words': 427}