165 lines
4.6 KiB
C
165 lines
4.6 KiB
C
/*
|
|
* Copyright (C) 2020 Weber Yann
|
|
*
|
|
* This file is part of pyrpn.
|
|
*
|
|
* pyrpn is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* pyrpn is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef _PYTHON_RPNEXPR_H__
|
|
#define _PYTHON_RPNEXPR_H__
|
|
|
|
#include "config.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
#include <Python.h>
|
|
#include "structmember.h"
|
|
|
|
#include "rpn_jit.h"
|
|
|
|
/**@defgroup python_type RPNExpr Python class
|
|
* @brief Exposed Python class : RPNExpr
|
|
* @ingroup python_module
|
|
*/
|
|
|
|
/**@file python_rpnexpr.h
|
|
* @brief Python RPNExpr type headers
|
|
* @ingroup python_type
|
|
*
|
|
* This file is the header of the RPNExpr Python class
|
|
*/
|
|
|
|
/**@brief RPNExpr Python class methods list
|
|
* @ingroup python_type */
|
|
extern PyMethodDef RPNExpr_methods[];
|
|
/**@brief RPNExpr Python class members list
|
|
* @ingroup python_type */
|
|
extern PyMemberDef RPNExpr_members[];
|
|
/**@brief RPNExpr Python class type definition
|
|
* @ingroup python_type */
|
|
extern PyTypeObject RPNExprType;
|
|
|
|
/**@brief Structure holding RPNExpr objects
|
|
* @ingroup python_type */
|
|
typedef struct
|
|
{
|
|
PyObject_VAR_HEAD;
|
|
|
|
/**@brief Pointer on @ref rpn_expr_s */
|
|
rpn_expr_t *rpn;
|
|
|
|
/**@brief Array storing expression argument
|
|
* @note As attribute of rpn_expr allowing malloc & free only once */
|
|
rpn_value_t *args;
|
|
} PyRPNExpr_t;
|
|
|
|
/**@brief Organize PyRPNExpr_t state data
|
|
* @see rpnexpr_getstate
|
|
* @see rpnexpr_setstate */
|
|
typedef struct
|
|
{
|
|
size_t total_sz;
|
|
size_t argc;
|
|
unsigned char stack_sz;
|
|
size_t token_sz;
|
|
} PyRPNExpr_state_t;
|
|
|
|
/**@brief RpnExpr __new__ method
|
|
* @param subtype Type of object being created (pyrpn.RPNExpr)
|
|
* @param args positional arguments for subtype
|
|
* @param kwargs keyword argumenrs for subtype
|
|
* @return The new Python RPNExpr object
|
|
*/
|
|
PyObject* rpnexpr_new(PyTypeObject *subtype, PyObject *args, PyObject* kwds);
|
|
|
|
/**@brief RpnExpr constructor
|
|
* @param self New RPNExpr instance
|
|
* @param args Positional arguments list
|
|
* @param kwds Keywords arguments dict
|
|
* @return 0 if no error else -1
|
|
* @ingroup python_type
|
|
*/
|
|
int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds);
|
|
|
|
/**@brief RPNExpr __del__ method
|
|
* @param self RPNExpr instance
|
|
* @ingroup python_type
|
|
*/
|
|
void rpnexpr_del(PyObject *self);
|
|
|
|
/**@brief Returns a byte representation of expression (like getstate but
|
|
* without the stack informations
|
|
* @param self RPNExpr instance
|
|
* @param noargs Not an argument...
|
|
* @return A bytes Python instance
|
|
*/
|
|
PyObject* rpnexpr_getexprstate(PyObject *self, PyObject *noargs);
|
|
|
|
/**@brief RPNExpr __getstate__ method for pickling
|
|
* @param self RPNExpr type object
|
|
* @param noargs Not an argument...
|
|
* @return A bytes Python instance suitable as argument for
|
|
* @ref rpnexpr_setstate
|
|
*/
|
|
PyObject* rpnexpr_getstate(PyObject *self, PyObject *noargs);
|
|
|
|
/**@brief RPNExpr __setstate__ method for pickling
|
|
* @param cls RPNExpr type object
|
|
* @param state Should by a bytes Python instance returned by @ref
|
|
* rpnexpr_getstate
|
|
* @return A bytes Python instance suitable as argument for
|
|
* @ref rpnexpr_getstate
|
|
*/
|
|
PyObject* rpnexpr_setstate(PyObject *cls, PyObject *state);
|
|
|
|
/**@brief Eval an RPN expression given arguments and return the
|
|
* value
|
|
* @param self RPNExpr instance
|
|
* @param argv Array of PyObject* arguments
|
|
* @param argc Number of arguments
|
|
* @return The value resulting of evaluation
|
|
* @ingroup python_type
|
|
*/
|
|
PyObject* rpnexpr_eval(PyObject* self, PyObject** argv, Py_ssize_t argc);
|
|
|
|
/**@brief Set all stack item to zero
|
|
* @param self RPNExpr instance
|
|
* @param noargs Dummy argument for METH_NOARG
|
|
* @return None
|
|
* @ingroup python_type
|
|
*/
|
|
PyObject* rpnexpr_reset_stack(PyObject *self, PyObject *noargs);
|
|
|
|
/**@brief RPNExpr.__repr__()
|
|
* @param self RPNExpr instance
|
|
* @ingroup python_type
|
|
*/
|
|
PyObject* rpnexpr_repr(PyObject *self);
|
|
|
|
/**@brief RPNExpr.__str__()
|
|
* @param self RPNExpr instance
|
|
* @ingroup python_type
|
|
*/
|
|
PyObject* rpnexpr_str(PyObject *self);
|
|
|
|
/**@brief Return a new Python str with a random RPN expression
|
|
* @param mod pyrpn module object
|
|
* @param args Position arguments in Python list
|
|
* @param kwds Keywords arguments in Python dict
|
|
* @ingroup python_module
|
|
*/
|
|
PyObject* rpnexpr_random(PyObject *cls, PyObject *args, PyObject *kwds);
|
|
|
|
#endif
|