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(); }
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); }
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(); } }
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); }
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)); }
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); }
public static LuryObject Or(LuryObject self, LuryObject other) { if (other.LuryTypeName != FullName) { throw new ArgumentException(); } return(GetObject((BigInteger)self.Value | (BigInteger)other.Value)); }
public static LuryObject Con(LuryObject self, LuryObject other) { if (other.LuryTypeName != TypeName) { throw new ArgumentException(); } return(GetObject(((LList)self.Value).Concat((LList)other.Value))); }
public static LuryObject Xor(LuryObject self, LuryObject other) { if (other.LuryTypeName != TypeName) { throw new ArgumentException(); } return((bool)self.Value ^ (bool)other.Value ? True : False); }
public static LuryObject NotEqual(LuryObject self, LuryObject other) { if (other.LuryTypeName != FullName) { throw new ArgumentException(); } return(self.Value != other.Value ? True : False); }
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); }
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]); }
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))); }
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); }
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(); }
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(); }
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(); }
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(); }
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(); } }
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(); } }
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); } }
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(); } }
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(); } }
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); }
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(); } }
public static LuryReference Create(LuryObject subject, LuryObject key) => new LuryReference(new Reference(subject, key));
public static LuryReference Create(LuryObject subject, string @object) => new LuryReference(new Reference(subject, @object));
private Reference(LuryObject subject, string @object, LuryObject key) { Subject = subject; Object = @object; Key = key; }
public Reference(LuryObject subject, LuryObject key) : this(subject, null, key) { }
public Reference(LuryObject subject, string @object) : this(subject, @object, null) { }