Fast IFS using RPN notation
python
c
x86-64
nasm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python_rpnexpr.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2020 Weber Yann
  3. *
  4. * This file is part of pyrpn.
  5. *
  6. * pyrpn is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * pyrpn is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _PYTHON_PYRPN_H__
  20. #define _PYTHON_PYRPN_H__
  21. #include "config.h"
  22. #include <errno.h>
  23. #define PY_SSIZE_T_CLEAN
  24. #include <Python.h>
  25. #include "structmember.h"
  26. #include "rpn_jit.h"
  27. /**@defgroup python_type RPNExpr Python class
  28. * @brief Exposed Python class : RPNExpr
  29. * @ingroup python_module
  30. */
  31. /**@file python_rpnexpr.h
  32. * @brief Python RPNExpr type headers
  33. * @ingroup python_type
  34. *
  35. * This file is the header of the RPNExpr Python class
  36. */
  37. /**@brief RPNExpr Python class methods list
  38. * @ingroup python_type */
  39. extern PyMethodDef RPNExpr_methods[];
  40. /**@brief RPNExpr Python class members list
  41. * @ingroup python_type */
  42. extern PyMemberDef RPNExpr_members[];
  43. /**@brief RPNExpr Python class type definition
  44. * @ingroup python_type */
  45. extern PyTypeObject RPNExprType;
  46. /**@brief Structure holding RPNExpr objects
  47. * @ingroup python_type */
  48. typedef struct
  49. {
  50. PyObject_VAR_HEAD;
  51. /**@brief Pointer on @ref rpn_expr_s */
  52. rpn_expr_t *rpn;
  53. /**@brief Array storing expression argument
  54. * @note As attribute of rpn_expr allowing malloc & free only once */
  55. rpn_value_t *args;
  56. } PyRPNExpr_t;
  57. /**@brief Organize PyRPNExpr_t state data
  58. * @see rpnexpr_getstate
  59. * @see rpnexpr_setstate */
  60. typedef struct
  61. {
  62. size_t total_sz;
  63. size_t argc;
  64. unsigned char stack_sz;
  65. size_t token_sz;
  66. } PyRPNExpr_state_t;
  67. /**@brief RpnExpr __new__ method
  68. * @param subtype Type of object being created (pyrpn.RPNExpr)
  69. * @param args positional arguments for subtype
  70. * @param kwargs keyword argumenrs for subtype
  71. * @return The new Python RPNExpr object
  72. */
  73. PyObject* rpnexpr_new(PyTypeObject *subtype, PyObject *args, PyObject* kwds);
  74. /**@brief RpnExpr constructor
  75. * @param self New RPNExpr instance
  76. * @param args Positional arguments list
  77. * @param kwds Keywords arguments dict
  78. * @return 0 if no error else -1
  79. * @ingroup python_type
  80. */
  81. int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds);
  82. /**@brief RPNExpr __del__ method
  83. * @param self RPNExpr instance
  84. * @ingroup python_type
  85. */
  86. void rpnexpr_del(PyObject *self);
  87. /**@brief RPNExpr __getstate__ method for pickling
  88. * @param cls RPNExpr type object
  89. * @param noargs Not an argument...
  90. * @return A bytes Python instance suitable as argument for
  91. * @ref rpnexpr_setstate
  92. */
  93. PyObject* rpnexpr_getstate(PyObject *cls, PyObject *noargs);
  94. /**@brief RPNExpr __setstate__ method for pickling
  95. * @param cls RPNExpr type object
  96. * @param state Should by a bytes Python instance returned by @ref
  97. * rpnexpr_getstate
  98. * @return A bytes Python instance suitable as argument for
  99. * @ref rpnexpr_setstate
  100. */
  101. PyObject* rpnexpr_setstate(PyObject *cls, PyObject *state);
  102. /**@brief Eval an RPN expression given arguments and return the
  103. * value
  104. * @param self RPNExpr instance
  105. * @param argv Array of PyObject* arguments
  106. * @param argc Number of arguments
  107. * @return The value resulting of evaluation
  108. * @ingroup python_type
  109. */
  110. PyObject* rpnexpr_eval(PyObject* self, PyObject** argv, Py_ssize_t argc);
  111. /**@brief Set all stack item to zero
  112. * @param self RPNExpr instance
  113. * @param noargs Dummy argument for METH_NOARG
  114. * @return None
  115. * @ingroup python_type
  116. */
  117. PyObject* rpnexpr_reset_stack(PyObject *self, PyObject *noargs);
  118. /**@brief RPNExpr.__repr__()
  119. * @param self RPNExpr instance
  120. * @ingroup python_type
  121. */
  122. PyObject* rpnexpr_repr(PyObject *self);
  123. /**@brief RPNExpr.__str__()
  124. * @param self RPNExpr instance
  125. * @ingroup python_type
  126. */
  127. PyObject* rpnexpr_str(PyObject *self);
  128. #endif