| Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 |  | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 2 | /* Frame object interface */ | 
 | 3 |  | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 4 | #ifndef Py_LIMITED_API | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 5 | #ifndef Py_FRAMEOBJECT_H | 
 | 6 | #define Py_FRAMEOBJECT_H | 
 | 7 | #ifdef __cplusplus | 
 | 8 | extern "C" { | 
 | 9 | #endif | 
 | 10 |  | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 11 | typedef struct { | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 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 */ | 
| Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 15 | } PyTryBlock; | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 16 |  | 
 | 17 | typedef struct _frame { | 
| Neil Schemenauer | 251ead8 | 2001-08-29 23:45:25 +0000 | [diff] [blame] | 18 |     PyObject_VAR_HEAD | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 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) */ | 
| Raymond Hettinger | 214b1c3 | 2004-07-02 06:41:07 +0000 | [diff] [blame] | 23 |     PyObject *f_locals;		/* local symbol table (any mapping) */ | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 24 |     PyObject **f_valuestack;	/* points after the last local */ | 
| Tim Peters | 8c96369 | 2001-06-23 05:26:56 +0000 | [diff] [blame] | 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; | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 29 |     PyObject *f_trace;		/* Trace function */ | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 30 |  | 
| Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 31 | 	/* In a generator, we need to be able to swap between the exception | 
 | 32 | 	   state inside the generator and the exception state of the calling | 
 | 33 | 	   frame (which shouldn't be impacted when the generator "yields" | 
 | 34 | 	   from an except handler). | 
 | 35 | 	   These three fields exist exactly for that, and are unused for | 
 | 36 | 	   non-generator frames. See the SAVE_EXC_STATE and SWAP_EXC_STATE | 
 | 37 | 	   macros in ceval.c for details of their use. */ | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 38 |     PyObject *f_exc_type, *f_exc_value, *f_exc_traceback; | 
| Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 39 |  | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 40 |     PyThreadState *f_tstate; | 
 | 41 |     int f_lasti;		/* Last instruction if called */ | 
| Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 42 |     /* Call PyFrame_GetLineNumber() instead of reading this field | 
 | 43 |        directly.  As of 2.3 f_lineno is only valid when tracing is | 
 | 44 |        active (i.e. when f_trace is set).  At other times we use | 
 | 45 |        PyCode_Addr2Line to calculate the line from the current | 
 | 46 |        bytecode index. */ | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 47 |     int f_lineno;		/* Current line number */ | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 48 |     int f_iblock;		/* index in f_blockstack */ | 
 | 49 |     PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ | 
| Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 50 |     PyObject *f_localsplus[1];	/* locals+stack, dynamically sized */ | 
| Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 51 | } PyFrameObject; | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 52 |  | 
 | 53 |  | 
 | 54 | /* Standard object interface */ | 
 | 55 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 56 | PyAPI_DATA(PyTypeObject) PyFrame_Type; | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 57 |  | 
| Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 58 | #define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type) | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 59 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 60 | PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, | 
| Jeremy Hylton | 30c9f39 | 2001-03-13 01:58:22 +0000 | [diff] [blame] | 61 |                                        PyObject *, PyObject *); | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 62 |  | 
 | 63 |  | 
 | 64 | /* The rest of the interface is specific for frame objects */ | 
 | 65 |  | 
| Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 66 | /* Block management functions */ | 
 | 67 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 68 | PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int); | 
 | 69 | PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *); | 
| Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 70 |  | 
 | 71 | /* Extend the value stack */ | 
 | 72 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 73 | PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int); | 
| Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 74 |  | 
| Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 75 | /* Conversions between "fast locals" and locals in dictionary */ | 
 | 76 |  | 
| Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 77 | PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); | 
 | 78 | PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); | 
| Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 79 |  | 
| Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 80 | PyAPI_FUNC(int) PyFrame_ClearFreeList(void); | 
 | 81 |  | 
| Alexandre Vassalotti | 7b82b40 | 2009-07-21 04:30:03 +0000 | [diff] [blame] | 82 | /* Return the line of code the frame is currently executing. */ | 
 | 83 | PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *); | 
 | 84 |  | 
| Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 85 | #ifdef __cplusplus | 
 | 86 | } | 
 | 87 | #endif | 
 | 88 | #endif /* !Py_FRAMEOBJECT_H */ | 
| Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 89 | #endif /* Py_LIMITED_API */ |