Ejemplo n.º 1
0
        public static TraceBackFrame /*!*/ _getframeImpl(CodeContext /*!*/ context, int depth)
        {
            var stack = PythonOps.GetFunctionStack();

            if (depth < stack.Count)
            {
                TraceBackFrame cur           = null;
                int            curTraceFrame = -1;

                for (int i = 0; i < stack.Count - depth; i++)
                {
                    var elem = stack[i];

                    if (elem.Frame != null)
                    {
                        // we previously handed out a frame here, hand out the same one now
                        cur = elem.Frame;
                    }
                    else
                    {
                        // create a new frame and save it for future calls
                        cur = new TraceBackFrame(
                            context,
                            Builtin.globals(elem.Context),
                            Builtin.locals(elem.Context),
                            elem.Code,
                            cur
                            );

                        stack[i] = new FunctionStack(elem.Context, elem.Code, cur);
                    }

                    curTraceFrame++;
                }
                return(cur);
            }

            throw PythonOps.ValueError("call stack is not deep enough");
        }
Ejemplo n.º 2
0
        public static void warn(CodeContext context, object message, PythonType category = null, int stacklevel = 1)
        {
            PythonContext pContext = context.LanguageContext;
            List          argv     = pContext.GetSystemStateValue("argv") as List;

            if (PythonOps.IsInstance(message, PythonExceptions.Warning))
            {
                category = DynamicHelpers.GetPythonType(message);
            }
            if (category == null)
            {
                category = PythonExceptions.UserWarning;
            }
            if (!category.IsSubclassOf(PythonExceptions.Warning))
            {
                throw PythonOps.ValueError("category is not a subclass of Warning");
            }

            TraceBackFrame   caller = null;
            PythonDictionary globals;
            int lineno;

            if (context.LanguageContext.PythonOptions.Frames)
            {
                try {
                    caller = SysModule._getframeImpl(context, stacklevel - 1);
                } catch (ValueErrorException) { }
            }
            if (caller == null)
            {
                globals = Builtin.globals(context) as PythonDictionary;
                lineno  = 1;
            }
            else
            {
                globals = caller.f_globals;
                lineno  = (int)caller.f_lineno;
            }

            string module;
            string filename;

            if (globals != null && globals.ContainsKey("__name__"))
            {
                module = (string)globals.get("__name__");
            }
            else
            {
                module = "<string>";
            }

            filename = globals.get("__file__") as string;
            if (filename == null || filename == "")
            {
                if (module == "__main__")
                {
                    if (argv != null && argv.Count > 0)
                    {
                        filename = argv[0] as string;
                    }
                    else
                    {
                        // interpreter lacks sys.argv
                        filename = "__main__";
                    }
                }
                if (filename == null || filename == "")
                {
                    filename = module;
                }
            }

            PythonDictionary registry = (PythonDictionary)globals.setdefault("__warningregistry__", new PythonDictionary());

            warn_explicit(context, message, category, filename, lineno, module, registry, globals);
        }
Ejemplo n.º 3
0
 public static object abs(CodeContext context, object o)
 {
     return(Builtin.abs(context, o));
 }
Ejemplo n.º 4
0
 public static object reduce(CodeContext /*!*/ context, SiteLocalStorage <CallSite <Func <CallSite, CodeContext, object, object, object, object> > > siteData, object func, object seq, object initializer)
 {
     return(Builtin.reduce(context, siteData, func, seq, initializer));
 }
Ejemplo n.º 5
0
 public static void _check_HRESULT(int hresult)
 {
     if (hresult < 0)
     {
         throw PythonOps.WindowsError("ctypes function returned failed HRESULT: {0}", Builtin.hex((BigInteger)(uint)hresult));
     }
 }
Ejemplo n.º 6
0
 public static object reload(CodeContext /*!*/ context, PythonModule scope)
 {
     return(Builtin.reload(context, scope));
 }
Ejemplo n.º 7
0
 public static object IsCallable(object o)
 {
     return(Builtin.Callable(o));
 }
Ejemplo n.º 8
0
 public static object OperatorAbs(object o)
 {
     return(Builtin.Abs(o));
 }
Ejemplo n.º 9
0
 public static object Abs(object o)
 {
     return(Builtin.Abs(o));
 }