/Include/frameobject.h

http://unladen-swallow.googlecode.com/ · C Header · 139 lines · 72 code · 27 blank · 40 comment · 2 complexity · 1ad8f6a0559319d5ad9d590104d7d36c MD5 · raw file

  1. /* Frame object interface */
  2. #ifndef Py_FRAMEOBJECT_H
  3. #define Py_FRAMEOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct PyTryBlock {
  8. int b_type; /* what kind of block this is */
  9. int b_handler; /* where to jump to find handler */
  10. int b_level; /* value stack level to pop to */
  11. } PyTryBlock;
  12. /* Keep this in sync with Util/PyTypeBuilder.h. */
  13. typedef struct _frame {
  14. PyObject_VAR_HEAD
  15. struct _frame *f_back; /* previous frame, or NULL */
  16. PyCodeObject *f_code; /* code segment */
  17. PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
  18. PyObject *f_globals; /* global symbol table (PyDictObject) */
  19. PyObject *f_locals; /* local symbol table (any mapping) */
  20. PyObject **f_valuestack; /* points after the last local */
  21. /* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
  22. Frame evaluation usually NULLs it, but a frame that yields sets it
  23. to the current stack top. */
  24. PyObject **f_stacktop;
  25. PyObject *f_trace; /* Trace function */
  26. /* If an exception is raised in this frame, the next three are used to
  27. * record the exception info (if any) originally in the thread state. See
  28. * comments before set_exc_info() -- it's not obvious.
  29. * Invariant: if _type is NULL, then so are _value and _traceback.
  30. * Desired invariant: all three are NULL, or all three are non-NULL. That
  31. * one isn't currently true, but "should be".
  32. */
  33. PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
  34. PyThreadState *f_tstate;
  35. /* When running through the bytecode interpreter, f_lasti records
  36. the index of the most recent instruction to start executing.
  37. It's used to resume generators, to let tracers change the
  38. current line number, and to look up the current line number
  39. through co_lnotab (See PyCode_Addr2Line). Under LLVM, f_lasti
  40. is a negative number used to index basic blocks that we might
  41. want to resume from (for generators and line changes within
  42. tracing functions). When f_lasti is negative (and hence
  43. meaningless), f_lineno is correct. f_lasti is initialized to
  44. -1 when a function is first entered. */
  45. int f_lasti;
  46. #ifdef WITH_LLVM
  47. /* At frame creation-time, we snapshot the state of f_code->co_use_jit.
  48. Without this, Python code can cause active generators to flip between
  49. LLVM and the interpreter at will, which is a bad idea. */
  50. int f_use_jit;
  51. #endif
  52. /* Call PyFrame_GetLineNumber() instead of reading this field
  53. directly. As of Unladen Swallow 2009Q2 f_lineno is valid when
  54. tracing is active (i.e. when f_trace is set) and when f_lasti
  55. is negative. At other times we use PyCode_Addr2Line to
  56. calculate the line from the current bytecode index. */
  57. int f_lineno; /* Current line number */
  58. unsigned char f_throwflag; /* true if generator.throw() was called */
  59. unsigned char f_iblock; /* index in f_blockstack */
  60. #ifdef WITH_LLVM
  61. /* Holds a value from _PyFrameBailReason describing if we've
  62. bailed back from JITted code to the interpreter loop and
  63. why. */
  64. unsigned char f_bailed_from_llvm;
  65. unsigned char f_guard_type;
  66. #endif
  67. PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
  68. PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
  69. } PyFrameObject;
  70. typedef enum _PyFrameBailReason {
  71. _PYFRAME_NO_BAIL,
  72. _PYFRAME_TRACE_ON_ENTRY,
  73. _PYFRAME_LINE_TRACE,
  74. _PYFRAME_BACKEDGE_TRACE,
  75. _PYFRAME_CALL_PROFILE,
  76. /* Fatal guard failures invalidate the machine code. */
  77. _PYFRAME_FATAL_GUARD_FAIL,
  78. _PYFRAME_GUARD_FAIL,
  79. } _PyFrameBailReason;
  80. enum _PyFrameGuardType {
  81. _PYGUARD_DEFAULT = 0,
  82. _PYGUARD_BINOP,
  83. _PYGUARD_ATTR,
  84. _PYGUARD_CFUNC,
  85. _PYGUARD_BRANCH,
  86. _PYGUARD_STORE_SUBSCR,
  87. _PYGUARD_LOAD_METHOD,
  88. _PYGUARD_CALL_METHOD,
  89. };
  90. /* Standard object interface */
  91. PyAPI_DATA(PyTypeObject) PyFrame_Type;
  92. #define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
  93. #define PyFrame_IsRestricted(f) \
  94. ((f)->f_builtins != (f)->f_tstate->interp->builtins)
  95. PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
  96. PyObject *, PyObject *);
  97. /* The rest of the interface is specific for frame objects */
  98. /* Block management functions */
  99. PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
  100. PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
  101. /* Extend the value stack */
  102. PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
  103. /* Conversions between "fast locals" and locals in dictionary */
  104. PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
  105. PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
  106. PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
  107. /* Return the line of code the frame is currently executing. */
  108. PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #endif /* !Py_FRAMEOBJECT_H */