frameobject.h 3.45 KB
Newer Older
1

Guido van Rossum's avatar
Guido van Rossum committed
2 3
/* Frame object interface */

4
#ifndef Py_LIMITED_API
5 6 7 8 9 10
#ifndef Py_FRAMEOBJECT_H
#define Py_FRAMEOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif

Guido van Rossum's avatar
Guido van Rossum committed
11
typedef struct {
12 13 14
    int b_type;                 /* what kind of block this is */
    int b_handler;              /* where to jump to find handler */
    int b_level;                /* value stack level to pop to */
15
} PyTryBlock;
Guido van Rossum's avatar
Guido van Rossum committed
16 17

typedef struct _frame {
18
    PyObject_VAR_HEAD
19 20 21 22 23 24
    struct _frame *f_back;      /* previous frame, or NULL */
    PyCodeObject *f_code;       /* code segment */
    PyObject *f_builtins;       /* builtin symbol table (PyDictObject) */
    PyObject *f_globals;        /* global symbol table (PyDictObject) */
    PyObject *f_locals;         /* local symbol table (any mapping) */
    PyObject **f_valuestack;    /* points after the last local */
25 26 27 28
    /* Next free slot in f_valuestack.  Frame creation sets to f_valuestack.
       Frame evaluation usually NULLs it, but a frame that yields sets it
       to the current stack top. */
    PyObject **f_stacktop;
29 30
    PyObject *f_trace;          /* Trace function */

31 32 33 34 35 36 37
    /* In a generator, we need to be able to swap between the exception
       state inside the generator and the exception state of the calling
       frame (which shouldn't be impacted when the generator "yields"
       from an except handler).
       These three fields exist exactly for that, and are unused for
       non-generator frames. See the save_exc_state and swap_exc_state
       functions in ceval.c for details of their use. */
38
    PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
39
    /* Borrowed reference to a generator, or NULL */
40
    PyObject *f_gen;
41

42
    int f_lasti;                /* Last instruction if called */
43 44 45 46 47
    /* Call PyFrame_GetLineNumber() instead of reading this field
       directly.  As of 2.3 f_lineno is only valid when tracing is
       active (i.e. when f_trace is set).  At other times we use
       PyCode_Addr2Line to calculate the line from the current
       bytecode index. */
48 49
    int f_lineno;               /* Current line number */
    int f_iblock;               /* index in f_blockstack */
50
    char f_executing;           /* whether the frame is still executing */
51
    PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
52
    PyObject *f_localsplus[1];  /* locals+stack, dynamically sized */
53
} PyFrameObject;
Guido van Rossum's avatar
Guido van Rossum committed
54 55 56 57


/* Standard object interface */

58
PyAPI_DATA(PyTypeObject) PyFrame_Type;
Guido van Rossum's avatar
Guido van Rossum committed
59

60
#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
Guido van Rossum's avatar
Guido van Rossum committed
61

62
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
63
                                       PyObject *, PyObject *);
Guido van Rossum's avatar
Guido van Rossum committed
64 65 66 67 68 69


/* The rest of the interface is specific for frame objects */

/* Block management functions */

70 71
PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
72 73 74

/* Extend the value stack */

75
PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
76

77 78
/* Conversions between "fast locals" and locals in dictionary */

79
PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
80 81

PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
82
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
83

Christian Heimes's avatar
Christian Heimes committed
84 85
PyAPI_FUNC(int) PyFrame_ClearFreeList(void);

86 87
PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);

88 89 90
/* Return the line of code the frame is currently executing. */
PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);

91 92 93 94
#ifdef __cplusplus
}
#endif
#endif /* !Py_FRAMEOBJECT_H */
95
#endif /* Py_LIMITED_API */