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.

rpn_if_default.h 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 __rpn_if_default__h__
  20. #define __rpn_if_default__h__
  21. /**@file rpn_if_default.h Defines default IF
  22. * @ingroup ifs_if_default
  23. * @ingroup ifs_if
  24. * @brief Default IF definitions
  25. */
  26. /**@defgroup ifs_if_default Default functions
  27. * @ingroup ifs_if
  28. * @brief Simple iterated functions functions
  29. *
  30. * Defines default @ref rpn_if_param_s.res_f and @ref rpn_if_param_s.arg_f
  31. * functions.
  32. */
  33. #include "config.h"
  34. #include "rpn_if.h"
  35. /**@weakgroup ifs_if_default_posflag Default IF position flags
  36. * @ingroup ifs_if_default
  37. * @{ */
  38. #define RPN_IF_POSITION_LINEAR 0 ///< One expr for position
  39. #define RPN_IF_POSITION_XY 1 ///< two expr for position
  40. #define RPN_IF_POSITION_XDIM 2 ///< X expr for position
  41. #define RPN_IF_POSITION_OF_LOOP 0 ///< Loop on position overflow
  42. #define RPN_IF_POSITION_OF_ERR 16 ///< Trigger error on position overflow
  43. /**@}*/
  44. /**@weakgroup ifs_if_default_resflag Default IF position flags
  45. * @ingroup ifs_if_default
  46. * @{ */
  47. #define RPN_IF_RES_BOOL 0 ///< Set to one when position occurs
  48. #define RPN_IF_RES_CONST 1 ///< Set to a constant value
  49. #define RPN_IF_RES_CONST_RGBA 2 ///< Set to a constant RGB using alpha channel
  50. #define RPN_IF_RES_COUNT 3 ///< Count number of time position occurs
  51. #define RPN_IF_RES_XFUN 4 ///< Set to result of rpn_expr
  52. #define RPN_IF_RES_RGB 5 ///< Set result to RGB color from rpn_expr
  53. #define RPN_IF_RES_RGBA 6 ///< Set result to RGB using alpha channel from rpn_expr
  54. /**@}*/
  55. /**@brief Alias for struct @ref rpn_if_default_data_s */
  56. typedef struct rpn_if_default_data_s rpn_if_default_data_t;
  57. /**@brief Stores default IF data
  58. *
  59. * Stores flags and size limit
  60. */
  61. struct rpn_if_default_data_s
  62. {
  63. /**@brief Flag defining position coordinate handling */
  64. short pos_flag;
  65. /**@brief Flag defining result handling */
  66. short res_flag;
  67. /**@brief Stores size limits given pos_flag
  68. *
  69. * @note If NULL no limit
  70. * - For @ref RPN_IF_POSITION_LINEAR size_lim is a single size_t
  71. * - For @ref RPN_IF_POSITION_XY size_lim is two size_t (height and width)
  72. * - For @ref RPN_IF_POSITION_XDIM *size_lim is the size of size_lim
  73. */
  74. size_t *size_lim;
  75. /**@brief Store constant values to set mem giver res_flag
  76. * - For @ref RPN_IF_RES_CONST_RGBA const_val points on a single value
  77. * - For @ref RPN_IF_RES_CONST_RGBA const_val points on 4 values
  78. */
  79. rpn_value_t *const_val;
  80. };
  81. /**@brief Create a new @ref rpn_if_s corresponding to given flags
  82. * @ingroup ifs_if_default
  83. *
  84. * @param pos_flag Binary OR combination of RPN_IF_POSITION_*
  85. * (@ref ifs_if_default_posflag )
  86. * @param pos_flag Binary OR combination of RPN_IF_RES_*
  87. * (@ref ifs_if_default_posflag )
  88. * @returns A new @ref rpn_if_t (see @ref rpn_if_new ) or NULL on
  89. * error
  90. * @todo Implementation/testing
  91. */
  92. rpn_if_t* rpn_if_new_default(short pos_flag, short res_flag);
  93. /**@brief Default argf function ( see @ref rpn_if_param_s.arg_f ) */
  94. int rpn_if_argf_default(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  95. /**@brief Default result function ( see @ref rpn_if_param_s.res_f ) */
  96. int rpn_if_resf_default(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  97. /**@brief Set the first expression argument from position
  98. * @param rif Expressions
  99. * @param pos Memory map offset
  100. * @param args pointer on expressions arguments
  101. * @note Other arguments are set using the generic @ref rpn_if_argf_default
  102. * function
  103. */
  104. int rpn_if_argf_linear(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  105. /**@brief Transform 1st expression result to position
  106. * @param rif Expressions
  107. * @param pos Pointer on resulting position in memory map
  108. * @param data Pointer on resulting data
  109. * @note Data from position fecth is done by generic @ref rpn_if_resf_default
  110. * function
  111. */
  112. int rpn_if_resf_linear(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  113. /**@brief Set the 1st & 2nd argument from position
  114. * @param rif Expressions
  115. * @param pos Memory map offset
  116. * @param args pointer on expression arguments
  117. * @note Other arguments are set using the generic @ref rpn_if_argf_default
  118. * function
  119. */
  120. int rpn_if_argf_xy(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  121. /**@brief Transform 1st and 2nd result into a memory map's offset
  122. * @param rif Expressions
  123. * @param pos Memory map offset pointer
  124. * @param data Pointer on resulting data
  125. * @note Data from position fetch is done by generic @ref rpn_if_resf_default
  126. * function
  127. */
  128. int rpn_if_resf_xy(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  129. /**@brief Set X first arguments from position
  130. * @param rif Expressions
  131. * @param pos Memory map offset
  132. * @param args Pointer on expression arguments
  133. * @note Other arguments are set using the generic @ref rpn_if_argf_default
  134. * function
  135. */
  136. int rpn_if_argf_xdim(rpn_if_t *rif, size_t pos, rpn_value_t *args);
  137. /**@brief Transform X arguments into a memory map's offset
  138. * @param rif Expressions
  139. * @param pos Memory map offset pointer
  140. * @param data Pointer on resulting data
  141. * @note Data from position fetch is done by generic @ref rpn_if_resf_default
  142. * function
  143. */
  144. int rpn_if_resf_xdim(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
  145. #endif