Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:43

0001 #ifndef Py_INTERNAL_COMPILE_H
0002 #define Py_INTERNAL_COMPILE_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "this header requires Py_BUILD_CORE define"
0009 #endif
0010 
0011 struct _arena;   // Type defined in pycore_pyarena.h
0012 struct _mod;     // Type defined in pycore_ast.h
0013 
0014 // Export the symbol for test_peg_generator (built as a library)
0015 PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
0016     struct _mod *mod,
0017     PyObject *filename,
0018     PyCompilerFlags *flags,
0019     int optimize,
0020     struct _arena *arena);
0021 
0022 static const _PyCompilerSrcLocation NO_LOCATION = {-1, -1, -1, -1};
0023 
0024 typedef struct {
0025     int optimize;
0026     int ff_features;
0027 
0028     int recursion_depth;            /* current recursion depth */
0029     int recursion_limit;            /* recursion limit */
0030 } _PyASTOptimizeState;
0031 
0032 extern int _PyAST_Optimize(
0033     struct _mod *,
0034     struct _arena *arena,
0035     _PyASTOptimizeState *state);
0036 
0037 typedef struct {
0038     int h_offset;
0039     int h_startdepth;
0040     int h_preserve_lasti;
0041 } _PyCompile_ExceptHandlerInfo;
0042 
0043 typedef struct {
0044     int i_opcode;
0045     int i_oparg;
0046     _PyCompilerSrcLocation i_loc;
0047     _PyCompile_ExceptHandlerInfo i_except_handler_info;
0048 } _PyCompile_Instruction;
0049 
0050 typedef struct {
0051     _PyCompile_Instruction *s_instrs;
0052     int s_allocated;
0053     int s_used;
0054 
0055     int *s_labelmap;       /* label id --> instr offset */
0056     int s_labelmap_size;
0057     int s_next_free_label; /* next free label id */
0058 } _PyCompile_InstructionSequence;
0059 
0060 typedef struct {
0061     PyObject *u_name;
0062     PyObject *u_qualname;  /* dot-separated qualified name (lazy) */
0063 
0064     /* The following fields are dicts that map objects to
0065        the index of them in co_XXX.      The index is used as
0066        the argument for opcodes that refer to those collections.
0067     */
0068     PyObject *u_consts;    /* all constants */
0069     PyObject *u_names;     /* all names */
0070     PyObject *u_varnames;  /* local variables */
0071     PyObject *u_cellvars;  /* cell variables */
0072     PyObject *u_freevars;  /* free variables */
0073     PyObject *u_fasthidden; /* dict; keys are names that are fast-locals only
0074                                temporarily within an inlined comprehension. When
0075                                value is True, treat as fast-local. */
0076 
0077     Py_ssize_t u_argcount;        /* number of arguments for block */
0078     Py_ssize_t u_posonlyargcount;        /* number of positional only arguments for block */
0079     Py_ssize_t u_kwonlyargcount; /* number of keyword only arguments for block */
0080 
0081     int u_firstlineno; /* the first lineno of the block */
0082 } _PyCompile_CodeUnitMetadata;
0083 
0084 
0085 /* Utility for a number of growing arrays used in the compiler */
0086 int _PyCompile_EnsureArrayLargeEnough(
0087         int idx,
0088         void **array,
0089         int *alloc,
0090         int default_alloc,
0091         size_t item_size);
0092 
0093 int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
0094 
0095 int _PyCompile_InstrSize(int opcode, int oparg);
0096 
0097 /* Access compiler internals for unit testing */
0098 
0099 PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
0100         PyObject *ast,
0101         PyObject *filename,
0102         PyCompilerFlags *flags,
0103         int optimize,
0104         int compile_mode);
0105 
0106 PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
0107         PyObject *instructions,
0108         PyObject *consts,
0109         int nlocals);
0110 
0111 PyAPI_FUNC(PyCodeObject*)
0112 _PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename,
0113                     PyObject *instructions);
0114 
0115 #ifdef __cplusplus
0116 }
0117 #endif
0118 #endif /* !Py_INTERNAL_COMPILE_H */