blob: 157cba39debae63ecac892255c6f99a23751c99a [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_FRAMEOBJECT_H
2#define Py_FRAMEOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007/***********************************************************
Guido van Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000010
11 All Rights Reserved
12
Guido van Rossumd266eb41996-10-25 14:44:06 +000013Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000016both that copyright notice and this permission notice appear in
Guido van Rossumf70e43a1991-02-19 12:39:46 +000017supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000018Centrum or CWI or Corporation for National Research Initiatives or
19CNRI not be used in advertising or publicity pertaining to
20distribution of the software without specific, written prior
21permission.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000022
Guido van Rossumd266eb41996-10-25 14:44:06 +000023While CWI is the initial source for this software, a modified version
24is made available by the Corporation for National Research Initiatives
25(CNRI) at the Internet address ftp://ftp.python.org.
26
27STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
28REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
29MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
30CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
31DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
32PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000035
36******************************************************************/
37
Guido van Rossum3f5da241990-12-20 15:06:42 +000038/* Frame object interface */
39
40typedef struct {
41 int b_type; /* what kind of block this is */
42 int b_handler; /* where to jump to find handler */
43 int b_level; /* value stack level to pop to */
Guido van Rossumcaa63801995-01-12 11:45:45 +000044} PyTryBlock;
Guido van Rossum3f5da241990-12-20 15:06:42 +000045
46typedef struct _frame {
Guido van Rossumcaa63801995-01-12 11:45:45 +000047 PyObject_HEAD
Guido van Rossum3f5da241990-12-20 15:06:42 +000048 struct _frame *f_back; /* previous frame, or NULL */
Guido van Rossumcaa63801995-01-12 11:45:45 +000049 PyCodeObject *f_code; /* code segment */
50 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
51 PyObject *f_globals; /* global symbol table (PyDictObject) */
52 PyObject *f_locals; /* local symbol table (PyDictObject) */
Guido van Rossumcdf578e1997-01-20 04:16:40 +000053 PyObject **f_valuestack; /* points after the last local */
54 PyObject *f_trace; /* Trace function */
Guido van Rossuma027efa1997-05-05 20:56:21 +000055 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
56 PyThreadState *f_tstate;
Guido van Rossum088bc2a1992-01-14 18:32:11 +000057 int f_lasti; /* Last instruction if called */
58 int f_lineno; /* Current line number */
Guido van Rossumcaa63801995-01-12 11:45:45 +000059 int f_restricted; /* Flag set if restricted operations
60 in this scope */
Guido van Rossumcdf578e1997-01-20 04:16:40 +000061 int f_iblock; /* index in f_blockstack */
62 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
63 int f_nlocals; /* number of locals */
64 int f_stacksize; /* size of value stack */
65 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
Guido van Rossumcaa63801995-01-12 11:45:45 +000066} PyFrameObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000067
68
69/* Standard object interface */
70
Guido van Rossum051ab121995-02-27 10:17:52 +000071extern DL_IMPORT(PyTypeObject) PyFrame_Type;
Guido van Rossum3f5da241990-12-20 15:06:42 +000072
Guido van Rossumcaa63801995-01-12 11:45:45 +000073#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
Guido van Rossum3f5da241990-12-20 15:06:42 +000074
Guido van Rossumcaa63801995-01-12 11:45:45 +000075PyFrameObject * PyFrame_New
Guido van Rossuma027efa1997-05-05 20:56:21 +000076 Py_PROTO((PyThreadState *, PyCodeObject *,
Guido van Rossumcdf578e1997-01-20 04:16:40 +000077 PyObject *, PyObject *));
Guido van Rossum3f5da241990-12-20 15:06:42 +000078
79
80/* The rest of the interface is specific for frame objects */
81
Guido van Rossum93817821995-01-17 16:01:01 +000082/* Tuple access macros */
Guido van Rossum3f5da241990-12-20 15:06:42 +000083
Guido van Rossum408027e1996-12-30 16:17:54 +000084#ifndef Py_DEBUG
Guido van Rossumcaa63801995-01-12 11:45:45 +000085#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
86#define GETITEMNAME(v, i) \
87 PyString_AS_STRING((PyStringObject *)GETITEM((v), (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000088#else
Guido van Rossumcaa63801995-01-12 11:45:45 +000089#define GETITEM(v, i) PyTuple_GetItem((v), (i))
90#define GETITEMNAME(v, i) PyString_AsString(GETITEM(v, i))
Guido van Rossum3f5da241990-12-20 15:06:42 +000091#endif
92
Guido van Rossumcaa63801995-01-12 11:45:45 +000093#define GETUSTRINGVALUE(s) ((unsigned char *)PyString_AS_STRING(s))
Guido van Rossum3f5da241990-12-20 15:06:42 +000094
95/* Code access macros */
96
97#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
98#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
Guido van Rossumd594c911991-04-03 19:03:22 +000099#define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +0000100
101
102/* Block management functions */
103
Guido van Rossumcaa63801995-01-12 11:45:45 +0000104void PyFrame_BlockSetup Py_PROTO((PyFrameObject *, int, int, int));
105PyTryBlock *PyFrame_BlockPop Py_PROTO((PyFrameObject *));
Guido van Rossuma9e7dc11992-10-18 18:53:57 +0000106
107/* Extend the value stack */
108
Guido van Rossumcaa63801995-01-12 11:45:45 +0000109PyObject **PyFrame_ExtendStack Py_PROTO((PyFrameObject *, int, int));
Guido van Rossuma3309961993-07-28 09:05:47 +0000110
Guido van Rossumb6775db1994-08-01 11:34:53 +0000111/* Conversions between "fast locals" and locals in dictionary */
112
Guido van Rossum93817821995-01-17 16:01:01 +0000113void PyFrame_LocalsToFast Py_PROTO((PyFrameObject *, int));
114void PyFrame_FastToLocals Py_PROTO((PyFrameObject *));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000115
Guido van Rossuma3309961993-07-28 09:05:47 +0000116#ifdef __cplusplus
117}
118#endif
119#endif /* !Py_FRAMEOBJECT_H */