IterationIR.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #ifndef MANDEL_ITERATIONIR_H
  2. #define MANDEL_ITERATIONIR_H
  3. #include <string>
  4. #include <vector>
  5. #include <variant>
  6. #include <any>
  7. #include "IterationFormula.h"
  8. #include "Arena.h"
  9. namespace mnd
  10. {
  11. namespace ir
  12. {
  13. struct NodeBase;
  14. struct Constant;
  15. struct Variable;
  16. struct UnaryOperation;
  17. struct Negation;
  18. struct BinaryOperation;
  19. struct Addition;
  20. struct Subtraction;
  21. struct Multiplication;
  22. struct Atan2;
  23. struct Pow;
  24. struct Cos;
  25. struct Sin;
  26. struct Exp;
  27. struct Ln;
  28. using Node = std::variant<
  29. Constant,
  30. Variable,
  31. Negation,
  32. Addition,
  33. Subtraction,
  34. Multiplication,
  35. Atan2,
  36. Pow,
  37. Cos,
  38. Sin,
  39. Exp,
  40. Ln
  41. >;
  42. struct Formula
  43. {
  44. util::Arena<Node> nodeArena;
  45. Node* newA;
  46. Node* newB;
  47. std::string toString(void) const;
  48. };
  49. }
  50. ir::Formula expand(const mnd::IterationFormula& fmla);
  51. }
  52. struct mnd::ir::NodeBase
  53. {
  54. std::any nodeData;
  55. };
  56. struct mnd::ir::Constant : NodeBase
  57. {
  58. double value;
  59. inline Constant(double val) : value{ val } {}
  60. };
  61. struct mnd::ir::Variable : NodeBase
  62. {
  63. std::string name;
  64. inline Variable(const std::string name) : name{ name } {}
  65. };
  66. struct mnd::ir::UnaryOperation : NodeBase
  67. {
  68. Node* value;
  69. inline UnaryOperation(Node* value) : value{ value } {}
  70. };
  71. struct mnd::ir::Negation : mnd::ir::UnaryOperation
  72. {
  73. inline Negation(Node* value) : UnaryOperation{ value } {}
  74. };
  75. struct mnd::ir::BinaryOperation : NodeBase
  76. {
  77. Node* left;
  78. Node* right;
  79. inline BinaryOperation(Node* left, Node* right) :
  80. left{ left }, right{ right } {}
  81. };
  82. struct mnd::ir::Addition : mnd::ir::BinaryOperation
  83. {
  84. inline Addition(Node* left, Node* right) :
  85. BinaryOperation{ left, right } {}
  86. };
  87. struct mnd::ir::Subtraction : mnd::ir::BinaryOperation
  88. {
  89. inline Subtraction(Node* left, Node* right) :
  90. BinaryOperation{ left, right } {}
  91. };
  92. struct mnd::ir::Multiplication : mnd::ir::BinaryOperation
  93. {
  94. inline Multiplication(Node* left, Node* right) :
  95. BinaryOperation{ left, right } {}
  96. };
  97. struct mnd::ir::Atan2 : mnd::ir::BinaryOperation
  98. {
  99. inline Atan2(Node* left, Node* right) :
  100. BinaryOperation{ left, right } {}
  101. };
  102. struct mnd::ir::Pow : mnd::ir::BinaryOperation
  103. {
  104. inline Pow(Node* left, Node* right) :
  105. BinaryOperation{ left, right } {}
  106. };
  107. struct mnd::ir::Cos : mnd::ir::UnaryOperation
  108. {
  109. inline Cos(Node* value) : UnaryOperation{ value } {}
  110. };
  111. struct mnd::ir::Sin : mnd::ir::UnaryOperation
  112. {
  113. inline Sin(Node* value) : UnaryOperation{ value } {}
  114. };
  115. struct mnd::ir::Exp : mnd::ir::UnaryOperation
  116. {
  117. inline Exp(Node* value) : UnaryOperation{ value } {}
  118. };
  119. struct mnd::ir::Ln : mnd::ir::UnaryOperation
  120. {
  121. inline Ln(Node* value) : UnaryOperation{ value } {}
  122. };
  123. #endif // MANDEL_ITERATIONIR_H