blob: c51f58f9a3cc5898e0cf3ac18992998bc50946b8 [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 Rossumfd71b9e2000-06-30 23:50:40 +000013Copyright (c) 2000, BeOpen.com.
14Copyright (c) 1995-2000, Corporation for National Research Initiatives.
15Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
16All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000017
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000018See the file "Misc/COPYRIGHT" for information on usage and
19redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000020
21******************************************************************/
22
Guido van Rossum3f5da241990-12-20 15:06:42 +000023/* Frame object interface */
24
25typedef struct {
26 int b_type; /* what kind of block this is */
27 int b_handler; /* where to jump to find handler */
28 int b_level; /* value stack level to pop to */
Guido van Rossumcaa63801995-01-12 11:45:45 +000029} PyTryBlock;
Guido van Rossum3f5da241990-12-20 15:06:42 +000030
31typedef struct _frame {
Guido van Rossumcaa63801995-01-12 11:45:45 +000032 PyObject_HEAD
Guido van Rossum3f5da241990-12-20 15:06:42 +000033 struct _frame *f_back; /* previous frame, or NULL */
Guido van Rossumcaa63801995-01-12 11:45:45 +000034 PyCodeObject *f_code; /* code segment */
35 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
36 PyObject *f_globals; /* global symbol table (PyDictObject) */
37 PyObject *f_locals; /* local symbol table (PyDictObject) */
Guido van Rossumcdf578e1997-01-20 04:16:40 +000038 PyObject **f_valuestack; /* points after the last local */
39 PyObject *f_trace; /* Trace function */
Guido van Rossuma027efa1997-05-05 20:56:21 +000040 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
41 PyThreadState *f_tstate;
Guido van Rossum088bc2a1992-01-14 18:32:11 +000042 int f_lasti; /* Last instruction if called */
43 int f_lineno; /* Current line number */
Guido van Rossumcaa63801995-01-12 11:45:45 +000044 int f_restricted; /* Flag set if restricted operations
45 in this scope */
Guido van Rossumcdf578e1997-01-20 04:16:40 +000046 int f_iblock; /* index in f_blockstack */
47 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
48 int f_nlocals; /* number of locals */
49 int f_stacksize; /* size of value stack */
50 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
Guido van Rossumcaa63801995-01-12 11:45:45 +000051} PyFrameObject;
Guido van Rossum3f5da241990-12-20 15:06:42 +000052
53
54/* Standard object interface */
55
Guido van Rossum051ab121995-02-27 10:17:52 +000056extern DL_IMPORT(PyTypeObject) PyFrame_Type;
Guido van Rossum3f5da241990-12-20 15:06:42 +000057
Guido van Rossumcaa63801995-01-12 11:45:45 +000058#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
Guido van Rossum3f5da241990-12-20 15:06:42 +000059
Guido van Rossum43466ec1998-12-04 18:48:25 +000060DL_IMPORT(PyFrameObject *) PyFrame_New
Guido van Rossuma027efa1997-05-05 20:56:21 +000061 Py_PROTO((PyThreadState *, PyCodeObject *,
Guido van Rossumcdf578e1997-01-20 04:16:40 +000062 PyObject *, PyObject *));
Guido van Rossum3f5da241990-12-20 15:06:42 +000063
64
65/* The rest of the interface is specific for frame objects */
66
Guido van Rossum93817821995-01-17 16:01:01 +000067/* Tuple access macros */
Guido van Rossum3f5da241990-12-20 15:06:42 +000068
Guido van Rossum408027e1996-12-30 16:17:54 +000069#ifndef Py_DEBUG
Guido van Rossumcaa63801995-01-12 11:45:45 +000070#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
71#define GETITEMNAME(v, i) \
72 PyString_AS_STRING((PyStringObject *)GETITEM((v), (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000073#else
Guido van Rossumcaa63801995-01-12 11:45:45 +000074#define GETITEM(v, i) PyTuple_GetItem((v), (i))
75#define GETITEMNAME(v, i) PyString_AsString(GETITEM(v, i))
Guido van Rossum3f5da241990-12-20 15:06:42 +000076#endif
77
Guido van Rossumcaa63801995-01-12 11:45:45 +000078#define GETUSTRINGVALUE(s) ((unsigned char *)PyString_AS_STRING(s))
Guido van Rossum3f5da241990-12-20 15:06:42 +000079
80/* Code access macros */
81
82#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i)))
83#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i)))
Guido van Rossumd594c911991-04-03 19:03:22 +000084#define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i)))
Guido van Rossum3f5da241990-12-20 15:06:42 +000085
86
87/* Block management functions */
88
Guido van Rossum43466ec1998-12-04 18:48:25 +000089DL_IMPORT(void) PyFrame_BlockSetup Py_PROTO((PyFrameObject *, int, int, int));
90DL_IMPORT(PyTryBlock *) PyFrame_BlockPop Py_PROTO((PyFrameObject *));
Guido van Rossuma9e7dc11992-10-18 18:53:57 +000091
92/* Extend the value stack */
93
Guido van Rossum43466ec1998-12-04 18:48:25 +000094DL_IMPORT(PyObject **) PyFrame_ExtendStack Py_PROTO((PyFrameObject *, int, int));
Guido van Rossuma3309961993-07-28 09:05:47 +000095
Guido van Rossumb6775db1994-08-01 11:34:53 +000096/* Conversions between "fast locals" and locals in dictionary */
97
Guido van Rossum43466ec1998-12-04 18:48:25 +000098DL_IMPORT(void) PyFrame_LocalsToFast Py_PROTO((PyFrameObject *, int));
99DL_IMPORT(void) PyFrame_FastToLocals Py_PROTO((PyFrameObject *));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000100
Guido van Rossuma3309961993-07-28 09:05:47 +0000101#ifdef __cplusplus
102}
103#endif
104#endif /* !Py_FRAMEOBJECT_H */