2013-11-23 23:49:22 +01:00
|
|
|
#include "Python.h"
|
|
|
|
#include "opcode.h"
|
|
|
|
|
2014-01-07 21:41:53 +01:00
|
|
|
/*[clinic input]
|
2013-11-23 23:49:22 +01:00
|
|
|
module _opcode
|
2014-01-07 21:41:53 +01:00
|
|
|
[clinic start generated code]*/
|
|
|
|
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
|
2013-11-24 00:37:55 +01:00
|
|
|
|
2014-01-07 21:41:53 +01:00
|
|
|
/*[clinic input]
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
_opcode.stack_effect -> int
|
|
|
|
|
|
|
|
opcode: int
|
|
|
|
|
|
|
|
[
|
|
|
|
oparg: int
|
|
|
|
]
|
|
|
|
/
|
|
|
|
|
|
|
|
Compute the stack effect of the opcode.
|
2014-01-07 21:41:53 +01:00
|
|
|
[clinic start generated code]*/
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
PyDoc_STRVAR(_opcode_stack_effect__doc__,
|
2014-01-24 15:17:25 +01:00
|
|
|
"stack_effect(module, opcode, [oparg])\n"
|
2013-11-24 00:37:55 +01:00
|
|
|
"Compute the stack effect of the opcode.");
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
#define _OPCODE_STACK_EFFECT_METHODDEF \
|
|
|
|
{"stack_effect", (PyCFunction)_opcode_stack_effect, METH_VARARGS, _opcode_stack_effect__doc__},
|
|
|
|
|
|
|
|
static int
|
2013-11-24 00:37:55 +01:00
|
|
|
_opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg);
|
2013-11-23 23:49:22 +01:00
|
|
|
|
|
|
|
static PyObject *
|
2013-11-24 00:37:55 +01:00
|
|
|
_opcode_stack_effect(PyModuleDef *module, PyObject *args)
|
2013-11-23 23:49:22 +01:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int opcode;
|
|
|
|
int group_right_1 = 0;
|
|
|
|
int oparg = 0;
|
|
|
|
int _return_value;
|
|
|
|
|
2014-01-16 20:32:01 +01:00
|
|
|
switch (PyTuple_GET_SIZE(args)) {
|
2013-11-23 23:49:22 +01:00
|
|
|
case 1:
|
|
|
|
if (!PyArg_ParseTuple(args, "i:stack_effect", &opcode))
|
2014-01-22 12:05:49 +01:00
|
|
|
goto exit;
|
2013-11-23 23:49:22 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (!PyArg_ParseTuple(args, "ii:stack_effect", &opcode, &oparg))
|
2014-01-22 12:05:49 +01:00
|
|
|
goto exit;
|
2013-11-23 23:49:22 +01:00
|
|
|
group_right_1 = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_SetString(PyExc_TypeError, "_opcode.stack_effect requires 1 to 2 arguments");
|
2014-01-22 12:05:49 +01:00
|
|
|
goto exit;
|
2013-11-23 23:49:22 +01:00
|
|
|
}
|
|
|
|
_return_value = _opcode_stack_effect_impl(module, opcode, group_right_1, oparg);
|
|
|
|
if ((_return_value == -1) && PyErr_Occurred())
|
|
|
|
goto exit;
|
|
|
|
return_value = PyLong_FromLong((long)_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-11-24 00:37:55 +01:00
|
|
|
_opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg)
|
2014-01-24 15:17:25 +01:00
|
|
|
/*[clinic end generated code: checksum=4689140ffda2494a123ea2593fb63445fb039774]*/
|
2013-11-23 23:49:22 +01:00
|
|
|
{
|
|
|
|
int effect;
|
2014-01-07 21:41:53 +01:00
|
|
|
if (HAS_ARG(opcode)) {
|
2013-11-23 23:49:22 +01:00
|
|
|
if (!group_right_1) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"stack_effect: opcode requires oparg but oparg was not specified");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (group_right_1) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"stack_effect: opcode does not permit oparg but oparg was specified");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
effect = PyCompile_OpcodeStackEffect(opcode, oparg);
|
|
|
|
if (effect == PY_INVALID_STACK_EFFECT) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"invalid opcode or oparg");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PyMethodDef
|
|
|
|
opcode_functions[] = {
|
|
|
|
_OPCODE_STACK_EFFECT_METHODDEF
|
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct PyModuleDef opcodemodule = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_opcode",
|
|
|
|
"Opcode support module.",
|
|
|
|
-1,
|
|
|
|
opcode_functions,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
|
|
PyInit__opcode(void)
|
|
|
|
{
|
|
|
|
return PyModule_Create(&opcodemodule);
|
|
|
|
}
|