blob: 36a51baae8784bae26ab18169dce77ed4780edf9 [file] [log] [blame]
Haibo Huang5eba2b42021-01-22 11:22:02 -08001/* Frame object interface */
2
3#ifndef Py_CPYTHON_FRAMEOBJECT_H
4# error "this header file must not be included directly"
5#endif
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef struct {
12 int b_type; /* what kind of block this is */
13 int b_handler; /* where to jump to find handler */
14 int b_level; /* value stack level to pop to */
15} PyTryBlock;
16
17struct _frame {
18 PyObject_VAR_HEAD
19 struct _frame *f_back; /* previous frame, or NULL */
20 PyCodeObject *f_code; /* code segment */
21 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
22 PyObject *f_globals; /* global symbol table (PyDictObject) */
23 PyObject *f_locals; /* local symbol table (any mapping) */
24 PyObject **f_valuestack; /* points after the last local */
25 /* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
26 Frame evaluation usually NULLs it, but a frame that yields sets it
27 to the current stack top. */
28 PyObject **f_stacktop;
29 PyObject *f_trace; /* Trace function */
30 char f_trace_lines; /* Emit per-line trace events? */
31 char f_trace_opcodes; /* Emit per-opcode trace events? */
32
33 /* Borrowed reference to a generator, or NULL */
34 PyObject *f_gen;
35
36 int f_lasti; /* Last instruction if called */
37 /* Call PyFrame_GetLineNumber() instead of reading this field
38 directly. As of 2.3 f_lineno is only valid when tracing is
39 active (i.e. when f_trace is set). At other times we use
40 PyCode_Addr2Line to calculate the line from the current
41 bytecode index. */
42 int f_lineno; /* Current line number */
43 int f_iblock; /* index in f_blockstack */
44 char f_executing; /* whether the frame is still executing */
45 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
46 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
47};
48
49
50/* Standard object interface */
51
52PyAPI_DATA(PyTypeObject) PyFrame_Type;
53
54#define PyFrame_Check(op) Py_IS_TYPE(op, &PyFrame_Type)
55
56PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
57 PyObject *, PyObject *);
58
59/* only internal use */
60PyFrameObject* _PyFrame_New_NoTrack(PyThreadState *, PyCodeObject *,
61 PyObject *, PyObject *);
62
63
64/* The rest of the interface is specific for frame objects */
65
66/* Block management functions */
67
68PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
69PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
70
71/* Conversions between "fast locals" and locals in dictionary */
72
73PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
74
75PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
76PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
77
78PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
79
80PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
81
82#ifdef __cplusplus
83}
84#endif