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;
0012 struct _mod;
0013
0014
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;
0029 int 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;
0056 int s_labelmap_size;
0057 int s_next_free_label;
0058 } _PyCompile_InstructionSequence;
0059
0060 typedef struct {
0061 PyObject *u_name;
0062 PyObject *u_qualname;
0063
0064
0065
0066
0067
0068 PyObject *u_consts;
0069 PyObject *u_names;
0070 PyObject *u_varnames;
0071 PyObject *u_cellvars;
0072 PyObject *u_freevars;
0073 PyObject *u_fasthidden;
0074
0075
0076
0077 Py_ssize_t u_argcount;
0078 Py_ssize_t u_posonlyargcount;
0079 Py_ssize_t u_kwonlyargcount;
0080
0081 int u_firstlineno;
0082 } _PyCompile_CodeUnitMetadata;
0083
0084
0085
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
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