blob: e2bf7a1ef609674ccc330c5bb09b8ff5e1af05d2 [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 {
Fred Drakeea9cb5a2000-07-09 00:20:36 +000017 PyObject_HEAD
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 (PyDictObject) */
23 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 */
29 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
30 PyThreadState *f_tstate;
31 int f_lasti; /* Last instruction if called */
32 int f_lineno; /* Current line number */
33 int f_restricted; /* Flag set if restricted operations
Guido van Rossumcaa63801995-01-12 11:45:45 +000034 in this scope */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000035 int f_iblock; /* index in f_blockstack */
36 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
Jeremy Hylton2b724da2001-01-29 22:51:52 +000037 int f_size; /* size of localsplus */
Fred Drakeea9cb5a2000-07-09 00:20:36 +000038 int f_nlocals; /* number of locals */
Jeremy Hylton2b724da2001-01-29 22:51:52 +000039 int f_ncells;
40 int f_nfreevars;
Fred Drakeea9cb5a2000-07-09 00:20:36 +000041 int f_stacksize; /* size of value stack */
42 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
Guido van Rossumcaa63801995-01-12 11:45:45 +000043} PyFrameObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000044
45
46/* Standard object interface */
47
Guido van Rossum051ab121995-02-27 10:17:52 +000048extern DL_IMPORT(PyTypeObject) PyFrame_Type;
Guido van Rossum3f5da241990-12-20 15:06:42 +000049
Guido van Rossumcaa63801995-01-12 11:45:45 +000050#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
Guido van Rossum3f5da241990-12-20 15:06:42 +000051
Fred Drakeea9cb5a2000-07-09 00:20:36 +000052DL_IMPORT(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
Jeremy Hylton30c9f392001-03-13 01:58:22 +000053 PyObject *, PyObject *);
Guido van Rossum3f5da241990-12-20 15:06:42 +000054
55
56/* The rest of the interface is specific for frame objects */
57
Guido van Rossum93817821995-01-17 16:01:01 +000058/* Tuple access macros */
Guido van Rossum3f5da241990-12-20 15:06:42 +000059
Guido van Rossum408027e1996-12-30 16:17:54 +000060#ifndef Py_DEBUG
Guido van Rossumcaa63801995-01-12 11:45:45 +000061#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
62#define GETITEMNAME(v, i) \
63 PyString_AS_STRING((PyStringObject *)GETITEM((v), (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000064#else
Guido van Rossumcaa63801995-01-12 11:45:45 +000065#define GETITEM(v, i) PyTuple_GetItem((v), (i))
66#define GETITEMNAME(v, i) PyString_AsString(GETITEM(v, i))
Guido van Rossum3f5da241990-12-20 15:06:42 +000067#endif
68
Guido van Rossumcaa63801995-01-12 11:45:45 +000069#define GETUSTRINGVALUE(s) ((unsigned char *)PyString_AS_STRING(s))
Guido van Rossum3f5da241990-12-20 15:06:42 +000070
71/* Code access macros */
72
73#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
74#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
Guido van Rossumd594c911991-04-03 19:03:22 +000075#define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000076
77
78/* Block management functions */
79
Fred Drakeea9cb5a2000-07-09 00:20:36 +000080DL_IMPORT(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
81DL_IMPORT(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000082
83/* Extend the value stack */
84
Fred Drakeea9cb5a2000-07-09 00:20:36 +000085DL_IMPORT(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
Guido van Rossuma3309961993-07-28 09:05:47 +000086
Guido van Rossumb6775db1994-08-01 11:34:53 +000087/* Conversions between "fast locals" and locals in dictionary */
88
Fred Drakeea9cb5a2000-07-09 00:20:36 +000089DL_IMPORT(void) PyFrame_LocalsToFast(PyFrameObject *, int);
90DL_IMPORT(void) PyFrame_FastToLocals(PyFrameObject *);
Guido van Rossumb6775db1994-08-01 11:34:53 +000091
Guido van Rossuma3309961993-07-28 09:05:47 +000092#ifdef __cplusplus
93}
94#endif
95#endif /* !Py_FRAMEOBJECT_H */