Example #1
0
        public static LuryObject Call(LuryObject self, params object[] others)
        {
            var methodInfo = self.Value as MethodInfo;

            if (methodInfo != null)
            {
                return((LuryObject)methodInfo.Invoke(null, BindingFlags.Default, null, others, null));
            }

            var functionInfo = self.Value as UserFunctionInfo;

            if (functionInfo != null)
            {
                var param = functionInfo.ParameterNames.ToArray();

                if (param.Length != others.Length)
                {
                    throw new InvalidOperationException();
                }

                var context = new LuryContext(functionInfo.ParentContext);

                for (var i = 0; i < param.Length; i++)
                {
                    context[param[i]] = (LuryObject)others[i];
                }

                return(new LuryVisitor(context).VisitSuite(functionInfo.BodySuite));
            }

            throw new NotImplementedException();
        }
Example #2
0
        public LuryObject Assign(LuryContext context, LuryObject @object)
        {
            var reference = (Reference)Value;

            if (reference.Subject == null)
            {
                if (reference.Key == null)
                {
                    context[reference.Object] = @object;
                }
                else
                {
                    var obj = context[reference.Object];
                    LuryList.SetIndex(obj, reference.Key, @object);
                }
            }
            else
            {
                if (reference.Key == null)
                {
                    reference.Subject.SetMember(reference.Object, @object);
                }
                else
                {
                    LuryList.SetIndex(reference.Subject, reference.Key, @object);
                }
            }

            return(@object);
        }
Example #3
0
        public static LuryObject Pow(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName == FullName)
            {
                var exponent = (BigInteger)other.Value;

                if (exponent > int.MaxValue || exponent < int.MinValue)
                {
                    return(IntrinsicReal.GetObject(Math.Pow((double)(BigInteger)self.Value, (double)exponent)));
                }
                else
                {
                    return(GetObject(BigInteger.Pow((BigInteger)self.Value, (int)exponent)));
                }
            }
            else if (other.LuryTypeName == IntrinsicReal.FullName)
            {
                return(IntrinsicReal.GetObject(Math.Pow((double)(BigInteger)self.Value, (double)other.Value)));
            }
            else if (other.LuryTypeName == IntrinsicComplex.FullName)
            {
                return(IntrinsicComplex.GetObject(Complex.Pow((double)(BigInteger)self.Value, (Complex)other.Value)));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Example #4
0
        public static LuryObject NotEqual(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != TypeName)
            {
                throw new ArgumentException();
            }

            return(!((LList)self.Value).SequenceEqual((LList)other.Value) ? True : False);
        }
Example #5
0
        public static LuryObject Con(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != FullName)
            {
                throw new ArgumentException();
            }

            return(new LuryObject(TypeName, (string)self.Value + (string)other.Value, freeze: true));
        }
Example #6
0
        public static LuryObject In(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != FullName)
            {
                throw new ArgumentException();
            }

            return(((string)self.Value).Contains((string)other.Value) ? True : False);
        }
Example #7
0
        public static LuryObject Or(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != FullName)
            {
                throw new ArgumentException();
            }

            return(GetObject((BigInteger)self.Value | (BigInteger)other.Value));
        }
Example #8
0
        public static LuryObject Con(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != TypeName)
            {
                throw new ArgumentException();
            }

            return(GetObject(((LList)self.Value).Concat((LList)other.Value)));
        }
Example #9
0
        public static LuryObject Xor(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != TypeName)
            {
                throw new ArgumentException();
            }

            return((bool)self.Value ^ (bool)other.Value ? True : False);
        }
Example #10
0
        public static LuryObject NotEqual(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != FullName)
            {
                throw new ArgumentException();
            }

            return(self.Value != other.Value ? True : False);
        }
Example #11
0
        public static LuryObject Ltq(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != FullName)
            {
                throw new ArgumentException();
            }

            return(((string)self.Value).CompareTo(other.Value) <= 0 ? True : False);
        }
Example #12
0
            public static LuryObject fetch(LuryObject self)
            {
                var iterator = (LuryListIterator)self;
                var llist    = (LList)((LuryList)self.Value).Value;

                if (iterator.index < 0 || llist.Count < iterator.index + 1)
                {
                    throw new InvalidOperationException();
                }

                return(llist[iterator.index]);
            }
Example #13
0
        public static LuryObject Xor(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName != TypeName)
            {
                throw new ArgumentException();
            }

            var or  = ((LList)self.Value).Union((LList)other.Value);
            var and = ((LList)self.Value).Intersect((LList)other.Value);

            return(GetObject(or.Except(and)));
        }
Example #14
0
            public static LuryObject moveNext(LuryObject self)
            {
                var iterator = (LuryListIterator)self;
                var llist    = (LList)((LuryList)self.Value).Value;

                if (llist.Count <= iterator.index + 1)
                {
                    return(False);
                }

                iterator.index++;
                return(True);
            }
Example #15
0
        public static LuryObject Pow(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName == LuryInteger.FullName)
            {
                return(GetObject(Math.Pow((double)self.Value, (double)(BigInteger)other.Value)));
            }

            if (other.LuryTypeName == FullName)
            {
                return(GetObject(Math.Pow((double)self.Value, (double)other.Value)));
            }

            throw new ArgumentException();
        }
Example #16
0
        public static LuryObject Gtq(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName == FullName)
            {
                return((BigInteger)self.Value >= (BigInteger)other.Value ? True : False);
            }

            if (other.LuryTypeName == LuryReal.FullName)
            {
                return((double)(BigInteger)self.Value >= (double)(BigInteger)other.Value ? True : False);
            }

            throw new ArgumentException();
        }
Example #17
0
        public static LuryObject Sub(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName == FullName)
            {
                return(GetObject((BigInteger)self.Value - (BigInteger)other.Value));
            }

            if (other.LuryTypeName == LuryReal.FullName)
            {
                return(LuryReal.GetObject((double)(BigInteger)self.Value - (double)other.Value));
            }

            throw new ArgumentException();
        }
Example #18
0
        public static LuryObject IntDiv(LuryObject self, LuryObject other)
        {
            if (other.LuryTypeName == LuryInteger.FullName)
            {
                return(LuryInteger.GetObject(new BigInteger((double)self.Value) / (BigInteger)other.Value));
            }

            if (other.LuryTypeName == FullName)
            {
                return(LuryInteger.GetObject(new BigInteger((double)self.Value) / new BigInteger((double)other.Value)));
            }

            throw new ArgumentException();
        }
Example #19
0
 public static LuryObject Mod(LuryObject self, LuryObject other)
 {
     if (other.LuryTypeName == IntrinsicInteger.FullName)
     {
         return(GetObject((double)self.Value % (double)(BigInteger)other.Value));
     }
     else if (other.LuryTypeName == FullName)
     {
         return(GetObject((double)self.Value % (double)other.Value));
     }
     else
     {
         throw new ArgumentException();
     }
 }
Example #20
0
 public static LuryObject Gtq(LuryObject self, LuryObject other)
 {
     if (other.LuryTypeName == IntrinsicInteger.FullName)
     {
         return((double)self.Value >= (double)(BigInteger)other.Value ? True : False);
     }
     else if (other.LuryTypeName == FullName)
     {
         return((double)self.Value >= (double)other.Value ? True : False);
     }
     else
     {
         throw new ArgumentException();
     }
 }
Example #21
0
        public override void Assign(LuryObject value, LuryContext context)
        {
            var parentObj = this.parent.Evaluate(context);

            if (parentObj == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (parentObj.Has(this.child))
            {
                parentObj[this.child] = value;
            }
            else
            {
                throw new LuryException(LuryExceptionType.AttributeIsNotFound);
            }
        }
Example #22
0
 public static LuryObject NotEqual(LuryObject self, LuryObject other)
 {
     if (other.LuryTypeName == IntrinsicInteger.FullName)
     {
         return((Complex)self.Value != (Complex)(double)(BigInteger)other.Value ? True : False);
     }
     else if (other.LuryTypeName == IntrinsicReal.FullName)
     {
         return((Complex)self.Value != (Complex)(double)other.Value ? True : False);
     }
     else if (other.LuryTypeName == FullName)
     {
         return((Complex)self.Value != (Complex)other.Value ? True : False);
     }
     else
     {
         throw new ArgumentException();
     }
 }
Example #23
0
 public static LuryObject Sub(LuryObject self, LuryObject other)
 {
     if (other.LuryTypeName == FullName)
     {
         return(GetObject((BigInteger)self.Value - (BigInteger)other.Value));
     }
     else if (other.LuryTypeName == IntrinsicReal.FullName)
     {
         return(IntrinsicReal.GetObject((double)(BigInteger)self.Value - (double)other.Value));
     }
     else if (other.LuryTypeName == IntrinsicComplex.FullName)
     {
         return(IntrinsicComplex.GetObject((double)(BigInteger)self.Value - (Complex)other.Value));
     }
     else
     {
         throw new ArgumentException();
     }
 }
Example #24
0
        public static LuryObject SetIndex(LuryObject self, LuryObject other, LuryObject element)
        {
            var indexObject = other as LuryInteger;

            if (indexObject == null)
            {
                throw new InvalidOperationException();
            }

            var index = (BigInteger)indexObject.Value;
            var llist = (LList)self.Value;

            if (index < 0 || index > int.MaxValue)
            {
                throw new InvalidOperationException();
            }

            return(llist[(int)index] = element);
        }
Example #25
0
 public static LuryObject Pow(LuryObject self, LuryObject other)
 {
     if (other.LuryTypeName == IntrinsicInteger.FullName)
     {
         return(GetObject(Complex.Pow((Complex)self.Value, (Complex)(double)(BigInteger)other.Value)));
     }
     else if (other.LuryTypeName == IntrinsicReal.FullName)
     {
         return(GetObject(Complex.Pow((Complex)self.Value, (Complex)(double)other.Value)));
     }
     else if (other.LuryTypeName == FullName)
     {
         return(GetObject(Complex.Pow((Complex)self.Value, (Complex)other.Value)));
     }
     else
     {
         throw new ArgumentException();
     }
 }
Example #26
0
 public static LuryReference Create(LuryObject subject, LuryObject key)
 => new LuryReference(new Reference(subject, key));
Example #27
0
 public static LuryReference Create(LuryObject subject, string @object)
 => new LuryReference(new Reference(subject, @object));
Example #28
0
 private Reference(LuryObject subject, string @object, LuryObject key)
 {
     Subject = subject;
     Object  = @object;
     Key     = key;
 }
Example #29
0
 public Reference(LuryObject subject, LuryObject key)
     : this(subject, null, key)
 {
 }
Example #30
0
 public Reference(LuryObject subject, string @object)
     : this(subject, @object, null)
 {
 }