Chris@87
|
1
|
Chris@87
|
2 /* Frame object interface */
|
Chris@87
|
3
|
Chris@87
|
4 #ifndef Py_FRAMEOBJECT_H
|
Chris@87
|
5 #define Py_FRAMEOBJECT_H
|
Chris@87
|
6 #ifdef __cplusplus
|
Chris@87
|
7 extern "C" {
|
Chris@87
|
8 #endif
|
Chris@87
|
9
|
Chris@87
|
10 typedef struct {
|
Chris@87
|
11 int b_type; /* what kind of block this is */
|
Chris@87
|
12 int b_handler; /* where to jump to find handler */
|
Chris@87
|
13 int b_level; /* value stack level to pop to */
|
Chris@87
|
14 } PyTryBlock;
|
Chris@87
|
15
|
Chris@87
|
16 typedef struct _frame {
|
Chris@87
|
17 PyObject_VAR_HEAD
|
Chris@87
|
18 struct _frame *f_back; /* previous frame, or NULL */
|
Chris@87
|
19 PyCodeObject *f_code; /* code segment */
|
Chris@87
|
20 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
|
Chris@87
|
21 PyObject *f_globals; /* global symbol table (PyDictObject) */
|
Chris@87
|
22 PyObject *f_locals; /* local symbol table (any mapping) */
|
Chris@87
|
23 PyObject **f_valuestack; /* points after the last local */
|
Chris@87
|
24 /* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
|
Chris@87
|
25 Frame evaluation usually NULLs it, but a frame that yields sets it
|
Chris@87
|
26 to the current stack top. */
|
Chris@87
|
27 PyObject **f_stacktop;
|
Chris@87
|
28 PyObject *f_trace; /* Trace function */
|
Chris@87
|
29
|
Chris@87
|
30 /* If an exception is raised in this frame, the next three are used to
|
Chris@87
|
31 * record the exception info (if any) originally in the thread state. See
|
Chris@87
|
32 * comments before set_exc_info() -- it's not obvious.
|
Chris@87
|
33 * Invariant: if _type is NULL, then so are _value and _traceback.
|
Chris@87
|
34 * Desired invariant: all three are NULL, or all three are non-NULL. That
|
Chris@87
|
35 * one isn't currently true, but "should be".
|
Chris@87
|
36 */
|
Chris@87
|
37 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
|
Chris@87
|
38
|
Chris@87
|
39 PyThreadState *f_tstate;
|
Chris@87
|
40 int f_lasti; /* Last instruction if called */
|
Chris@87
|
41 /* Call PyFrame_GetLineNumber() instead of reading this field
|
Chris@87
|
42 directly. As of 2.3 f_lineno is only valid when tracing is
|
Chris@87
|
43 active (i.e. when f_trace is set). At other times we use
|
Chris@87
|
44 PyCode_Addr2Line to calculate the line from the current
|
Chris@87
|
45 bytecode index. */
|
Chris@87
|
46 int f_lineno; /* Current line number */
|
Chris@87
|
47 int f_iblock; /* index in f_blockstack */
|
Chris@87
|
48 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
|
Chris@87
|
49 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
|
Chris@87
|
50 } PyFrameObject;
|
Chris@87
|
51
|
Chris@87
|
52
|
Chris@87
|
53 /* Standard object interface */
|
Chris@87
|
54
|
Chris@87
|
55 PyAPI_DATA(PyTypeObject) PyFrame_Type;
|
Chris@87
|
56
|
Chris@87
|
57 #define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
|
Chris@87
|
58 #define PyFrame_IsRestricted(f) \
|
Chris@87
|
59 ((f)->f_builtins != (f)->f_tstate->interp->builtins)
|
Chris@87
|
60
|
Chris@87
|
61 PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
|
Chris@87
|
62 PyObject *, PyObject *);
|
Chris@87
|
63
|
Chris@87
|
64
|
Chris@87
|
65 /* The rest of the interface is specific for frame objects */
|
Chris@87
|
66
|
Chris@87
|
67 /* Block management functions */
|
Chris@87
|
68
|
Chris@87
|
69 PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
|
Chris@87
|
70 PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
|
Chris@87
|
71
|
Chris@87
|
72 /* Extend the value stack */
|
Chris@87
|
73
|
Chris@87
|
74 PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
|
Chris@87
|
75
|
Chris@87
|
76 /* Conversions between "fast locals" and locals in dictionary */
|
Chris@87
|
77
|
Chris@87
|
78 PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
|
Chris@87
|
79 PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
|
Chris@87
|
80
|
Chris@87
|
81 PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
|
Chris@87
|
82
|
Chris@87
|
83 /* Return the line of code the frame is currently executing. */
|
Chris@87
|
84 PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
|
Chris@87
|
85
|
Chris@87
|
86 #ifdef __cplusplus
|
Chris@87
|
87 }
|
Chris@87
|
88 #endif
|
Chris@87
|
89 #endif /* !Py_FRAMEOBJECT_H */
|