Ejemplo n.º 1
0
        public static StackObject *EnumHasFlag(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            var       ret    = esp - 1 - 1;
            AppDomain domain = intp.AppDomain;

            var    p   = esp - 1;
            object val = StackObject.ToObject(p, domain, mStack);

            intp.Free(p);

            p = esp - 1 - 1;
            object ins = StackObject.ToObject(p, domain, mStack);

            intp.Free(p);

            bool res = false;

            if (ins is ILEnumTypeInstance enumIns)
            {
                int num    = enumIns.Fields[0].Value;
                int valNum = ((ILEnumTypeInstance)val).Fields[0].Value;
                res = (num & valNum) == valNum;
            }
            else
            {
                res = ((Enum)ins).HasFlag((Enum)val);
            }
            if (res)
                return(ILIntepreter.PushOne(ret)); }
Ejemplo n.º 2
0
        /*public unsafe static object DelegateEqulity(ILContext ctx, object instance, object[] param, IType[] genericArguments)
         * {
         *  //op_Equality,op_Inequality
         *  var esp = ctx.ESP;
         *  var mStack = ctx.ManagedStack;
         *  var domain = ctx.AppDomain;
         *
         *  var dele1 = StackObject.ToObject((esp - 1 - 1), domain, mStack);
         *  var dele2 = StackObject.ToObject((esp - 1), domain, mStack);
         *
         *  if (dele1 != null)
         *  {
         *      if (dele2 != null)
         *      {
         *          if (dele1 is IDelegateAdapter)
         *          {
         *              if (dele2 is IDelegateAdapter)
         *                  return ((IDelegateAdapter)dele1).Equals((IDelegateAdapter)dele2);
         *              else
         *                  return ((IDelegateAdapter)dele1).Equals((Delegate)dele2);
         *          }
         *          else
         *          {
         *              if (dele2 is IDelegateAdapter)
         *              {
         *                  return (Delegate)dele1 == ((IDelegateAdapter)dele2).GetConvertor(dele1.GetType());
         *              }
         *              else
         *                  return (Delegate)dele1 == (Delegate)dele2;
         *          }
         *      }
         *      else
         *          return dele1 == null;
         *  }
         *  else
         *      return dele2 == null;
         * }*/

        public unsafe static StackObject *DelegateInequlity(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            //Don't ask me why not esp -2, unity won't return the right result
            var       ret    = esp - 1 - 1;
            AppDomain domain = intp.AppDomain;
            var       param  = esp - 1;
            object    dele2  = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = esp - 1 - 1;
            object dele1 = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            bool res = false;

            if (dele1 != null)
            {
                if (dele2 != null)
                {
                    if (dele1 is IDelegateAdapter)
                    {
                        if (dele2 is IDelegateAdapter)
                        {
                            res = !((IDelegateAdapter)dele1).Equals((IDelegateAdapter)dele2);
                        }
                        else
                        {
                            res = !((IDelegateAdapter)dele1).Equals((Delegate)dele2);
                        }
                    }
                    else
                    {
                        if (dele2 is IDelegateAdapter)
                        {
                            res = (Delegate)dele1 != ((IDelegateAdapter)dele2).GetConvertor(dele1.GetType());
                        }
                        else
                        {
                            res = (Delegate)dele1 != (Delegate)dele2;
                        }
                    }
                }
                else
                {
                    res = dele1 != null;
                }
            }
            else
            {
                res = dele2 != null;
            }
            if (res)
                return(ILIntepreter.PushOne(ret)); }
Ejemplo n.º 3
0
        public static StackObject *TypeEquals(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            var       ret     = ILIntepreter.Minus(esp, 2);
            var       p       = esp - 1;
            AppDomain dommain = intp.AppDomain;
            var       other   = StackObject.ToObject(p, dommain, mStack);

            intp.Free(p);
            p = ILIntepreter.Minus(esp, 2);
            var instance = StackObject.ToObject(p, dommain, mStack);

            intp.Free(p);
            if (instance is ILRuntimeType)
            {
                if (other is ILRuntimeType)
                {
                    if (((ILRuntimeType)instance).ILType == ((ILRuntimeType)other).ILType)
                    {
                        return(ILIntepreter.PushOne(ret));
                    }
                    else
                    {
                        return(ILIntepreter.PushZero(ret));
                    }
                }
                else
                {
                    return(ILIntepreter.PushZero(ret));
                }
            }
            else
            {
                if (((Type)typeof(Type).CheckCLRTypes(instance)).Equals(((Type)typeof(Type).CheckCLRTypes(other))))
                {
                    return(ILIntepreter.PushOne(ret));
                }
                else
                {
                    return(ILIntepreter.PushZero(ret));
                }
            }
        }