Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 1 | /* Frame object interface */ |
| 2 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 3 | #ifndef Py_LIMITED_API |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 4 | #ifndef Py_FRAMEOBJECT_H |
| 5 | #define Py_FRAMEOBJECT_H |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 10 | typedef struct { |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 11 | 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 Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 14 | } PyTryBlock; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 15 | |
| 16 | typedef struct _frame { |
Neil Schemenauer | 251ead8 | 2001-08-29 23:45:25 +0000 | [diff] [blame] | 17 | PyObject_VAR_HEAD |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 18 | 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) */ |
| 22 | PyObject *f_locals; /* local symbol table (any mapping) */ |
| 23 | PyObject **f_valuestack; /* points after the last local */ |
Tim Peters | 8c96369 | 2001-06-23 05:26:56 +0000 | [diff] [blame] | 24 | /* 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; |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 28 | PyObject *f_trace; /* Trace function */ |
Nick Coghlan | 5a85167 | 2017-09-08 10:14:16 +1000 | [diff] [blame] | 29 | char f_trace_lines; /* Emit per-line trace events? */ |
| 30 | char f_trace_opcodes; /* Emit per-opcode trace events? */ |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 31 | |
Antoine Pitrou | 236a547 | 2013-08-06 23:06:59 +0200 | [diff] [blame] | 32 | /* Borrowed reference to a generator, or NULL */ |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 33 | PyObject *f_gen; |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 34 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 35 | int f_lasti; /* Last instruction if called */ |
Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 36 | /* Call PyFrame_GetLineNumber() instead of reading this field |
| 37 | directly. As of 2.3 f_lineno is only valid when tracing is |
| 38 | active (i.e. when f_trace is set). At other times we use |
| 39 | PyCode_Addr2Line to calculate the line from the current |
| 40 | bytecode index. */ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 41 | int f_lineno; /* Current line number */ |
| 42 | int f_iblock; /* index in f_blockstack */ |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 43 | char f_executing; /* whether the frame is still executing */ |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 44 | PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 45 | PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 46 | } PyFrameObject; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | /* Standard object interface */ |
| 50 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 51 | PyAPI_DATA(PyTypeObject) PyFrame_Type; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 52 | |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 53 | #define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 54 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 55 | PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, |
INADA Naoki | 5a625d0 | 2016-12-24 20:19:08 +0900 | [diff] [blame] | 56 | PyObject *, PyObject *); |
| 57 | |
| 58 | /* only internal use */ |
| 59 | PyFrameObject* _PyFrame_New_NoTrack(PyThreadState *, PyCodeObject *, |
| 60 | PyObject *, PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | /* The rest of the interface is specific for frame objects */ |
| 64 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 65 | /* Block management functions */ |
| 66 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 67 | PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int); |
| 68 | PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *); |
Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 69 | |
| 70 | /* Extend the value stack */ |
| 71 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 72 | PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 73 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 74 | /* Conversions between "fast locals" and locals in dictionary */ |
| 75 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 76 | PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); |
Victor Stinner | 41bb43a | 2013-10-29 01:19:37 +0100 | [diff] [blame] | 77 | |
| 78 | PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 79 | PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 80 | |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 81 | PyAPI_FUNC(int) PyFrame_ClearFreeList(void); |
| 82 | |
David Malcolm | 49526f4 | 2012-06-22 14:55:41 -0400 | [diff] [blame] | 83 | PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out); |
| 84 | |
Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 85 | /* Return the line of code the frame is currently executing. */ |
| 86 | PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *); |
| 87 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 88 | #ifdef __cplusplus |
| 89 | } |
| 90 | #endif |
| 91 | #endif /* !Py_FRAMEOBJECT_H */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 92 | #endif /* Py_LIMITED_API */ |