blob: 17e7679ac870f0cabe67d05b85fc5a42e230f1d1 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum3f5da241990-12-20 15:06:42 +00002/* Frame object interface */
3
Fred Drakeea9cb5a2000-07-09 00:20:36 +00004#ifndef Py_FRAMEOBJECT_H
5#define Py_FRAMEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
Guido van Rossum3f5da241990-12-20 15:06:42 +000010typedef struct {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000011 int b_type; /* what kind of block this is */
12 int b_handler; /* where to jump to find handler */
13 int b_level; /* value stack level to pop to */
Guido van Rossumcaa63801995-01-12 11:45:45 +000014} PyTryBlock;
Guido van Rossum3f5da241990-12-20 15:06:42 +000015
16typedef struct _frame {
Neil Schemenauer251ead82001-08-29 23:45:25 +000017 PyObject_VAR_HEAD
Fred Drakeea9cb5a2000-07-09 00:20:36 +000018 struct _frame *f_back; /* previous frame, or NULL */
19 PyCodeObject *f_code; /* code segment */
20 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
21 PyObject *f_globals; /* global symbol table (PyDictObject) */
Raymond Hettinger214b1c32004-07-02 06:41:07 +000022 PyObject *f_locals; /* local symbol table (any mapping) */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000023 PyObject **f_valuestack; /* points after the last local */
Tim Peters8c963692001-06-23 05:26:56 +000024 /* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
25 Frame evaluation usually NULLs it, but a frame that yields sets it
26 to the current stack top. */
27 PyObject **f_stacktop;
Fred Drakeea9cb5a2000-07-09 00:20:36 +000028 PyObject *f_trace; /* Trace function */
Tim Peters7df5e7f2006-05-26 23:14:37 +000029
30 /* If an exception is raised in this frame, the next three are used to
31 * record the exception info (if any) originally in the thread state. See
32 * comments before set_exc_info() -- it's not obvious.
33 * Invariant: if _type is NULL, then so are _value and _traceback.
34 * Desired invariant: all three are NULL, or all three are non-NULL. That
35 * one isn't currently true, but "should be".
36 */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000037 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
Tim Peters7df5e7f2006-05-26 23:14:37 +000038
Fred Drakeea9cb5a2000-07-09 00:20:36 +000039 PyThreadState *f_tstate;
40 int f_lasti; /* Last instruction if called */
Jeffrey Yasskinf7f858d2009-05-08 22:23:21 +000041 /* Call PyFrame_GetLineNumber() instead of reading this field
42 directly. As of 2.3 f_lineno is only valid when tracing is
43 active (i.e. when f_trace is set). At other times we use
44 PyCode_Addr2Line to calculate the line from the current
45 bytecode index. */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000046 int f_lineno; /* Current line number */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000047 int f_iblock; /* index in f_blockstack */
48 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000049 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
Guido van Rossumcaa63801995-01-12 11:45:45 +000050} PyFrameObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000051
52
53/* Standard object interface */
54
Mark Hammond91a681d2002-08-12 07:21:58 +000055PyAPI_DATA(PyTypeObject) PyFrame_Type;
Guido van Rossum3f5da241990-12-20 15:06:42 +000056
Guido van Rossumcaa63801995-01-12 11:45:45 +000057#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
Neal Norwitzb9845e72006-06-12 02:11:18 +000058#define PyFrame_IsRestricted(f) \
59 ((f)->f_builtins != (f)->f_tstate->interp->builtins)
Guido van Rossum3f5da241990-12-20 15:06:42 +000060
Mark Hammond91a681d2002-08-12 07:21:58 +000061PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
Jeremy Hylton30c9f392001-03-13 01:58:22 +000062 PyObject *, PyObject *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000063
64
65/* The rest of the interface is specific for frame objects */
66
Guido van Rossum3f5da241990-12-20 15:06:42 +000067/* Block management functions */
68
Mark Hammond91a681d2002-08-12 07:21:58 +000069PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
70PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000071
72/* Extend the value stack */
73
Mark Hammond91a681d2002-08-12 07:21:58 +000074PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
Guido van Rossuma3309961993-07-28 09:05:47 +000075
Guido van Rossumb6775db1994-08-01 11:34:53 +000076/* Conversions between "fast locals" and locals in dictionary */
77
Mark Hammond91a681d2002-08-12 07:21:58 +000078PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
79PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
Guido van Rossumb6775db1994-08-01 11:34:53 +000080
Christian Heimes3b718a72008-02-14 12:47:33 +000081PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
82
Jeffrey Yasskinf7f858d2009-05-08 22:23:21 +000083/* Return the line of code the frame is currently executing. */
84PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
85
Guido van Rossuma3309961993-07-28 09:05:47 +000086#ifdef __cplusplus
87}
88#endif
89#endif /* !Py_FRAMEOBJECT_H */