Mercurial > cpython-lru_cache-weakref
annotate Include/code.h @ 70987:c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
This removes nested loops in PyEval_EvalCodeEx.
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 25 Jun 2011 22:54:45 -0500 |
| parents | 3c9232a684ae |
| children |
| rev | line source |
|---|---|
| 35742 | 1 /* Definitions for bytecode */ |
| 2 | |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65348
diff
changeset
|
3 #ifndef Py_LIMITED_API |
| 35742 | 4 #ifndef Py_CODE_H |
| 5 #define Py_CODE_H | |
| 6 #ifdef __cplusplus | |
| 7 extern "C" { | |
| 8 #endif | |
| 9 | |
| 10 /* Bytecode object */ | |
| 11 typedef struct { | |
| 12 PyObject_HEAD | |
| 13 int co_argcount; /* #arguments, except *args */ | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
14 int co_kwonlyargcount; /* #keyword only arguments */ |
| 35742 | 15 int co_nlocals; /* #local variables */ |
| 16 int co_stacksize; /* #entries needed for evaluation stack */ | |
| 17 int co_flags; /* CO_..., see below */ | |
| 18 PyObject *co_code; /* instruction opcodes */ | |
| 19 PyObject *co_consts; /* list (constants used) */ | |
| 20 PyObject *co_names; /* list of strings (names used) */ | |
| 21 PyObject *co_varnames; /* tuple of strings (local variable names) */ | |
| 22 PyObject *co_freevars; /* tuple of strings (free variable names) */ | |
| 23 PyObject *co_cellvars; /* tuple of strings (cell variable names) */ | |
|
51248
410dfd423ef1
Merged revisions 69188 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
46885
diff
changeset
|
24 /* The rest doesn't count for hash or comparisons */ |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
68257
diff
changeset
|
25 unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
26 PyObject *co_filename; /* unicode (where it was loaded from) */ |
|
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
27 PyObject *co_name; /* unicode (name, for reference) */ |
| 35742 | 28 int co_firstlineno; /* first source line number */ |
|
55372
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
29 PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
30 Objects/lnotab_notes.txt for details. */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
31 void *co_zombieframe; /* for optimization only (see frameobject.c) */ |
|
59705
eea72b81a23c
Merged revisions 79060 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
55372
diff
changeset
|
32 PyObject *co_weakreflist; /* to support weakrefs to code objects */ |
| 35742 | 33 } PyCodeObject; |
| 34 | |
| 35 /* Masks for co_flags above */ | |
| 36 #define CO_OPTIMIZED 0x0001 | |
| 37 #define CO_NEWLOCALS 0x0002 | |
| 38 #define CO_VARARGS 0x0004 | |
| 39 #define CO_VARKEYWORDS 0x0008 | |
| 40 #define CO_NESTED 0x0010 | |
| 41 #define CO_GENERATOR 0x0020 | |
| 42 /* The CO_NOFREE flag is set if there are no free or cell variables. | |
| 43 This information is redundant, but it allows a single flag test | |
| 44 to determine whether there is any extra work to be done when the | |
| 45 call frame it setup. | |
| 46 */ | |
| 47 #define CO_NOFREE 0x0040 | |
|
36602
9c0fd586475c
Generators have been permanent for a while. This comment is no longer applicable.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35744
diff
changeset
|
48 |
|
55062
65e41bcbc25d
Merged revisions 73782-73784 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52641
diff
changeset
|
49 /* These are no longer used. */ |
|
36654
6b42920accc9
Per discussion on python-dev, remove CO_GENERATOR_ALLOWED. Leave comment about not removing yet.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36602
diff
changeset
|
50 #if 0 |
|
6b42920accc9
Per discussion on python-dev, remove CO_GENERATOR_ALLOWED. Leave comment about not removing yet.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36602
diff
changeset
|
51 #define CO_GENERATOR_ALLOWED 0x1000 |
|
55062
65e41bcbc25d
Merged revisions 73782-73784 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
52641
diff
changeset
|
52 #endif |
| 35742 | 53 #define CO_FUTURE_DIVISION 0x2000 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
54 #define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */ |
|
36726
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36712
diff
changeset
|
55 #define CO_FUTURE_WITH_STATEMENT 0x8000 |
|
45965
91ac8049e709
Add __future__ import for print_function. It's a no-op in 3.0, but it needs to not be a syntax error.
Eric Smith <eric@trueblade.com>
parents:
44351
diff
changeset
|
56 #define CO_FUTURE_PRINT_FUNCTION 0x10000 |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45965
diff
changeset
|
57 #define CO_FUTURE_UNICODE_LITERALS 0x20000 |
|
36726
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36712
diff
changeset
|
58 |
|
52641
0530aadff696
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents:
51248
diff
changeset
|
59 #define CO_FUTURE_BARRY_AS_BDFL 0x40000 |
|
0530aadff696
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents:
51248
diff
changeset
|
60 |
|
70987
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
68257
diff
changeset
|
61 /* This value is found in the co_cell2arg array when the associated cell |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
68257
diff
changeset
|
62 variable does not correspond to an argument. The maximum number of |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
68257
diff
changeset
|
63 arguments is 255 (indexed up to 254), so 255 work as a special flag.*/ |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
68257
diff
changeset
|
64 #define CO_CELL_NOT_AN_ARG 255 |
|
c5b0585624ef
map cells to arg slots at code creation time (closes #12399)
Benjamin Peterson <benjamin@python.org>
parents:
68257
diff
changeset
|
65 |
|
36726
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36712
diff
changeset
|
66 /* This should be defined if a future statement modifies the syntax. |
|
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36712
diff
changeset
|
67 For example, when a keyword is added. |
|
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36712
diff
changeset
|
68 */ |
|
52641
0530aadff696
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents:
51248
diff
changeset
|
69 #define PY_PARSER_REQUIRES_FUTURE_KEYWORD |
| 35742 | 70 |
| 71 #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */ | |
| 72 | |
|
35744
e7815495bb27
Use the newer names for APIs after the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
73 PyAPI_DATA(PyTypeObject) PyCode_Type; |
| 35742 | 74 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
43569
diff
changeset
|
75 #define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type) |
| 35742 | 76 #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars)) |
| 77 | |
| 78 /* Public interface */ | |
|
35744
e7815495bb27
Use the newer names for APIs after the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
79 PyAPI_FUNC(PyCodeObject *) PyCode_New( |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
80 int, int, int, int, int, PyObject *, PyObject *, |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
81 PyObject *, PyObject *, PyObject *, PyObject *, |
|
65348
453fd8182c2f
Use locale encoding if Py_FileSystemDefaultEncoding is not set
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65021
diff
changeset
|
82 PyObject *, PyObject *, int, PyObject *); |
| 35742 | 83 /* same as struct above */ |
|
55372
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
84 |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
85 /* Creates a new empty code object with the specified source location. */ |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
86 PyAPI_FUNC(PyCodeObject *) |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
87 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno); |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
88 |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
89 /* Return the line number associated with the specified bytecode index |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
90 in this code object. If you just need the line number of a frame, |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
91 use PyFrame_GetLineNumber() instead. */ |
|
35744
e7815495bb27
Use the newer names for APIs after the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
92 PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int); |
| 35742 | 93 |
| 94 /* for internal use only */ | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
95 typedef struct _addr_pair { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
96 int ap_lower; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
97 int ap_upper; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
98 } PyAddrPair; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
99 |
|
55372
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
100 /* Update *bounds to describe the first and one-past-the-last instructions in the |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
101 same line as lasti. Return the number of that line. |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
102 */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65348
diff
changeset
|
103 #ifndef Py_LIMITED_API |
|
55372
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
104 PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co, |
|
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55060
diff
changeset
|
105 int lasti, PyAddrPair *bounds); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65348
diff
changeset
|
106 #endif |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36988
diff
changeset
|
107 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
108 PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts, |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
109 PyObject *names, PyObject *lineno_obj); |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
110 |
| 35742 | 111 #ifdef __cplusplus |
| 112 } | |
| 113 #endif | |
| 114 #endif /* !Py_CODE_H */ | |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65348
diff
changeset
|
115 #endif /* Py_LIMITED_API */ |
