You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

  1. #include "Python.h"
  2. #include "opcode.h"
  3. /*[clinic input]
  4. module _opcode
  5. [clinic start generated code]*/
  6. /*[clinic end generated code: output=da39a3ee5e6b4b0d input=117442e66eb376e6]*/
  7. #include "clinic/_opcode.c.h"
  8. /*[clinic input]
  9. _opcode.stack_effect -> int
  10. opcode: int
  11. oparg: object = None
  12. /
  13. Compute the stack effect of the opcode.
  14. [clinic start generated code]*/
  15. static int
  16. _opcode_stack_effect_impl(PyModuleDef *module, int opcode, PyObject *oparg)
  17. /*[clinic end generated code: output=1fcafd5596c6b050 input=2d0a9ee53c0418f5]*/
  18. {
  19. int effect;
  20. int oparg_int = 0;
  21. if (HAS_ARG(opcode)) {
  22. if (oparg == Py_None) {
  23. PyErr_SetString(PyExc_ValueError,
  24. "stack_effect: opcode requires oparg but oparg was not specified");
  25. return -1;
  26. }
  27. oparg_int = (int)PyLong_AsLong(oparg);
  28. if ((oparg_int == -1) && PyErr_Occurred())
  29. return -1;
  30. }
  31. else if (oparg != Py_None) {
  32. PyErr_SetString(PyExc_ValueError,
  33. "stack_effect: opcode does not permit oparg but oparg was specified");
  34. return -1;
  35. }
  36. effect = PyCompile_OpcodeStackEffect(opcode, oparg_int);
  37. if (effect == PY_INVALID_STACK_EFFECT) {
  38. PyErr_SetString(PyExc_ValueError,
  39. "invalid opcode or oparg");
  40. return -1;
  41. }
  42. return effect;
  43. }
  44. static PyMethodDef
  45. opcode_functions[] = {
  46. _OPCODE_STACK_EFFECT_METHODDEF
  47. {NULL, NULL, 0, NULL}
  48. };
  49. static struct PyModuleDef opcodemodule = {
  50. PyModuleDef_HEAD_INIT,
  51. "_opcode",
  52. "Opcode support module.",
  53. -1,
  54. opcode_functions,
  55. NULL,
  56. NULL,
  57. NULL,
  58. NULL
  59. };
  60. PyMODINIT_FUNC
  61. PyInit__opcode(void)
  62. {
  63. return PyModule_Create(&opcodemodule);
  64. }