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