(root)/
Python-3.12.0/
Modules/
clinic/
_testinternalcapi.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6  #  include "pycore_gc.h"            // PyGC_Head
       7  #  include "pycore_runtime.h"       // _Py_ID()
       8  #endif
       9  
      10  
      11  PyDoc_STRVAR(_testinternalcapi_compiler_codegen__doc__,
      12  "compiler_codegen($module, /, ast, filename, optimize, compile_mode=0)\n"
      13  "--\n"
      14  "\n"
      15  "Apply compiler code generation to an AST.");
      16  
      17  #define _TESTINTERNALCAPI_COMPILER_CODEGEN_METHODDEF    \
      18      {"compiler_codegen", _PyCFunction_CAST(_testinternalcapi_compiler_codegen), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_compiler_codegen__doc__},
      19  
      20  static PyObject *
      21  _testinternalcapi_compiler_codegen_impl(PyObject *module, PyObject *ast,
      22                                          PyObject *filename, int optimize,
      23                                          int compile_mode);
      24  
      25  static PyObject *
      26  _testinternalcapi_compiler_codegen(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      27  {
      28      PyObject *return_value = NULL;
      29      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      30  
      31      #define NUM_KEYWORDS 4
      32      static struct {
      33          PyGC_Head _this_is_not_used;
      34          PyObject_VAR_HEAD
      35          PyObject *ob_item[NUM_KEYWORDS];
      36      } _kwtuple = {
      37          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
      38          .ob_item = { &_Py_ID(ast), &_Py_ID(filename), &_Py_ID(optimize), &_Py_ID(compile_mode), },
      39      };
      40      #undef NUM_KEYWORDS
      41      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
      42  
      43      #else  // !Py_BUILD_CORE
      44      #  define KWTUPLE NULL
      45      #endif  // !Py_BUILD_CORE
      46  
      47      static const char * const _keywords[] = {"ast", "filename", "optimize", "compile_mode", NULL};
      48      static _PyArg_Parser _parser = {
      49          .keywords = _keywords,
      50          .fname = "compiler_codegen",
      51          .kwtuple = KWTUPLE,
      52      };
      53      #undef KWTUPLE
      54      PyObject *argsbuf[4];
      55      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
      56      PyObject *ast;
      57      PyObject *filename;
      58      int optimize;
      59      int compile_mode = 0;
      60  
      61      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
      62      if (!args) {
      63          goto exit;
      64      }
      65      ast = args[0];
      66      filename = args[1];
      67      optimize = _PyLong_AsInt(args[2]);
      68      if (optimize == -1 && PyErr_Occurred()) {
      69          goto exit;
      70      }
      71      if (!noptargs) {
      72          goto skip_optional_pos;
      73      }
      74      compile_mode = _PyLong_AsInt(args[3]);
      75      if (compile_mode == -1 && PyErr_Occurred()) {
      76          goto exit;
      77      }
      78  skip_optional_pos:
      79      return_value = _testinternalcapi_compiler_codegen_impl(module, ast, filename, optimize, compile_mode);
      80  
      81  exit:
      82      return return_value;
      83  }
      84  
      85  PyDoc_STRVAR(_testinternalcapi_optimize_cfg__doc__,
      86  "optimize_cfg($module, /, instructions, consts, nlocals)\n"
      87  "--\n"
      88  "\n"
      89  "Apply compiler optimizations to an instruction list.");
      90  
      91  #define _TESTINTERNALCAPI_OPTIMIZE_CFG_METHODDEF    \
      92      {"optimize_cfg", _PyCFunction_CAST(_testinternalcapi_optimize_cfg), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_optimize_cfg__doc__},
      93  
      94  static PyObject *
      95  _testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions,
      96                                      PyObject *consts, int nlocals);
      97  
      98  static PyObject *
      99  _testinternalcapi_optimize_cfg(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     100  {
     101      PyObject *return_value = NULL;
     102      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     103  
     104      #define NUM_KEYWORDS 3
     105      static struct {
     106          PyGC_Head _this_is_not_used;
     107          PyObject_VAR_HEAD
     108          PyObject *ob_item[NUM_KEYWORDS];
     109      } _kwtuple = {
     110          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     111          .ob_item = { &_Py_ID(instructions), &_Py_ID(consts), &_Py_ID(nlocals), },
     112      };
     113      #undef NUM_KEYWORDS
     114      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     115  
     116      #else  // !Py_BUILD_CORE
     117      #  define KWTUPLE NULL
     118      #endif  // !Py_BUILD_CORE
     119  
     120      static const char * const _keywords[] = {"instructions", "consts", "nlocals", NULL};
     121      static _PyArg_Parser _parser = {
     122          .keywords = _keywords,
     123          .fname = "optimize_cfg",
     124          .kwtuple = KWTUPLE,
     125      };
     126      #undef KWTUPLE
     127      PyObject *argsbuf[3];
     128      PyObject *instructions;
     129      PyObject *consts;
     130      int nlocals;
     131  
     132      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
     133      if (!args) {
     134          goto exit;
     135      }
     136      instructions = args[0];
     137      consts = args[1];
     138      nlocals = _PyLong_AsInt(args[2]);
     139      if (nlocals == -1 && PyErr_Occurred()) {
     140          goto exit;
     141      }
     142      return_value = _testinternalcapi_optimize_cfg_impl(module, instructions, consts, nlocals);
     143  
     144  exit:
     145      return return_value;
     146  }
     147  
     148  PyDoc_STRVAR(_testinternalcapi_assemble_code_object__doc__,
     149  "assemble_code_object($module, /, filename, instructions, metadata)\n"
     150  "--\n"
     151  "\n"
     152  "Create a code object for the given instructions.");
     153  
     154  #define _TESTINTERNALCAPI_ASSEMBLE_CODE_OBJECT_METHODDEF    \
     155      {"assemble_code_object", _PyCFunction_CAST(_testinternalcapi_assemble_code_object), METH_FASTCALL|METH_KEYWORDS, _testinternalcapi_assemble_code_object__doc__},
     156  
     157  static PyObject *
     158  _testinternalcapi_assemble_code_object_impl(PyObject *module,
     159                                              PyObject *filename,
     160                                              PyObject *instructions,
     161                                              PyObject *metadata);
     162  
     163  static PyObject *
     164  _testinternalcapi_assemble_code_object(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     165  {
     166      PyObject *return_value = NULL;
     167      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     168  
     169      #define NUM_KEYWORDS 3
     170      static struct {
     171          PyGC_Head _this_is_not_used;
     172          PyObject_VAR_HEAD
     173          PyObject *ob_item[NUM_KEYWORDS];
     174      } _kwtuple = {
     175          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     176          .ob_item = { &_Py_ID(filename), &_Py_ID(instructions), &_Py_ID(metadata), },
     177      };
     178      #undef NUM_KEYWORDS
     179      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     180  
     181      #else  // !Py_BUILD_CORE
     182      #  define KWTUPLE NULL
     183      #endif  // !Py_BUILD_CORE
     184  
     185      static const char * const _keywords[] = {"filename", "instructions", "metadata", NULL};
     186      static _PyArg_Parser _parser = {
     187          .keywords = _keywords,
     188          .fname = "assemble_code_object",
     189          .kwtuple = KWTUPLE,
     190      };
     191      #undef KWTUPLE
     192      PyObject *argsbuf[3];
     193      PyObject *filename;
     194      PyObject *instructions;
     195      PyObject *metadata;
     196  
     197      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
     198      if (!args) {
     199          goto exit;
     200      }
     201      filename = args[0];
     202      instructions = args[1];
     203      metadata = args[2];
     204      return_value = _testinternalcapi_assemble_code_object_impl(module, filename, instructions, metadata);
     205  
     206  exit:
     207      return return_value;
     208  }
     209  /*[clinic end generated code: output=2965f1578b986218 input=a9049054013a1b77]*/