Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 11 | /* Frame object interface */ |
| 12 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 13 | #ifndef Py_FRAMEOBJECT_H |
| 14 | #define Py_FRAMEOBJECT_H |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 19 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 20 | int b_type; /* what kind of block this is */ |
| 21 | int b_handler; /* where to jump to find handler */ |
| 22 | int b_level; /* value stack level to pop to */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 23 | } PyTryBlock; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 24 | |
| 25 | typedef struct _frame { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 26 | PyObject_HEAD |
| 27 | struct _frame *f_back; /* previous frame, or NULL */ |
| 28 | PyCodeObject *f_code; /* code segment */ |
| 29 | PyObject *f_builtins; /* builtin symbol table (PyDictObject) */ |
| 30 | PyObject *f_globals; /* global symbol table (PyDictObject) */ |
| 31 | PyObject *f_locals; /* local symbol table (PyDictObject) */ |
| 32 | PyObject **f_valuestack; /* points after the last local */ |
| 33 | PyObject *f_trace; /* Trace function */ |
| 34 | PyObject *f_exc_type, *f_exc_value, *f_exc_traceback; |
| 35 | PyThreadState *f_tstate; |
| 36 | int f_lasti; /* Last instruction if called */ |
| 37 | int f_lineno; /* Current line number */ |
| 38 | int f_restricted; /* Flag set if restricted operations |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 39 | in this scope */ |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 40 | int f_iblock; /* index in f_blockstack */ |
| 41 | PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ |
| 42 | int f_nlocals; /* number of locals */ |
| 43 | int f_stacksize; /* size of value stack */ |
| 44 | PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 45 | } PyFrameObject; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 46 | |
| 47 | |
| 48 | /* Standard object interface */ |
| 49 | |
Guido van Rossum | 051ab12 | 1995-02-27 10:17:52 +0000 | [diff] [blame] | 50 | extern DL_IMPORT(PyTypeObject) PyFrame_Type; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 51 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 52 | #define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 53 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 54 | DL_IMPORT(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, |
| 55 | PyObject *, PyObject *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | /* The rest of the interface is specific for frame objects */ |
| 59 | |
Guido van Rossum | 9381782 | 1995-01-17 16:01:01 +0000 | [diff] [blame] | 60 | /* Tuple access macros */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 62 | #ifndef Py_DEBUG |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 63 | #define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i)) |
| 64 | #define GETITEMNAME(v, i) \ |
| 65 | PyString_AS_STRING((PyStringObject *)GETITEM((v), (i))) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 66 | #else |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 67 | #define GETITEM(v, i) PyTuple_GetItem((v), (i)) |
| 68 | #define GETITEMNAME(v, i) PyString_AsString(GETITEM(v, i)) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 71 | #define GETUSTRINGVALUE(s) ((unsigned char *)PyString_AS_STRING(s)) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 72 | |
| 73 | /* Code access macros */ |
| 74 | |
| 75 | #define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i))) |
| 76 | #define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i))) |
Guido van Rossum | d594c91 | 1991-04-03 19:03:22 +0000 | [diff] [blame] | 77 | #define Getnamev(f, i) (GETITEM((f)->f_code->co_names, (i))) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | /* Block management functions */ |
| 81 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 82 | DL_IMPORT(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int); |
| 83 | DL_IMPORT(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *); |
Guido van Rossum | a9e7dc1 | 1992-10-18 18:53:57 +0000 | [diff] [blame] | 84 | |
| 85 | /* Extend the value stack */ |
| 86 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 87 | DL_IMPORT(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 88 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 89 | /* Conversions between "fast locals" and locals in dictionary */ |
| 90 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 91 | DL_IMPORT(void) PyFrame_LocalsToFast(PyFrameObject *, int); |
| 92 | DL_IMPORT(void) PyFrame_FastToLocals(PyFrameObject *); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 93 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 94 | #ifdef __cplusplus |
| 95 | } |
| 96 | #endif |
| 97 | #endif /* !Py_FRAMEOBJECT_H */ |