blob: 949016a47b77b862bf2304a420caf8b8aafd0aea [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
13Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
15provided that the above copyright notice appear in all copies and that
16both that copyright notice and this permission notice appear in
17supporting documentation, and that the names of Stichting Mathematisch
18Centrum or CWI not be used in advertising or publicity pertaining to
19distribution of the software without specific, written prior permission.
20
21STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
22THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
23FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
24FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
29******************************************************************/
30
Guido van Rossum3f5da241990-12-20 15:06:42 +000031/* Frame object interface */
32
33typedef struct {
34 int b_type; /* what kind of block this is */
35 int b_handler; /* where to jump to find handler */
36 int b_level; /* value stack level to pop to */
Guido van Rossumcaa63801995-01-12 11:45:45 +000037} PyTryBlock;
Guido van Rossum3f5da241990-12-20 15:06:42 +000038
39typedef struct _frame {
Guido van Rossumcaa63801995-01-12 11:45:45 +000040 PyObject_HEAD
Guido van Rossum3f5da241990-12-20 15:06:42 +000041 struct _frame *f_back; /* previous frame, or NULL */
Guido van Rossumcaa63801995-01-12 11:45:45 +000042 PyCodeObject *f_code; /* code segment */
43 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
44 PyObject *f_globals; /* global symbol table (PyDictObject) */
45 PyObject *f_locals; /* local symbol table (PyDictObject) */
46 PyObject *f_owner; /* owner (e.g. class or module) or NULL */
47 PyObject *f_fastlocals; /* fast local variables (PyListObject) */
48 PyObject *f_localmap; /* local variable names (PyDictObject) */
49 PyObject **f_valuestack; /* malloc'ed array */
50 PyTryBlock *f_blockstack; /* malloc'ed array */
Guido van Rossum3f5da241990-12-20 15:06:42 +000051 int f_nvalues; /* size of f_valuestack */
52 int f_nblocks; /* size of f_blockstack */
53 int f_iblock; /* index in f_blockstack */
Guido van Rossum088bc2a1992-01-14 18:32:11 +000054 int f_lasti; /* Last instruction if called */
55 int f_lineno; /* Current line number */
Guido van Rossumcaa63801995-01-12 11:45:45 +000056 int f_restricted; /* Flag set if restricted operations
57 in this scope */
58 PyObject *f_trace; /* Trace function */
59} PyFrameObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000060
61
62/* Standard object interface */
63
Guido van Rossumcaa63801995-01-12 11:45:45 +000064extern DL_IMPORT PyTypeObject PyFrame_Type;
Guido van Rossum3f5da241990-12-20 15:06:42 +000065
Guido van Rossumcaa63801995-01-12 11:45:45 +000066#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
Guido van Rossum3f5da241990-12-20 15:06:42 +000067
Guido van Rossumcaa63801995-01-12 11:45:45 +000068PyFrameObject * PyFrame_New
69 Py_PROTO((PyFrameObject *, PyCodeObject *,
70 PyObject *, PyObject *, PyObject *, int, int));
Guido van Rossum3f5da241990-12-20 15:06:42 +000071
72
73/* The rest of the interface is specific for frame objects */
74
Guido van Rossum93817821995-01-17 16:01:01 +000075/* Tuple access macros */
Guido van Rossum3f5da241990-12-20 15:06:42 +000076
77#ifdef NDEBUG
Guido van Rossumcaa63801995-01-12 11:45:45 +000078#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
79#define GETITEMNAME(v, i) \
80 PyString_AS_STRING((PyStringObject *)GETITEM((v), (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000081#else
Guido van Rossumcaa63801995-01-12 11:45:45 +000082#define GETITEM(v, i) PyTuple_GetItem((v), (i))
83#define GETITEMNAME(v, i) PyString_AsString(GETITEM(v, i))
Guido van Rossum3f5da241990-12-20 15:06:42 +000084#endif
85
Guido van Rossumcaa63801995-01-12 11:45:45 +000086#define GETUSTRINGVALUE(s) ((unsigned char *)PyString_AS_STRING(s))
Guido van Rossum3f5da241990-12-20 15:06:42 +000087
88/* Code access macros */
89
90#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
91#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
Guido van Rossumd594c911991-04-03 19:03:22 +000092#define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000093
94
95/* Block management functions */
96
Guido van Rossumcaa63801995-01-12 11:45:45 +000097void PyFrame_BlockSetup Py_PROTO((PyFrameObject *, int, int, int));
98PyTryBlock *PyFrame_BlockPop Py_PROTO((PyFrameObject *));
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000099
100/* Extend the value stack */
101
Guido van Rossumcaa63801995-01-12 11:45:45 +0000102PyObject **PyFrame_ExtendStack Py_PROTO((PyFrameObject *, int, int));
Guido van Rossuma3309961993-07-28 09:05:47 +0000103
Guido van Rossumb6775db1994-08-01 11:34:53 +0000104/* Conversions between "fast locals" and locals in dictionary */
105
Guido van Rossum93817821995-01-17 16:01:01 +0000106void PyFrame_LocalsToFast Py_PROTO((PyFrameObject *, int));
107void PyFrame_FastToLocals Py_PROTO((PyFrameObject *));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000108
Guido van Rossuma3309961993-07-28 09:05:47 +0000109#ifdef __cplusplus
110}
111#endif
112#endif /* !Py_FRAMEOBJECT_H */