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_rpntoken.h 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 2023 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_RPNTOKEN_H__
  20. #define _PYTHON_RPNTOKEN_H__
  21. #include "config.h"
  22. #include "rpn_parse.h"
  23. #define PY_SSIZE_T_CLEAN
  24. #include <Python.h>
  25. #include "structmember.h"
  26. /**@file python_rpntoken.h
  27. * @brief Python RPNToken type headers
  28. * @ingroup python_ext
  29. * @ingroup pymod_pyrpn_token
  30. *
  31. * This file is the header of the RPNToken classes and subclasses
  32. *
  33. */
  34. /**@defgroup pymod_pyrpn_token module pyrpn.token
  35. * @brief Python module representing RPNExpr tokens
  36. * @ingroup pymod_pyrpn
  37. */
  38. /**@brief pyrpn.token module */
  39. extern PyModuleDef rpntokens_module;
  40. /**@defgroup pymod_pyrpn_token_Token pyrpn.token.Token
  41. * @brief Abstract class representing an @ref pymod_pyrpn_RPNExpr token
  42. * @ingroup pymod_pyrpn_token */
  43. /**@brief pyrpn.token.Token generic type
  44. * @ingroup pymod_pyrpn_token_Token */
  45. extern PyTypeObject RPNTokenType;
  46. /**@defgroup pymod_pyrpn_token_TokenOp pyrpn.token.TokenOp
  47. * @brief Python class representing an @ref pymod_pyrpn_RPNExpr operation token
  48. *
  49. * Extends @ref pymod_pyrpn_token_Token
  50. * @ingroup pymod_pyrpn_token */
  51. /**@brief pyrpn.token.TokenOp type
  52. * @ingroup pymod_pyrpn_token_TokenOp */
  53. extern PyTypeObject RPNTokenOpType;
  54. /**@defgroup pymod_pyrpn_token_TokenVal pyrpn.token.TokenVal
  55. * @brief Python class representing an @ref pymod_pyrpn_RPNExpr value token
  56. *
  57. * Extends @ref pymod_pyrpn_token_Token
  58. * @ingroup pymod_pyrpn_token */
  59. /**@brief pyrpn.token.TokenVal type
  60. * @ingroup pymod_pyrpn_token_TokenVal */
  61. extern PyTypeObject RPNTokenValType;
  62. /**@defgroup pymod_pyrpn_token_TokenArg pyrpn.token.TokenArg
  63. * @brief Python class representing an @ref pymod_pyrpn_RPNExpr argument token
  64. *
  65. * Extends @ref pymod_pyrpn_token_Token
  66. * @ingroup pymod_pyrpn_token */
  67. /**@brief pyrpn.token.TokenArg type
  68. * @ingroup pymod_pyrpn_token_TokenArg */
  69. extern PyTypeObject RPNTokenArgType;
  70. /**@brief C representation of @ref RPNTokenType generic class
  71. * @ingroup pymod_pyrpn_token_Token */
  72. typedef struct
  73. {
  74. /** Python's type definition */
  75. PyObject_HEAD;
  76. /** @brief The token value (will be set by subtypes) */
  77. rpn_token_t value;
  78. } RPNToken_t;
  79. /**@brief C representation of all @ref RPNTokenType subclasses
  80. * @ingroup pymod_pyrpn_token_tokenOp
  81. * @ingroup pymod_pyrpn_token_tokenVal
  82. * @ingroup pymod_pyrpn_token_tokenArg
  83. */
  84. typedef struct {
  85. /** @brief Pointer on super type */
  86. RPNToken_t super;
  87. } RPNTokenSubClass_t;
  88. /**@brief C representation of @ref RPNTokenOpType
  89. * @ingroup pymod_pyrpn_token_TokenOp */
  90. typedef RPNTokenSubClass_t RPNTokenOp_t;
  91. /**@brief C representation of @ref RPNTokenValType
  92. * @ingroup pymod_pyrpn_token_TokenVal */
  93. typedef RPNTokenSubClass_t RPNTokenVal_t;
  94. /**@brief C representation of @ref RPNTokenArgType
  95. * @ingroup pymod_pyrpn_token_TokenArg */
  96. typedef RPNTokenSubClass_t RPNTokenArg_t;
  97. /**@brief Module initialisation function
  98. * @return initialized module
  99. * @ingroup pymod_pyrpn_token */
  100. PyObject* rpntokens_module_init(void);
  101. /**@brief Class method returning a token instance from a string representation
  102. * @param cls @ref RPNTokenType class or any subclass
  103. * @param arg A str representing a token
  104. * @return A new @ref RPNTokenType subclass instance or NULL on error
  105. * @ingroup pymod_pyrpn_token_Token
  106. */
  107. PyObject* rpntoken_from_str(PyObject *cls, PyObject *arg);
  108. /**@brief Instanciate a new RPNToken subclass given a C token
  109. * @param token An expression token
  110. * @return A new @ref RPNTokenType subclass instance
  111. * @ingroup pymod_pyrpn_token_Token
  112. */
  113. PyObject* rpntoken_from_token(const rpn_token_t *token);
  114. /**@brief @ref RPNTokenType __init__ method
  115. * @param _self @ref RPNTokenType subclass instance
  116. * @param args Positional arguments
  117. * @param kwds Keyword arguments
  118. * @return 0 or -1 on error
  119. * @ingroup pymod_pyrpn_token_Token
  120. */
  121. int rpntoken_init(PyObject *_self, PyObject *args, PyObject *kwds);
  122. /**@brief PEP-207 comparison method
  123. * @param _self An @ref RPNTokenType subclass instance
  124. * @param other The @ref RPNTokenType subclass instance to compare to
  125. * @param op The comparison
  126. * @return Py_True or Py_False
  127. * @ingroup pymod_pyrpn_token_Token
  128. */
  129. PyObject* rpntoken_richcompare(PyObject *_self, PyObject *other, int op);
  130. /**@brief __str__ method
  131. * @param _self An @ref RPNTokenType subclass instance
  132. * @return A str representing the token
  133. * @ingroup pymod_pyrpn_token_Token */
  134. PyObject* rpntoken_str(PyObject *_self);
  135. /**@brief __repr__ method
  136. * @param _self An @ref RPNTokenType subclass instance
  137. * @return A str representing the token
  138. * @ingroup pymod_pyrpn_token_Token */
  139. PyObject* rpntoken_repr(PyObject *_self);
  140. /**@brief @ref RPNTokenOpType __init__ method
  141. * @param _self RPNTokenOpType being initialized
  142. * @param args Positional arguments
  143. * @param kwds Keyword arguments
  144. * @return 0 or -1 on error
  145. * @ingroup pymod_pyrpn_token_TokenOp */
  146. int rpntokenop_init(PyObject *_self, PyObject *args, PyObject *kwds);
  147. /**@brief @ref RPNTokenOpType opcode_max method
  148. * @param Py_UNUSED unused argument for static method
  149. * @return The maximum valid opcode
  150. * @ingroup pymod_pyrpn_token_TokenOp */
  151. PyObject *rpntokenop_opcode_max(PyObject *Py_UNUSED(_static));
  152. /**@brief @ref RPNTokenOpType chr method
  153. * @param _self @ref RPNTokenOpType instance
  154. * @param Py_UNUSED unused argument
  155. * @return A string with a single chr representing the operation
  156. * @ingroup pymod_pyrpn_token_TokenOp */
  157. PyObject *rpntokenop_opchr(PyObject *_self, PyObject* Py_UNUSED(_null));
  158. /**@brief @ref RPNTokenOpType str method
  159. * @param _self @ref RPNTokenOpType instance
  160. * @param Py_UNUSED unused argument
  161. * @return A string representing the operation on multiple chr
  162. * @ingroup pymod_pyrpn_token_TokenOp */
  163. PyObject *rpntokenop_opstr(PyObject *_self, PyObject* Py_UNUSED(_null));
  164. /**@brief @ref RPNTokenValType __init__ method
  165. * @param _self RPNTokenValType being initialized
  166. * @param args Positional arguments
  167. * @param kwds Keyword arguments
  168. * @return 0 or -1 on error
  169. * @ingroup pymod_pyrpn_token_TokenVal */
  170. int rpntokenval_init(PyObject *_self, PyObject *args, PyObject *kwds);
  171. /**@brief @ref RPNTokenArgType __init__ method
  172. * @param _self RPNTokenArgType being initialized
  173. * @param args Positional arguments
  174. * @param kwds Keyword arguments
  175. * @return 0 or -1 on error
  176. * @ingroup pymod_pyrpn_token_TokenArg */
  177. int rpntokenarg_init(PyObject *_self, PyObject *args, PyObject *kwds);
  178. #endif