annotate Include/code.h @ 65105:8bcbdd6730a7

#10034: import readline in longer example.
author Georg Brandl <georg@python.org>
date Wed, 06 Oct 2010 05:08:32 +0000
parents 01b96f78fb70
children 453fd8182c2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1 /* Definitions for bytecode */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
3 #ifndef Py_CODE_H
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
4 #define Py_CODE_H
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
5 #ifdef __cplusplus
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6 extern "C" {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
7 #endif
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
8
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
9 /* Bytecode object */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
10 typedef struct {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11 PyObject_HEAD
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 int co_argcount; /* #arguments, except *args */
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
13 int co_kwonlyargcount; /* #keyword only arguments */
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14 int co_nlocals; /* #local variables */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
15 int co_stacksize; /* #entries needed for evaluation stack */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
16 int co_flags; /* CO_..., see below */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
17 PyObject *co_code; /* instruction opcodes */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18 PyObject *co_consts; /* list (constants used) */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 PyObject *co_names; /* list of strings (names used) */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20 PyObject *co_varnames; /* tuple of strings (local variable names) */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
21 PyObject *co_freevars; /* tuple of strings (free variable names) */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
22 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
23 /* The rest doesn't count for hash or comparisons */
43569
19319e70fc3e Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents: 42334
diff changeset
24 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
25 PyObject *co_name; /* unicode (name, for reference) */
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
26 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
27 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
28 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
29 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
30 PyObject *co_weakreflist; /* to support weakrefs to code objects */
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
31 } PyCodeObject;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
32
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
33 /* Masks for co_flags above */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
34 #define CO_OPTIMIZED 0x0001
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
35 #define CO_NEWLOCALS 0x0002
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
36 #define CO_VARARGS 0x0004
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
37 #define CO_VARKEYWORDS 0x0008
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
38 #define CO_NESTED 0x0010
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
39 #define CO_GENERATOR 0x0020
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
40 /* The CO_NOFREE flag is set if there are no free or cell variables.
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
41 This information is redundant, but it allows a single flag test
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
42 to determine whether there is any extra work to be done when the
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
43 call frame it setup.
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
44 */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
45 #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
46
36988
49c6eb688906 Checkpoint. 218 tests are okay; 53 are failing. Done so far:
Guido van Rossum <guido@python.org>
parents: 36726
diff changeset
47 /* These are no longer used. */
55060
cc6b91c3d719 a little more fiddling to make flags like 2.x
Benjamin Peterson <benjamin@python.org>
parents: 55059
diff changeset
48 #if 0
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
49 #define CO_GENERATOR_ALLOWED 0x1000
55060
cc6b91c3d719 a little more fiddling to make flags like 2.x
Benjamin Peterson <benjamin@python.org>
parents: 55059
diff changeset
50 #endif
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
51 #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
52 #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
53 #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
54 #define CO_FUTURE_PRINT_FUNCTION 0x10000
46120
78504d604b44 Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45965
diff changeset
55 #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
56
52641
0530aadff696 The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents: 51248
diff changeset
57 #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
58
36726
bbf16fd024df from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents: 36712
diff changeset
59 /* 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
60 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
61 */
52641
0530aadff696 The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents: 51248
diff changeset
62 #define PY_PARSER_REQUIRES_FUTURE_KEYWORD
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
63
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
64 #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
65
35744
e7815495bb27 Use the newer names for APIs after the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents: 35742
diff changeset
66 PyAPI_DATA(PyTypeObject) PyCode_Type;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
67
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
68 #define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
69 #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
70
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
71 /* Public interface */
35744
e7815495bb27 Use the newer names for APIs after the AST merge
Neal Norwitz <nnorwitz@gmail.com>
parents: 35742
diff changeset
72 PyAPI_FUNC(PyCodeObject *) PyCode_New(
40215
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
73 int, int, int, int, int, PyObject *, PyObject *,
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
74 PyObject *, PyObject *, PyObject *, PyObject *,
1cce0526d9b0 Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents: 39610
diff changeset
75 PyObject *, PyObject *, int, PyObject *);
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
76 /* same as struct above */
55372
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55060
diff changeset
77
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55060
diff changeset
78 /* 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
79 PyAPI_FUNC(PyCodeObject *)
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55060
diff changeset
80 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
81
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55060
diff changeset
82 /* 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
83 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
84 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
85 PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
86
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
87 /* 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
88 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
89 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
90 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
91 } 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
92
55372
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55060
diff changeset
93 /* 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
94 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
95 */
55372
79718ee03986 Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55060
diff changeset
96 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
97 int lasti, PyAddrPair *bounds);
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
98
39610
3674f20ac781 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents: 38453
diff changeset
99 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
100 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
101
65021
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
102 /* List of weak references to all code objects. The list is used by
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
103 initfsencoding() to redecode code filenames at startup if the filesystem
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
104 encoding changes. At initfsencoding() exit, the list is set to NULL and it
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
105 is no more used. */
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
106
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
107 extern PyObject *_Py_code_object_list;
01b96f78fb70 Issue #9630: Redecode filenames when setting the filesystem encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59705
diff changeset
108
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
109 #ifdef __cplusplus
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
110 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
111 #endif
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
112 #endif /* !Py_CODE_H */