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