Esempio n. 1
0
        internal static PythonDictionary GetInvertedRegistry(CodeContext /*!*/ context)
        {
            EnsureModuleInitialized(context);

            return((PythonDictionary)PythonContext.GetContext(context).GetModuleState(_invertedRegistryKey));
        }
Esempio n. 2
0
 private static int GetStackSize(CodeContext /*!*/ context)
 {
     return((int)PythonContext.GetContext(context).GetModuleState(_stackSizeKey));
 }
Esempio n. 3
0
 private static long GetLockCount(CodeContext /*!*/ context)
 {
     return((long)PythonContext.GetContext(context).GetModuleState(_lockCountKey));
 }
Esempio n. 4
0
        public static object iconcat(CodeContext /*!*/ context, object a, object b)
        {
            TestBothSequence(a, b);

            return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceAdd, a, b));
        }
Esempio n. 5
0
 public static object Call(CodeContext /*!*/ context, Delegate @delegate, [ParamDictionary] IDictionary <object, object> dict, params object[] args)
 {
     return(PythonContext.GetContext(context).CallWithKeywords(@delegate, args, dict));
 }
Esempio n. 6
0
 public static object irshift(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceRightShift, a, b));
 }
Esempio n. 7
0
 public static object itruediv(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceTrueDivide, a, b));
 }
Esempio n. 8
0
 public static object ne(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.NotEqual, a, b));
 }
Esempio n. 9
0
 public static object gt(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.GreaterThan, a, b));
 }
Esempio n. 10
0
 public static void setrecursionlimit(CodeContext /*!*/ context, int limit)
 {
     PythonContext.GetContext(context).RecursionLimit = limit;
 }
Esempio n. 11
0
 public static int getrecursionlimit(CodeContext /*!*/ context)
 {
     return(PythonContext.GetContext(context).RecursionLimit);
 }
Esempio n. 12
0
 public static string getdefaultencoding(CodeContext /*!*/ context)
 {
     return(PythonContext.GetContext(context).GetDefaultEncodingName());
 }
Esempio n. 13
0
        /// <summary>
        /// Returns the digits for the format spec, no sign is included.
        /// </summary>
        private static string DoubleToFormatString(CodeContext /*!*/ context, double self, StringFormatSpec /*!*/ spec)
        {
            self = Math.Abs(self);
            const int DefaultPrecision = 6;
            int       precision        = spec.Precision ?? DefaultPrecision;

            string digits;

            switch (spec.Type)
            {
            case '%': {
                string fmt = "0." + new string('0', precision) + "%";
                if (spec.ThousandsComma)
                {
                    fmt = "#," + fmt;
                }
                digits = self.ToString(fmt, CultureInfo.InvariantCulture);
                break;
            }

            case 'f':
            case 'F': {
                string fmt = "0." + new string('0', precision);
                if (spec.ThousandsComma)
                {
                    fmt = "#," + fmt;
                }
                digits = self.ToString(fmt, CultureInfo.InvariantCulture);
                break;
            }

            case 'e':
            case 'E': {
                string fmt = "0." + new string('0', precision) + spec.Type + "+00";
                if (spec.ThousandsComma)
                {
                    fmt = "#," + fmt;
                }
                digits = self.ToString(fmt, CultureInfo.InvariantCulture);
                break;
            }

            case '\0':
            case null:
                if (spec.Precision != null)
                {
                    // precision applies to the combined digits before and after the decimal point
                    // so we first need find out how many digits we have before...
                    int    digitCnt = 1;
                    double cur      = self;
                    while (cur >= 10)
                    {
                        cur /= 10;
                        digitCnt++;
                    }

                    // Use exponents if we don't have enough room for all the digits before.  If we
                    // only have as single digit avoid exponents.
                    if (digitCnt > spec.Precision.Value && digitCnt != 1)
                    {
                        // first round off the decimal value
                        self = MathUtils.RoundAwayFromZero(self, 0);

                        // then remove any insignificant digits
                        double pow = Math.Pow(10, digitCnt - Math.Max(spec.Precision.Value, 1));
                        self = self - (self % pow);

                        // finally format w/ the requested precision
                        string fmt = "0.0" + new string('#', spec.Precision.Value);

                        digits = self.ToString(fmt + "e+00", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        // we're including all the numbers to the right of the decimal we can, we explicitly
                        // round to match CPython's behavior
                        int decimalPoints = Math.Max(spec.Precision.Value - digitCnt, 0);

                        self   = MathUtils.RoundAwayFromZero(self, decimalPoints);
                        digits = self.ToString("0.0" + new string('#', decimalPoints));
                    }
                }
                else
                {
                    // just the default formatting
                    if (IncludeExponent(self))
                    {
                        digits = self.ToString("0.#e+00", CultureInfo.InvariantCulture);
                    }
                    else if (spec.ThousandsComma)
                    {
                        digits = self.ToString("#,0.0###", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        digits = self.ToString("0.0###", CultureInfo.InvariantCulture);
                    }
                }
                break;

            case 'n':
            case 'g':
            case 'G': {
                // precision applies to the combined digits before and after the decimal point
                // so we first need find out how many digits we have before...
                int    digitCnt = 1;
                double cur      = self;
                while (cur >= 10)
                {
                    cur /= 10;
                    digitCnt++;
                }

                // Use exponents if we don't have enough room for all the digits before.  If we
                // only have as single digit avoid exponents.
                if (digitCnt > precision && digitCnt != 1)
                {
                    // first round off the decimal value
                    self = MathUtils.RoundAwayFromZero(self, 0);

                    // then remove any insignificant digits
                    double pow  = Math.Pow(10, digitCnt - Math.Max(precision, 1));
                    double rest = self / pow;
                    self = self - self % pow;
                    if ((rest % 1) >= .5)
                    {
                        // round up
                        self += pow;
                    }

                    string fmt;
                    if (spec.Type == 'n' && PythonContext.GetContext(context).NumericCulture != PythonContext.CCulture)
                    {
                        // we've already figured out, we don't have any digits for decimal points, so just format as a number + exponent
                        fmt = "0";
                    }
                    else if (spec.Precision > 1 || digitCnt > 6)
                    {
                        // include the requested precision to the right of the decimal
                        fmt = "0.#" + new string('#', precision);
                    }
                    else
                    {
                        // zero precision, no decimal
                        fmt = "0";
                    }
                    if (spec.ThousandsComma)
                    {
                        fmt = "#," + fmt;
                    }

                    digits = self.ToString(fmt + (spec.Type == 'G' ? "E+00" : "e+00"), CultureInfo.InvariantCulture);
                }
                else
                {
                    // we're including all the numbers to the right of the decimal we can, we explicitly
                    // round to match CPython's behavior
                    if (self < 1)
                    {
                        // no implicit 0
                        digitCnt--;
                    }
                    int decimalPoints = Math.Max(precision - digitCnt, 0);

                    self = MathUtils.RoundAwayFromZero(self, decimalPoints);

                    if (spec.Type == 'n' && PythonContext.GetContext(context).NumericCulture != PythonContext.CCulture)
                    {
                        if (digitCnt != precision && (self % 1) != 0)
                        {
                            digits = self.ToString("#,0.0" + new string('#', decimalPoints));
                        }
                        else
                        {
                            // leave out the decimal if the precision == # of digits or we have a whole number
                            digits = self.ToString("#,0");
                        }
                    }
                    else
                    {
                        if (digitCnt != precision && (self % 1) != 0)
                        {
                            digits = self.ToString("0.0" + new string('#', decimalPoints));
                        }
                        else
                        {
                            // leave out the decimal if the precision == # of digits or we have a whole number
                            digits = self.ToString("0");
                        }
                    }
                }
            }
            break;

            default:
                throw PythonOps.ValueError("Unknown format code '{0}' for object of type 'float'", spec.Type.ToString());
            }

            return(digits);
        }
Esempio n. 14
0
        internal static PythonDictionary GetExtensionCache(CodeContext /*!*/ context)
        {
            EnsureModuleInitialized(context);

            return((PythonDictionary)PythonContext.GetContext(context).GetModuleState(_extensionCacheKey));
        }
Esempio n. 15
0
 public static object iand(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceBitwiseAnd, a, b));
 }
Esempio n. 16
0
 public static object add(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.Add, a, b));
 }
Esempio n. 17
0
 public static object ipow(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlacePower, a, b));
 }
Esempio n. 18
0
 public static object floordiv(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.FloorDivide, a, b));
 }
Esempio n. 19
0
 public static object isub(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceSubtract, a, b));
 }
Esempio n. 20
0
 public static object mul(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.Multiply, a, b));
 }
Esempio n. 21
0
 public static object ixor(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceExclusiveOr, a, b));
 }
Esempio n. 22
0
 public static object or_(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Operation(PythonOperationKind.BitwiseOr, a, b));
 }
Esempio n. 23
0
 public static object Call(CodeContext /*!*/ context, Delegate @delegate, params object[] args)
 {
     return(PythonContext.GetContext(context).CallSplat(@delegate, args));
 }
Esempio n. 24
0
 public static bool contains(CodeContext /*!*/ context, object a, object b)
 {
     return(PythonContext.GetContext(context).Contains(b, a));
 }
Esempio n. 25
0
 public static int field_size_limit(CodeContext /*!*/ context)
 {
     return((int)PythonContext.GetContext(context).
            GetModuleState(_fieldSizeLimitKey));
 }
Esempio n. 26
0
 public static void delitem(CodeContext /*!*/ context, object a, object b)
 {
     PythonContext.GetContext(context).DelIndex(a, b);
 }
Esempio n. 27
0
 private static void SetStackSize(CodeContext /*!*/ context, int stackSize)
 {
     PythonContext.GetContext(context).SetModuleState(_stackSizeKey, stackSize);
 }
Esempio n. 28
0
 public static void setitem(CodeContext /*!*/ context, object a, object b, object c)
 {
     PythonContext.GetContext(context).SetIndex(a, b, c);
 }
Esempio n. 29
0
 private static void SetLockCount(CodeContext /*!*/ context, long lockCount)
 {
     PythonContext.GetContext(context).SetModuleState(_lockCountKey, lockCount);
 }
Esempio n. 30
0
        internal static PythonDictionary GetDispatchTable(CodeContext /*!*/ context)
        {
            EnsureModuleInitialized(context);

            return((PythonDictionary)PythonContext.GetContext(context).GetModuleState(_dispatchTableKey));
        }