1#include "Python.h"
2#include "opcode.h"
3
4/*[clinic input]
5module _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
19Compute the stack effect of the opcode.
20[clinic start generated code]*/
21
22static int
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
55static PyMethodDef
56opcode_functions[] =  {
57    _OPCODE_STACK_EFFECT_METHODDEF
58    {NULL, NULL, 0, NULL}
59};
60
61
62static 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
74PyMODINIT_FUNC
75PyInit__opcode(void)
76{
77    return PyModule_Create(&opcodemodule);
78}
79