123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- #include "python_if.h"
-
- PyMethodDef RPNIterExpr_methods[] = {
- {"__getstate__", (PyCFunction)rpnif_getstate, METH_NOARGS,
- "Pickling method. Return a bytes repr of tokenized expression \
- and the stack state."},
- {"__setstate__", (PyCFunction)rpnif_setstate, METH_O,
- "Unpickling method"},
- {NULL} //Sentinel
- };
-
- PyMemberDef RPNIterExpr_members[] = {
- {NULL}
- };
-
- PyGetSetDef RPNIterExpr_getset[] = {
- {NULL}
- };
-
- PyTypeObject RPNIterExprType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "pyrpn.RPNIterExpr", /* tp_name */
- sizeof(PyRPNIterExpr_t), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor)rpnif_del, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_reserved */
- rpnif_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- rpnif_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
- "RPN expression evaluator", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- RPNIterExpr_methods, /* tp_methods */
- RPNIterExpr_members, /* tp_members */
- RPNIterExpr_getset, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- rpnif_init, /* tp_init */
- 0, /* tp_alloc */
- rpnif_new, /* tp_new */
- };
-
- PyObject* rpnif_new(PyTypeObject *subtype, PyObject *args, PyObject* kwds)
- {
- PyObject *ret, *err;
- PyRPNIterExpr_t *expr;
- ret = PyType_GenericNew(subtype, args, kwds);
- if((err = PyErr_Occurred()))
- {
- Py_DECREF(err);
- return ret;
- }
- expr = (PyRPNIterExpr_t*)ret;
- expr->rif = NULL;
-
- return ret;
- }
-
-
- int rpnif_init(PyObject *self, PyObject *args, PyObject *kwds)
- {
- /**@todo TODO write the function */
- PyRPNIterExpr_t *expr_self;
- char *names[] = {"pos_flag", "res_flag", "lim", "value", "stack_size", NULL};
- unsigned short pos_flag, res_flag, stack_size;
- PyObject *lim, *value;
- char err_str[256];
-
- expr_self = (PyRPNIterExpr_t*)self;
-
- stack_size = 16;
- value = lim = NULL;
- expr_self->rif = NULL;
-
- if(!PyArg_ParseTupleAndKeywords(args, kwds, "HHO|OH:RPNIterExpr.__init__", names,
- &pos_flag, &res_flag, lim, value, &stack_size))
- {
- return -1;
- }
-
- // Args checking
- if(stack_size < 4 || stack_size > 255)
- {
- snprintf(err_str, 128,
- "Stack size should be in [0..255] but %u given",
- stack_size);
- PyErr_SetString(PyExc_ValueError, err_str);
- return -1;
- }
- //Check & convert lim
-
- //Check & convert value
-
- return 0;
- }
-
- void rpnif_del(PyObject *self)
- {
- PyRPNIterExpr_t *expr_self;
-
- expr_self = (PyRPNIterExpr_t*)self;
- if(expr_self->rif)
- {
- rpn_if_free(expr_self->rif);
- expr_self->rif = NULL;
- }
- }
-
- PyObject* rpnif_str(PyObject *self)
- {
- /**@todo TODO write the function */
- Py_RETURN_NONE;
- }
-
- PyObject* rpnif_repr(PyObject *self)
- {
- /**@todo TODO write the function */
- Py_RETURN_NONE;
- }
-
- PyObject* rpnif_getstate(PyObject *self, PyObject *noargs)
- {
- /**@todo TODO write the function */
- Py_RETURN_NONE;
- }
-
- PyObject* rpnif_setstate(PyObject *self, PyObject *state_bytes)
- {
- /**@todo TODO write the function */
- Py_RETURN_NONE;
- }
|