Chris@87
|
1 /* Definitions for bytecode */
|
Chris@87
|
2
|
Chris@87
|
3 #ifndef Py_CODE_H
|
Chris@87
|
4 #define Py_CODE_H
|
Chris@87
|
5 #ifdef __cplusplus
|
Chris@87
|
6 extern "C" {
|
Chris@87
|
7 #endif
|
Chris@87
|
8
|
Chris@87
|
9 /* Bytecode object */
|
Chris@87
|
10 typedef struct {
|
Chris@87
|
11 PyObject_HEAD
|
Chris@87
|
12 int co_argcount; /* #arguments, except *args */
|
Chris@87
|
13 int co_nlocals; /* #local variables */
|
Chris@87
|
14 int co_stacksize; /* #entries needed for evaluation stack */
|
Chris@87
|
15 int co_flags; /* CO_..., see below */
|
Chris@87
|
16 PyObject *co_code; /* instruction opcodes */
|
Chris@87
|
17 PyObject *co_consts; /* list (constants used) */
|
Chris@87
|
18 PyObject *co_names; /* list of strings (names used) */
|
Chris@87
|
19 PyObject *co_varnames; /* tuple of strings (local variable names) */
|
Chris@87
|
20 PyObject *co_freevars; /* tuple of strings (free variable names) */
|
Chris@87
|
21 PyObject *co_cellvars; /* tuple of strings (cell variable names) */
|
Chris@87
|
22 /* The rest doesn't count for hash/cmp */
|
Chris@87
|
23 PyObject *co_filename; /* string (where it was loaded from) */
|
Chris@87
|
24 PyObject *co_name; /* string (name, for reference) */
|
Chris@87
|
25 int co_firstlineno; /* first source line number */
|
Chris@87
|
26 PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See
|
Chris@87
|
27 Objects/lnotab_notes.txt for details. */
|
Chris@87
|
28 void *co_zombieframe; /* for optimization only (see frameobject.c) */
|
Chris@87
|
29 PyObject *co_weakreflist; /* to support weakrefs to code objects */
|
Chris@87
|
30 } PyCodeObject;
|
Chris@87
|
31
|
Chris@87
|
32 /* Masks for co_flags above */
|
Chris@87
|
33 #define CO_OPTIMIZED 0x0001
|
Chris@87
|
34 #define CO_NEWLOCALS 0x0002
|
Chris@87
|
35 #define CO_VARARGS 0x0004
|
Chris@87
|
36 #define CO_VARKEYWORDS 0x0008
|
Chris@87
|
37 #define CO_NESTED 0x0010
|
Chris@87
|
38 #define CO_GENERATOR 0x0020
|
Chris@87
|
39 /* The CO_NOFREE flag is set if there are no free or cell variables.
|
Chris@87
|
40 This information is redundant, but it allows a single flag test
|
Chris@87
|
41 to determine whether there is any extra work to be done when the
|
Chris@87
|
42 call frame it setup.
|
Chris@87
|
43 */
|
Chris@87
|
44 #define CO_NOFREE 0x0040
|
Chris@87
|
45
|
Chris@87
|
46 #if 0
|
Chris@87
|
47 /* This is no longer used. Stopped defining in 2.5, do not re-use. */
|
Chris@87
|
48 #define CO_GENERATOR_ALLOWED 0x1000
|
Chris@87
|
49 #endif
|
Chris@87
|
50 #define CO_FUTURE_DIVISION 0x2000
|
Chris@87
|
51 #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */
|
Chris@87
|
52 #define CO_FUTURE_WITH_STATEMENT 0x8000
|
Chris@87
|
53 #define CO_FUTURE_PRINT_FUNCTION 0x10000
|
Chris@87
|
54 #define CO_FUTURE_UNICODE_LITERALS 0x20000
|
Chris@87
|
55
|
Chris@87
|
56 /* This should be defined if a future statement modifies the syntax.
|
Chris@87
|
57 For example, when a keyword is added.
|
Chris@87
|
58 */
|
Chris@87
|
59 #if 1
|
Chris@87
|
60 #define PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
Chris@87
|
61 #endif
|
Chris@87
|
62
|
Chris@87
|
63 #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
|
Chris@87
|
64
|
Chris@87
|
65 PyAPI_DATA(PyTypeObject) PyCode_Type;
|
Chris@87
|
66
|
Chris@87
|
67 #define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
|
Chris@87
|
68 #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
|
Chris@87
|
69
|
Chris@87
|
70 /* Public interface */
|
Chris@87
|
71 PyAPI_FUNC(PyCodeObject *) PyCode_New(
|
Chris@87
|
72 int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
|
Chris@87
|
73 PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
|
Chris@87
|
74 /* same as struct above */
|
Chris@87
|
75
|
Chris@87
|
76 /* Creates a new empty code object with the specified source location. */
|
Chris@87
|
77 PyAPI_FUNC(PyCodeObject *)
|
Chris@87
|
78 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
|
Chris@87
|
79
|
Chris@87
|
80 /* Return the line number associated with the specified bytecode index
|
Chris@87
|
81 in this code object. If you just need the line number of a frame,
|
Chris@87
|
82 use PyFrame_GetLineNumber() instead. */
|
Chris@87
|
83 PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
|
Chris@87
|
84
|
Chris@87
|
85 /* for internal use only */
|
Chris@87
|
86 #define _PyCode_GETCODEPTR(co, pp) \
|
Chris@87
|
87 ((*Py_TYPE((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \
|
Chris@87
|
88 ((co)->co_code, 0, (void **)(pp)))
|
Chris@87
|
89
|
Chris@87
|
90 typedef struct _addr_pair {
|
Chris@87
|
91 int ap_lower;
|
Chris@87
|
92 int ap_upper;
|
Chris@87
|
93 } PyAddrPair;
|
Chris@87
|
94
|
Chris@87
|
95 /* Update *bounds to describe the first and one-past-the-last instructions in the
|
Chris@87
|
96 same line as lasti. Return the number of that line.
|
Chris@87
|
97 */
|
Chris@87
|
98 PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
|
Chris@87
|
99 int lasti, PyAddrPair *bounds);
|
Chris@87
|
100
|
Chris@87
|
101 PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
|
Chris@87
|
102 PyObject *names, PyObject *lineno_obj);
|
Chris@87
|
103
|
Chris@87
|
104 #ifdef __cplusplus
|
Chris@87
|
105 }
|
Chris@87
|
106 #endif
|
Chris@87
|
107 #endif /* !Py_CODE_H */
|