Chris@87: /* Definitions for bytecode */ Chris@87: Chris@87: #ifndef Py_CODE_H Chris@87: #define Py_CODE_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: /* Bytecode object */ Chris@87: typedef struct { Chris@87: PyObject_HEAD Chris@87: int co_argcount; /* #arguments, except *args */ Chris@87: int co_nlocals; /* #local variables */ Chris@87: int co_stacksize; /* #entries needed for evaluation stack */ Chris@87: int co_flags; /* CO_..., see below */ Chris@87: PyObject *co_code; /* instruction opcodes */ Chris@87: PyObject *co_consts; /* list (constants used) */ Chris@87: PyObject *co_names; /* list of strings (names used) */ Chris@87: PyObject *co_varnames; /* tuple of strings (local variable names) */ Chris@87: PyObject *co_freevars; /* tuple of strings (free variable names) */ Chris@87: PyObject *co_cellvars; /* tuple of strings (cell variable names) */ Chris@87: /* The rest doesn't count for hash/cmp */ Chris@87: PyObject *co_filename; /* string (where it was loaded from) */ Chris@87: PyObject *co_name; /* string (name, for reference) */ Chris@87: int co_firstlineno; /* first source line number */ Chris@87: PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See Chris@87: Objects/lnotab_notes.txt for details. */ Chris@87: void *co_zombieframe; /* for optimization only (see frameobject.c) */ Chris@87: PyObject *co_weakreflist; /* to support weakrefs to code objects */ Chris@87: } PyCodeObject; Chris@87: Chris@87: /* Masks for co_flags above */ Chris@87: #define CO_OPTIMIZED 0x0001 Chris@87: #define CO_NEWLOCALS 0x0002 Chris@87: #define CO_VARARGS 0x0004 Chris@87: #define CO_VARKEYWORDS 0x0008 Chris@87: #define CO_NESTED 0x0010 Chris@87: #define CO_GENERATOR 0x0020 Chris@87: /* The CO_NOFREE flag is set if there are no free or cell variables. Chris@87: This information is redundant, but it allows a single flag test Chris@87: to determine whether there is any extra work to be done when the Chris@87: call frame it setup. Chris@87: */ Chris@87: #define CO_NOFREE 0x0040 Chris@87: Chris@87: #if 0 Chris@87: /* This is no longer used. Stopped defining in 2.5, do not re-use. */ Chris@87: #define CO_GENERATOR_ALLOWED 0x1000 Chris@87: #endif Chris@87: #define CO_FUTURE_DIVISION 0x2000 Chris@87: #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */ Chris@87: #define CO_FUTURE_WITH_STATEMENT 0x8000 Chris@87: #define CO_FUTURE_PRINT_FUNCTION 0x10000 Chris@87: #define CO_FUTURE_UNICODE_LITERALS 0x20000 Chris@87: Chris@87: /* This should be defined if a future statement modifies the syntax. Chris@87: For example, when a keyword is added. Chris@87: */ Chris@87: #if 1 Chris@87: #define PY_PARSER_REQUIRES_FUTURE_KEYWORD Chris@87: #endif Chris@87: Chris@87: #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */ Chris@87: Chris@87: PyAPI_DATA(PyTypeObject) PyCode_Type; Chris@87: Chris@87: #define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type) Chris@87: #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars)) Chris@87: Chris@87: /* Public interface */ Chris@87: PyAPI_FUNC(PyCodeObject *) PyCode_New( Chris@87: int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *, Chris@87: PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *); Chris@87: /* same as struct above */ Chris@87: Chris@87: /* Creates a new empty code object with the specified source location. */ Chris@87: PyAPI_FUNC(PyCodeObject *) Chris@87: PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno); Chris@87: Chris@87: /* Return the line number associated with the specified bytecode index Chris@87: in this code object. If you just need the line number of a frame, Chris@87: use PyFrame_GetLineNumber() instead. */ Chris@87: PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int); Chris@87: Chris@87: /* for internal use only */ Chris@87: #define _PyCode_GETCODEPTR(co, pp) \ Chris@87: ((*Py_TYPE((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \ Chris@87: ((co)->co_code, 0, (void **)(pp))) Chris@87: Chris@87: typedef struct _addr_pair { Chris@87: int ap_lower; Chris@87: int ap_upper; Chris@87: } PyAddrPair; Chris@87: Chris@87: /* Update *bounds to describe the first and one-past-the-last instructions in the Chris@87: same line as lasti. Return the number of that line. Chris@87: */ Chris@87: PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co, Chris@87: int lasti, PyAddrPair *bounds); Chris@87: Chris@87: PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts, Chris@87: PyObject *names, PyObject *lineno_obj); Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_CODE_H */