Example #1
0
        public static HybInstance PostfixDec(HybInstance a)
        {
            if (a.IsCompiledType)
            {
                if (a.GetHybType().IsValueType)
                {
                    if (a.Is <Int64>())
                    {
                        return(HybInstance.Int64(a.As <Int64>() - 1));
                    }
                    if (a.Is <Int32>())
                    {
                        return(HybInstance.Int(a.As <Int32>() - 1));
                    }
                    if (a.Is <short>())
                    {
                        return(HybInstance.Short(a.As <short>() - 1));
                    }
                    if (a.Is <byte>())
                    {
                        return(HybInstance.Byte(a.As <byte>() - 1));
                    }
                }
            }

            var decMethod = GetDecMethod(a);

            if (decMethod != null)
            {
                return(decMethod.Target.Invoke(null, new HybInstance[] { a }));
            }

            throw new NotImplementedException();
        }
Example #2
0
        private bool IsTrueOrEquivalent(HybInstance obj)
        {
            if (obj == null)
            {
                return(false);
            }

            try
            {
                if (obj.IsCompiledType &&
                    Convert.ToInt32(obj.InnerObject) == 0)
                {
                    return(false);
                }
            }
            catch { }

            if (obj.Is <bool>() && obj.As <bool>() == false)
            {
                return(false);
            }
            if (obj.As <object>() == null)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        public static HybInstance ShiftLeft(HybInstance a, HybInstance b)
        {
            if (a.IsNull())
            {
                throw new NullReferenceException(a.Id);
            }

            if (a.GetHybType().IsPrimitive)
            {
                if (a.Is <Int32>())
                {
                    return(HybInstance.Int(a.As <Int32>() << b.As <Int32>()));
                }
                if (a.Is <Int64>())
                {
                    return(HybInstance.Int64(a.As <Int64>() << b.As <Int32>()));
                }
                if (a.Is <UInt32>())
                {
                    return(HybInstance.UInt(a.As <UInt32>() << b.As <Int32>()));
                }
                if (a.Is <UInt64>())
                {
                    return(HybInstance.UInt64(a.As <UInt64>() << b.As <Int32>()));
                }
            }

            throw new NotImplementedException();
        }
Example #4
0
        public static HybInstance Add(HybInstance a, HybInstance b)
        {
            if (a.IsNull())
            {
                throw new NullReferenceException(a.Id);
            }

            if (a.GetHybType().IsPrimitive)
            {
                (a, b) = Promote(a, b);

                if (a.Is <Int32>())
                {
                    return(HybInstance.Int(a.As <Int32>() + b.As <Int32>()));
                }
                if (a.Is <Int64>())
                {
                    return(HybInstance.Int64(a.As <Int64>() + b.As <Int64>()));
                }
                if (a.Is <Single>())
                {
                    return(HybInstance.Float(a.As <Single>() + b.As <Single>()));
                }
                if (a.Is <Double>())
                {
                    return(HybInstance.Double(a.As <Double>() + b.As <Double>()));
                }
            }
            else if (a.Is <String>())
            {
                return(HybInstance.String(a.As <String>() + b.ToString()));
            }

            var addMethod = GetAddMethod(a);

            if (addMethod != null)
            {
                return(addMethod.Target.Invoke(null, new HybInstance[] { a, b }));
            }

            throw new NotImplementedException();
        }
Example #5
0
        public static HybInstance LE(HybInstance a, HybInstance b)
        {
            if (a.IsNull())
            {
                throw new NullReferenceException(a.Id);
            }

            if (a.GetHybType().IsPrimitive)
            {
                (a, b) = Promote(a, b);

                if (a.Is <Int32>())
                {
                    return(HybInstance.Bool(a.As <Int32>() <= b.As <Int32>()));
                }
                if (a.Is <Int64>())
                {
                    return(HybInstance.Bool(a.As <Int64>() <= b.As <Int64>()));
                }
                if (a.Is <Single>())
                {
                    return(HybInstance.Bool(a.As <Single>() <= b.As <Single>()));
                }
                if (a.Is <Double>())
                {
                    return(HybInstance.Bool(a.As <Double>() <= b.As <Double>()));
                }
            }

            var lessEqualMethod = GetLessEqualMethod(a);

            if (lessEqualMethod != null)
            {
                return(lessEqualMethod.Target.Invoke(null, new HybInstance[] { a, b }));
            }

            throw new NotImplementedException();
        }
Example #6
0
        public static HybInstance And(HybInstance a, HybInstance b)
        {
            if (a.IsCompiledType && b.IsCompiledType)
            {
                if (a.Is <bool>() && b.Is <bool>())
                {
                    return(a.As <bool>() && b.As <bool>() ?
                           HybInstanceCache.True :
                           HybInstanceCache.False);
                }
            }

            throw new NotImplementedException();
        }
Example #7
0
        public static HybInstance Xor(HybInstance a, HybInstance b)
        {
            if (a.IsCompiledType && b.IsCompiledType)
            {
                if (a.Is <bool>() && b.Is <bool>())
                {
                    return(HybInstance.Bool(a.As <bool>() ^ b.As <bool>()));
                }

                if (a.GetHybType().IsPrimitive)
                {
                    if (a.Is <Int32>())
                    {
                        return(HybInstance.Int(a.As <Int32>() ^ b.As <Int32>()));
                    }
                    if (a.Is <Int64>())
                    {
                        return(HybInstance.Int64(a.As <Int64>() ^ b.As <Int32>()));
                    }
                }
            }

            throw new NotImplementedException();
        }
Example #8
0
        public static HybInstance PrefixMinus(HybInstance a)
        {
            if (a.IsCompiledType)
            {
                if (a.GetHybType().IsValueType)
                {
                    if (a.Is <Decimal>())
                    {
                        return(HybInstance.Decimal(-a.As <Decimal>()));
                    }
                    if (a.Is <Double>())
                    {
                        return(HybInstance.Double(-a.As <Double>()));
                    }
                    if (a.Is <Single>())
                    {
                        return(HybInstance.Float(-a.As <Single>()));
                    }
                    if (a.Is <Int64>())
                    {
                        return(HybInstance.Int64(-a.As <Int64>()));
                    }
                    if (a.Is <Int32>())
                    {
                        return(HybInstance.Int(-a.As <Int32>()));
                    }
                    if (a.Is <short>())
                    {
                        return(HybInstance.Short(-a.As <short>()));
                    }
                    if (a.Is <sbyte>())
                    {
                        return(HybInstance.Byte(-a.As <sbyte>()));
                    }
                }
            }

            var negationMethod = GetUnaryNegationMethod(a);

            if (negationMethod != null)
            {
                return(negationMethod.Target.Invoke(null, new HybInstance[] { a }));
            }

            throw new NotImplementedException();
        }
Example #9
0
        public static HybInstance BitwiseOr(HybInstance a, HybInstance b)
        {
            if (a.IsCompiledType && b.IsCompiledType)
            {
                if (a.Is <bool>() && b.Is <bool>())
                {
                    return(a.As <bool>() | b.As <bool>() ?
                           HybInstanceCache.True :
                           HybInstanceCache.False);
                }
            }

            var bitwiseOrMethod = GetBitwiseOrMethod(a);

            if (bitwiseOrMethod != null)
            {
                return(bitwiseOrMethod.Target.Invoke(null, new HybInstance[] { a, b }));
            }

            throw new NotImplementedException();
        }
Example #10
0
        public static HybInstance PrefixNot(HybInstance a)
        {
            if (a.IsCompiledType)
            {
                if (a.Is <bool>())
                {
                    return(a.As <bool>() ?
                           HybInstanceCache.False :
                           HybInstanceCache.True);
                }
            }

            var plusMethod = GetUnaryPlusMethod(a);

            if (plusMethod != null)
            {
                return(plusMethod.Target.Invoke(null, new HybInstance[] { a }));
            }

            throw new NotImplementedException();
        }
Example #11
0
        public bool SetIndexer(HybInstance[] args, HybInstance value)
        {
            if (IsCompiledType)
            {
                if (Obj is Array ary)
                {
                    ary.SetValue(
                        value.Unwrap(),
                        args.Unwrap()
                        .Select(x => (int)x)
                        .ToArray());
                    return(true);
                }

                var idxer = GetIndexerProperty();
                if (idxer == null)
                {
                    return(false);
                }

                idxer.SetValue(Obj, value.As(idxer.PropertyType), args.Unwrap());
                return(true);
            }
            else
            {
                var p = Type.GetProperty("[]");
                if (p != null)
                {
                    value = p.SetMethod.Invoke(this, args.Concat(new HybInstance[] { value }).ToArray());
                    return(true);
                }

                if (Parent != null)
                {
                    return(Parent.SetIndexer(args, value));
                }
            }

            return(false);
        }