Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:45

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 #include "pycore_symtable.h"  // _Py_SourceLocation
0012 #include "pycore_instruction_sequence.h"
0013 
0014 struct _arena;   // Type defined in pycore_pyarena.h
0015 struct _mod;     // Type defined in pycore_ast.h
0016 
0017 // Export for 'test_peg_generator' shared extension
0018 PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
0019     struct _mod *mod,
0020     PyObject *filename,
0021     PyCompilerFlags *flags,
0022     int optimize,
0023     struct _arena *arena);
0024 
0025 /* AST optimizations */
0026 extern int _PyCompile_AstOptimize(
0027     struct _mod *mod,
0028     PyObject *filename,
0029     PyCompilerFlags *flags,
0030     int optimize,
0031     struct _arena *arena);
0032 
0033 struct _Py_SourceLocation;
0034 
0035 extern int _PyAST_Optimize(
0036     struct _mod *,
0037     struct _arena *arena,
0038     int optimize,
0039     int ff_features);
0040 
0041 
0042 typedef struct {
0043     PyObject *u_name;
0044     PyObject *u_qualname;  /* dot-separated qualified name (lazy) */
0045 
0046     /* The following fields are dicts that map objects to
0047        the index of them in co_XXX.      The index is used as
0048        the argument for opcodes that refer to those collections.
0049     */
0050     PyObject *u_consts;    /* all constants */
0051     PyObject *u_names;     /* all names */
0052     PyObject *u_varnames;  /* local variables */
0053     PyObject *u_cellvars;  /* cell variables */
0054     PyObject *u_freevars;  /* free variables */
0055     PyObject *u_fasthidden; /* dict; keys are names that are fast-locals only
0056                                temporarily within an inlined comprehension. When
0057                                value is True, treat as fast-local. */
0058 
0059     Py_ssize_t u_argcount;        /* number of arguments for block */
0060     Py_ssize_t u_posonlyargcount;        /* number of positional only arguments for block */
0061     Py_ssize_t u_kwonlyargcount; /* number of keyword only arguments for block */
0062 
0063     int u_firstlineno; /* the first lineno of the block */
0064 } _PyCompile_CodeUnitMetadata;
0065 
0066 
0067 /* Utility for a number of growing arrays used in the compiler */
0068 int _PyCompile_EnsureArrayLargeEnough(
0069         int idx,
0070         void **array,
0071         int *alloc,
0072         int default_alloc,
0073         size_t item_size);
0074 
0075 int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
0076 
0077 
0078 // Export for '_opcode' extension module
0079 PyAPI_FUNC(int) _PyCompile_OpcodeIsValid(int opcode);
0080 PyAPI_FUNC(int) _PyCompile_OpcodeHasArg(int opcode);
0081 PyAPI_FUNC(int) _PyCompile_OpcodeHasConst(int opcode);
0082 PyAPI_FUNC(int) _PyCompile_OpcodeHasName(int opcode);
0083 PyAPI_FUNC(int) _PyCompile_OpcodeHasJump(int opcode);
0084 PyAPI_FUNC(int) _PyCompile_OpcodeHasFree(int opcode);
0085 PyAPI_FUNC(int) _PyCompile_OpcodeHasLocal(int opcode);
0086 PyAPI_FUNC(int) _PyCompile_OpcodeHasExc(int opcode);
0087 
0088 PyAPI_FUNC(PyObject*) _PyCompile_GetUnaryIntrinsicName(int index);
0089 PyAPI_FUNC(PyObject*) _PyCompile_GetBinaryIntrinsicName(int index);
0090 
0091 /* Access compiler internals for unit testing */
0092 
0093 // Export for '_testinternalcapi' shared extension
0094 PyAPI_FUNC(PyObject*) _PyCompile_CleanDoc(PyObject *doc);
0095 
0096 // Export for '_testinternalcapi' shared extension
0097 PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
0098         PyObject *ast,
0099         PyObject *filename,
0100         PyCompilerFlags *flags,
0101         int optimize,
0102         int compile_mode);
0103 
0104 // Export for '_testinternalcapi' shared extension
0105 PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
0106         PyObject *instructions,
0107         PyObject *consts,
0108         int nlocals);
0109 
0110 // Export for '_testinternalcapi' shared extension
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 */