Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/internal/pycore_compile.h
12 views
1
#ifndef Py_INTERNAL_COMPILE_H
2
#define Py_INTERNAL_COMPILE_H
3
#ifdef __cplusplus
4
extern "C" {
5
#endif
6
7
#ifndef Py_BUILD_CORE
8
# error "this header requires Py_BUILD_CORE define"
9
#endif
10
11
struct _arena; // Type defined in pycore_pyarena.h
12
struct _mod; // Type defined in pycore_ast.h
13
14
// Export the symbol for test_peg_generator (built as a library)
15
PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
16
struct _mod *mod,
17
PyObject *filename,
18
PyCompilerFlags *flags,
19
int optimize,
20
struct _arena *arena);
21
22
static const _PyCompilerSrcLocation NO_LOCATION = {-1, -1, -1, -1};
23
24
extern int _PyAST_Optimize(
25
struct _mod *,
26
struct _arena *arena,
27
int optimize,
28
int ff_features);
29
30
typedef struct {
31
int h_label;
32
int h_startdepth;
33
int h_preserve_lasti;
34
} _PyCompile_ExceptHandlerInfo;
35
36
typedef struct {
37
int i_opcode;
38
int i_oparg;
39
_PyCompilerSrcLocation i_loc;
40
_PyCompile_ExceptHandlerInfo i_except_handler_info;
41
42
/* Used by the assembler */
43
int i_target;
44
int i_offset;
45
} _PyCompile_Instruction;
46
47
typedef struct {
48
_PyCompile_Instruction *s_instrs;
49
int s_allocated;
50
int s_used;
51
52
int *s_labelmap; /* label id --> instr offset */
53
int s_labelmap_size;
54
int s_next_free_label; /* next free label id */
55
} _PyCompile_InstructionSequence;
56
57
typedef struct {
58
PyObject *u_name;
59
PyObject *u_qualname; /* dot-separated qualified name (lazy) */
60
61
/* The following fields are dicts that map objects to
62
the index of them in co_XXX. The index is used as
63
the argument for opcodes that refer to those collections.
64
*/
65
PyObject *u_consts; /* all constants */
66
PyObject *u_names; /* all names */
67
PyObject *u_varnames; /* local variables */
68
PyObject *u_cellvars; /* cell variables */
69
PyObject *u_freevars; /* free variables */
70
PyObject *u_fasthidden; /* dict; keys are names that are fast-locals only
71
temporarily within an inlined comprehension. When
72
value is True, treat as fast-local. */
73
74
Py_ssize_t u_argcount; /* number of arguments for block */
75
Py_ssize_t u_posonlyargcount; /* number of positional only arguments for block */
76
Py_ssize_t u_kwonlyargcount; /* number of keyword only arguments for block */
77
78
int u_firstlineno; /* the first lineno of the block */
79
} _PyCompile_CodeUnitMetadata;
80
81
82
/* Utility for a number of growing arrays used in the compiler */
83
int _PyCompile_EnsureArrayLargeEnough(
84
int idx,
85
void **array,
86
int *alloc,
87
int default_alloc,
88
size_t item_size);
89
90
int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
91
92
/* Access compiler internals for unit testing */
93
94
PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
95
PyObject *ast,
96
PyObject *filename,
97
PyCompilerFlags *flags,
98
int optimize,
99
int compile_mode);
100
101
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
102
PyObject *instructions,
103
PyObject *consts,
104
int nlocals);
105
106
PyAPI_FUNC(PyCodeObject*)
107
_PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename,
108
PyObject *instructions);
109
110
#ifdef __cplusplus
111
}
112
#endif
113
#endif /* !Py_INTERNAL_COMPILE_H */
114
115