Esempio n. 1
0
        public override LuryObject Div(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryReal(this.value / ((LuryInteger)other).Value));
            }

            if (other is LuryReal)
            {
                return(new LuryReal(this.value  / ((LuryReal)other).value));
            }

            if (other is LuryComplex)
            {
                var o    = (LuryComplex)other;
                var icd2 = 1.0 / (o.Real * o.Real + o.Imag * o.Imag);
                return(new LuryComplex((this.value * o.Real) * icd2, (-this.value * o.Imag) * icd2));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 2
0
        public override LuryObject IDiv(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryReal(this.value / ((LuryInteger)other).Value));
            }

            if (other is LuryReal)
            {
                var o = ((LuryReal)other).Value;

                if (o == 0.0)
                {
                    throw new LuryException(LuryExceptionType.DivideByZero);
                }

                return(new LuryReal((double)((long)((double)this.value  / o))));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 3
0
        public override LuryObject Con(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            return new LuryString(this.value + other.ToString());
        }
Esempio n. 4
0
        public override LuryObject Pow(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            double or = 0.0, oi = 0.0;

            if (other is LuryInteger)
            {
                or = ((LuryInteger)other).Value;
            }
            else if (other is LuryReal)
            {
                or = ((LuryReal)other).Value;
            }
            else if (other is LuryComplex)
            {
                or = ((LuryComplex)other).real;
                oi = ((LuryComplex)other).imag;
            }
            else
            {
                throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
            }

            var log_zr = Math.Log(Math.Sqrt(this.real * this.real + this.imag * this.imag));
            var log_zi = Math.Atan2(this.imag, this.real);

            var a_log_zr = or * log_zr - log_zi * oi;
            var a_log_zi = oi * log_zr + or * log_zi;

            return(new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi)));
        }
Esempio n. 5
0
        public override LuryObject Mul(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryComplex(this.real  * ((LuryInteger)other).Value, this.imag * ((LuryInteger)other).Value));
            }

            if (other is LuryReal)
            {
                return(new LuryComplex(this.real  * ((LuryReal)other).Value, this.imag * ((LuryReal)other).Value));
            }

            if (other is LuryComplex)
            {
                var o = (LuryComplex)other;
                return(new LuryComplex(this.real * o.Real - this.imag * o.imag, this.imag * o.real + this.real * o.imag));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 6
0
        public override LuryObject Pow(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryReal(Math.Pow(this.value, ((LuryInteger)other).Value)));
            }

            if (other is LuryReal)
            {
                return(new LuryReal(Math.Pow(this.value, ((LuryReal)other).value)));
            }

            if (other is LuryComplex)
            {
                var or = ((LuryComplex)other).Real;
                var oi = ((LuryComplex)other).Imag;

                var log_zr = Math.Log(this.value);
                var log_zi = Math.Atan2(0.0, this.value);

                var a_log_zr = or * log_zr - log_zi * oi;
                var a_log_zi = oi * log_zr + or * log_zi;

                return(new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi)));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 7
0
        public override LuryObject Con(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            return(new LuryString(this.value + other.ToString()));
        }
Esempio n. 8
0
        public override LuryBoolean CEq(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (!(other is LuryString))
                throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);

            return this.value == ((LuryString)other).value ? LuryBoolean.True : LuryBoolean.False;
        }
Esempio n. 9
0
        public override LuryObject BAnd(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryInteger(this.value & ((LuryInteger)other).value);

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 10
0
        public override LuryBoolean CEq(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return this.value == (double)((LuryInteger)other).Value ? LuryBoolean.True : LuryBoolean.False;

            if (other is LuryReal)
                return this.value == ((LuryReal)other).Value ? LuryBoolean.True : LuryBoolean.False;

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 11
0
        public override LuryBoolean CEq(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (!(other is LuryBoolean))
            {
                throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
            }

            return(this.value == ((LuryBoolean)other).value ? True : False);
        }
Esempio n. 12
0
        public override LuryObject BOr(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryInteger(this.value | ((LuryInteger)other).value));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 13
0
        public override LuryObject Add(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryReal(this.value + ((LuryInteger)other).Value);

            if (other is LuryReal)
                return new LuryReal(this.value + ((LuryReal)other).value);

            if (other is LuryComplex)
                return new LuryComplex(this.value + ((LuryComplex)other).Real, ((LuryComplex)other).Imag);

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 14
0
        public override LuryObject IDiv(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryComplex((double)(long)(this.real  / ((LuryInteger)other).Value), (double)(long)(this.imag / ((LuryInteger)other).Value)));
            }

            if (other is LuryReal)
            {
                return(new LuryComplex((double)(long)(this.real  / ((LuryReal)other).Value), (double)(long)(this.imag / ((LuryReal)other).Value)));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 15
0
        public override LuryBoolean CEq(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(this.value == (double)((LuryInteger)other).Value ? LuryBoolean.True : LuryBoolean.False);
            }

            if (other is LuryReal)
            {
                return(this.value == ((LuryReal)other).Value ? LuryBoolean.True : LuryBoolean.False);
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 16
0
        public override LuryObject Sub(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            if (other is LuryInteger)
            {
                return(new LuryComplex(this.real  - ((LuryInteger)other).Value, this.imag));
            }

            if (other is LuryReal)
            {
                return(new LuryComplex(this.real  - ((LuryReal)other).Value, this.imag));
            }

            if (other is LuryComplex)
            {
                return(new LuryComplex(this.real  - ((LuryComplex)other).Real, this.imag  - ((LuryComplex)other).Imag));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 17
0
 public virtual LuryObject BXor(LuryObject other)
 {
     throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
 }
Esempio n. 18
0
 public void SetMemberNoRecursion(string name, LuryObject value)
 {
     this.members.Add(name, value);
 }
Esempio n. 19
0
 public void SetMemberNoRecursion(string name, LuryObject value)
 {
     this.members.Add(name, value);
 }
Esempio n. 20
0
 public virtual LuryObject Pow(LuryObject other)
 {
     throw new NotSupportedException();
 }
Esempio n. 21
0
File: IR.cs Progetto: nokok/lury
 public StatementExit(LuryObject returnValue, StatementExitReason reason)
 {
     this.ReturnValue = returnValue;
     this.ExitReason = reason;
 }
Esempio n. 22
0
File: IR.cs Progetto: nokok/lury
 public override void Assign(LuryObject value, LuryContext context)
 {
     context[this.reference] = value;
 }
Esempio n. 23
0
        public override LuryObject IDiv(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryReal(this.value / ((LuryInteger)other).Value);

            if (other is LuryReal)
            {
                var o = ((LuryReal)other).Value;

                if (o == 0.0)
                    throw new LuryException(LuryExceptionType.DivideByZero);

                return new LuryReal((double)((long)((double)this.value / o)));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 24
0
 public static void SetBuiltInFunctions(LuryObject obj)
 {
     obj["println"] = new LuryFunction(PrintLine);
     obj["print"] = new LuryFunction(Print);
 }
Esempio n. 25
0
        public override LuryObject Mul(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryComplex(this.real * ((LuryInteger)other).Value, this.imag * ((LuryInteger)other).Value);

            if (other is LuryReal)
                return new LuryComplex(this.real * ((LuryReal)other).Value, this.imag * ((LuryReal)other).Value);

            if (other is LuryComplex)
            {
                var o = (LuryComplex)other;
                return new LuryComplex(this.real * o.Real - this.imag * o.imag, this.imag * o.real + this.real * o.imag);
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 26
0
File: IR.cs Progetto: nokok/lury
        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);
        }
Esempio n. 27
0
 public virtual LuryObject Pow(LuryObject other)
 {
     throw new NotSupportedException();
 }
Esempio n. 28
0
 public LuryBoolean IsNot(LuryObject other)
 {
     return this.Is(other).LNot();
 }
Esempio n. 29
0
 public LuryBoolean Is(LuryObject other)
 {
     throw new NotImplementedException();
 }
Esempio n. 30
0
 public virtual LuryBoolean CNe(LuryObject other)
 {
     return this.CEq(other).LNot();
 }
Esempio n. 31
0
 public virtual LuryBoolean CELt(LuryObject other)
 {
     return this.CLt(other).LOr(this.CEq(other));
 }
Esempio n. 32
0
File: IR.cs Progetto: nokok/lury
 public abstract void Assign(LuryObject value, LuryContext context);
Esempio n. 33
0
File: IR.cs Progetto: nokok/lury
 public ConstantNode(LuryObject constant)
 {
     this.constant = constant;
 }
Esempio n. 34
0
        public override LuryObject IDiv(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryComplex((double)(long)(this.real / ((LuryInteger)other).Value), (double)(long)(this.imag / ((LuryInteger)other).Value));

            if (other is LuryReal)
                return new LuryComplex((double)(long)(this.real / ((LuryReal)other).Value), (double)(long)(this.imag / ((LuryReal)other).Value));

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 35
0
 public virtual LuryBoolean CEGt(LuryObject other)
 {
     return(this.CGt(other).LOr(this.CEq(other)));
 }
Esempio n. 36
0
        public override LuryObject Pow(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            double or = 0.0, oi = 0.0;

            if (other is LuryInteger)
                or = ((LuryInteger)other).Value;
            else if (other is LuryReal)
                or = ((LuryReal)other).Value;
            else if (other is LuryComplex)
            {
                or = ((LuryComplex)other).real;
                oi = ((LuryComplex)other).imag;
            }
            else
                throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);

            var log_zr = Math.Log(Math.Sqrt(this.real * this.real + this.imag * this.imag));
            var log_zi = Math.Atan2(this.imag, this.real);

            var a_log_zr = or * log_zr - log_zi * oi;
            var a_log_zi = oi * log_zr + or * log_zi;

            return new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi));
        }
Esempio n. 37
0
 public virtual LuryBoolean CEq(LuryObject other)
 {
     throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
 }
Esempio n. 38
0
        public override LuryObject Div(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryReal(this.value / ((LuryInteger)other).Value);

            if (other is LuryReal)
                return new LuryReal(this.value / ((LuryReal)other).value);

            if (other is LuryComplex)
            {
                var o = (LuryComplex)other;
                var icd2 = 1.0 / (o.Real * o.Real + o.Imag * o.Imag);
                return new LuryComplex((this.value * o.Real) * icd2, (-this.value * o.Imag) * icd2);
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 39
0
 public virtual LuryBoolean CNe(LuryObject other)
 {
     return(this.CEq(other).LNot());
 }
Esempio n. 40
0
        public override LuryObject Pow(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            if (other is LuryInteger)
                return new LuryReal(Math.Pow(this.value, ((LuryInteger)other).Value));

            if (other is LuryReal)
                return new LuryReal(Math.Pow(this.value, ((LuryReal)other).value));

            if (other is LuryComplex)
            {
                var or = ((LuryComplex)other).Real;
                var oi = ((LuryComplex)other).Imag;

                var log_zr = Math.Log(this.value);
                var log_zi = Math.Atan2(0.0, this.value);

                var a_log_zr = or * log_zr - log_zi * oi;
                var a_log_zi = oi * log_zr + or * log_zi;

                return new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi));
            }

            throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
        }
Esempio n. 41
0
 public LuryBoolean Is(LuryObject other)
 {
     throw new NotImplementedException();
 }
Esempio n. 42
0
File: IR.cs Progetto: nokok/lury
 public override void Assign(LuryObject value, LuryContext context)
 {
     this.lvalue.Assign(value, context);
 }
Esempio n. 43
0
 public LuryBoolean IsNot(LuryObject other)
 {
     return(this.Is(other).LNot());
 }