コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
ファイル: LuryString.cs プロジェクト: nokok/lury
        public override LuryObject Con(LuryObject other)
        {
            if (other == null)
                throw new LuryException(LuryExceptionType.NilReference);

            return new LuryString(this.value + other.ToString());
        }
コード例 #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)));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #7
0
        public override LuryObject Con(LuryObject other)
        {
            if (other == null)
            {
                throw new LuryException(LuryExceptionType.NilReference);
            }

            return(new LuryString(this.value + other.ToString()));
        }
コード例 #8
0
ファイル: LuryString.cs プロジェクト: nokok/lury
        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;
        }
コード例 #9
0
ファイル: LuryInteger.cs プロジェクト: nokok/lury
        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);
        }
コード例 #10
0
ファイル: LuryReal.cs プロジェクト: nokok/lury
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #13
0
ファイル: LuryReal.cs プロジェクト: nokok/lury
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #17
0
ファイル: LuryObject.cs プロジェクト: nokok/lury
 public virtual LuryObject BXor(LuryObject other)
 {
     throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
 }
コード例 #18
0
ファイル: LuryContext.cs プロジェクト: nokok/lury
 public void SetMemberNoRecursion(string name, LuryObject value)
 {
     this.members.Add(name, value);
 }
コード例 #19
0
 public void SetMemberNoRecursion(string name, LuryObject value)
 {
     this.members.Add(name, value);
 }
コード例 #20
0
 public virtual LuryObject Pow(LuryObject other)
 {
     throw new NotSupportedException();
 }
コード例 #21
0
ファイル: IR.cs プロジェクト: nokok/lury
 public StatementExit(LuryObject returnValue, StatementExitReason reason)
 {
     this.ReturnValue = returnValue;
     this.ExitReason = reason;
 }
コード例 #22
0
ファイル: IR.cs プロジェクト: nokok/lury
 public override void Assign(LuryObject value, LuryContext context)
 {
     context[this.reference] = value;
 }
コード例 #23
0
ファイル: LuryReal.cs プロジェクト: nokok/lury
        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);
        }
コード例 #24
0
ファイル: Intrinsic.cs プロジェクト: nokok/lury
 public static void SetBuiltInFunctions(LuryObject obj)
 {
     obj["println"] = new LuryFunction(PrintLine);
     obj["print"] = new LuryFunction(Print);
 }
コード例 #25
0
ファイル: LuryComplex.cs プロジェクト: nokok/lury
        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);
        }
コード例 #26
0
ファイル: IR.cs プロジェクト: 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);
        }
コード例 #27
0
ファイル: LuryObject.cs プロジェクト: nokok/lury
 public virtual LuryObject Pow(LuryObject other)
 {
     throw new NotSupportedException();
 }
コード例 #28
0
ファイル: LuryObject.cs プロジェクト: nokok/lury
 public LuryBoolean IsNot(LuryObject other)
 {
     return this.Is(other).LNot();
 }
コード例 #29
0
ファイル: LuryObject.cs プロジェクト: nokok/lury
 public LuryBoolean Is(LuryObject other)
 {
     throw new NotImplementedException();
 }
コード例 #30
0
ファイル: LuryObject.cs プロジェクト: nokok/lury
 public virtual LuryBoolean CNe(LuryObject other)
 {
     return this.CEq(other).LNot();
 }
コード例 #31
0
ファイル: LuryObject.cs プロジェクト: nokok/lury
 public virtual LuryBoolean CELt(LuryObject other)
 {
     return this.CLt(other).LOr(this.CEq(other));
 }
コード例 #32
0
ファイル: IR.cs プロジェクト: nokok/lury
 public abstract void Assign(LuryObject value, LuryContext context);
コード例 #33
0
ファイル: IR.cs プロジェクト: nokok/lury
 public ConstantNode(LuryObject constant)
 {
     this.constant = constant;
 }
コード例 #34
0
ファイル: LuryComplex.cs プロジェクト: nokok/lury
        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);
        }
コード例 #35
0
 public virtual LuryBoolean CEGt(LuryObject other)
 {
     return(this.CGt(other).LOr(this.CEq(other)));
 }
コード例 #36
0
ファイル: LuryComplex.cs プロジェクト: nokok/lury
        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));
        }
コード例 #37
0
 public virtual LuryBoolean CEq(LuryObject other)
 {
     throw new LuryException(LuryExceptionType.NotSupportedOperationBinary);
 }
コード例 #38
0
ファイル: LuryReal.cs プロジェクト: nokok/lury
        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);
        }
コード例 #39
0
 public virtual LuryBoolean CNe(LuryObject other)
 {
     return(this.CEq(other).LNot());
 }
コード例 #40
0
ファイル: LuryReal.cs プロジェクト: nokok/lury
        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);
        }
コード例 #41
0
 public LuryBoolean Is(LuryObject other)
 {
     throw new NotImplementedException();
 }
コード例 #42
0
ファイル: IR.cs プロジェクト: nokok/lury
 public override void Assign(LuryObject value, LuryContext context)
 {
     this.lvalue.Assign(value, context);
 }
コード例 #43
0
 public LuryBoolean IsNot(LuryObject other)
 {
     return(this.Is(other).LNot());
 }