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