kernel.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * This file is part of Gomu.
  3. *
  4. * Copyright 2016 by Jean Fromentin <jean.fromentin@math.cnrs.fr>
  5. *
  6. * Gomu 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. * (at your option) any later version.
  10. *
  11. * Gomu 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 Gomu. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef KERNEL_HPP
  20. #define KERNEL_HPP
  21. #include "module.hpp"
  22. #include <set>
  23. namespace Gomu{
  24. //************
  25. //* Typedefs *
  26. //************
  27. typedef Array<Type*> Signature;
  28. //***********************
  29. //* Auxiliary functions *
  30. //***********************
  31. //-------
  32. // Array
  33. //-------
  34. string array_disp(void*);
  35. void array_del(void*);
  36. void* array_copy(void*);
  37. int array_comp(void*,void*);
  38. //---------
  39. // Boolean
  40. //---------
  41. string boolean_disp(void*);
  42. void boolean_del(void*);
  43. void* boolean_copy(void*);
  44. int boolean_comp(void*,void*);
  45. //---------
  46. // Context
  47. //---------
  48. string context_disp(void*);
  49. void context_del(void*);
  50. void* context_copy(void*);
  51. int context_comp(void*,void*);
  52. //--------------------
  53. // ContextualFunction
  54. //--------------------
  55. string contextual_function_disp(void*);
  56. void contextual_function_del(void*);
  57. void* contextual_function_copy(void*);
  58. int contextual_function_comp(void*,void*);
  59. //----------
  60. // Function
  61. //----------
  62. string function_disp(void*);
  63. void function_del(void*);
  64. void* function_copy(void*);
  65. int function_comp(void*,void*);
  66. //---------
  67. // Integer
  68. //---------
  69. string integer_disp(void*);
  70. void integer_del(void*);
  71. void* integer_copy(void*);
  72. int integer_comp(void*,void*);
  73. //--------------
  74. // MetaFunction
  75. //--------------
  76. string meta_function_disp(void*);
  77. void meta_function_del(void*);
  78. void* meta_function_copy(void*);
  79. int meta_function_comp(void*,void*);
  80. //--------
  81. // Module
  82. //--------
  83. string module_disp(void*);
  84. void module_del(void*);
  85. void* module_copy(void*);
  86. int module_comp(void*,void*);
  87. //-----
  88. // Set
  89. //-----
  90. string set_disp(void*);
  91. void set_del(void*);
  92. void* set_copy(void*);
  93. int set_comp(void*,void*);
  94. //--------
  95. // String
  96. //--------
  97. string string_disp(void*);
  98. void string_del(void*);
  99. void* string_copy(void*);
  100. int string_comp(void*,void*);
  101. //-------
  102. // Tuple
  103. //-------
  104. string tuple_disp(void*);
  105. void tuple_del(void*);
  106. void* tuple_copy(void*);
  107. int tuple_comp(void*,void*);
  108. //------
  109. // Type
  110. //------
  111. string type_disp(void*);
  112. void type_del(void*);
  113. void* type_copy(void*);
  114. int type_comp(void*,void*);
  115. //------
  116. // Void
  117. //------
  118. string void_disp(void*);
  119. void void_del(void*);
  120. void* void_copy(void*);
  121. int void_comp(void*,void*);
  122. //***********************
  123. //* Auxiliary functions *
  124. //***********************
  125. //! Init the kernel
  126. //! \param context evaluation context
  127. //! \param interpreter the interpreter used for evaluation
  128. void init_kernel(Context& context,Interpreter& interpreter);
  129. //! Display Signature signature
  130. string disp_signature(const Signature& signaure);
  131. //! Load a module
  132. Value load_module(Context& context,Value& v);
  133. //! Unload a module
  134. Value unload(Context& context,Value& v);
  135. //! Reload a module
  136. Value reload(Context& context,Value& v);
  137. //***********************
  138. //* Inline declarations *
  139. //***********************
  140. //---------
  141. // Boolean
  142. //----------
  143. inline void
  144. boolean_del(void* v){delete (char*)v;}
  145. inline void*
  146. boolean_copy(void* v){return new char(*(char*)v);}
  147. //---------
  148. // Context
  149. //---------
  150. inline string
  151. context_disp(void*){return "Context";}
  152. inline void
  153. context_del(void*){}
  154. inline void*
  155. context_copy(void*){Bug("Not yet implemented");}
  156. inline int
  157. context_comp(void*,void*){Bug("Not yet implemented");}
  158. //--------------------
  159. // ContextualFunction
  160. //--------------------
  161. inline void
  162. contextual_function_del(void*){Bug("Not yet implemented");}
  163. inline void*
  164. contextual_function_copy(void*){Bug("Not yet implemented");}
  165. inline int
  166. contextual_function_comp(void*,void*){Bug("Not yet implemented");}
  167. //----------
  168. // Function
  169. //----------
  170. inline void
  171. function_del(void*){Bug("Not yet implemented");}
  172. inline void*
  173. function_copy(void*){Bug("Not yet implemented");}
  174. inline int
  175. function_comp(void*,void*){Bug("Not yet implemented");}
  176. //---------
  177. // Integer
  178. //---------
  179. inline void
  180. integer_del(void* v){fmpz_clear((fmpz*)v);}
  181. inline int
  182. integer_comp(void* v1,void* v2){return fmpz_cmp((fmpz*)v1,(fmpz*)v2);}
  183. //--------------
  184. // MetaFunction
  185. //--------------
  186. inline void
  187. meta_function_del(void*){}
  188. inline void*
  189. meta_function_copy(void*){Bug("Not yet implemented");}
  190. inline int
  191. meta_function_comp(void*,void*){Bug("Not yet implemented");}
  192. //--------
  193. // Module
  194. //--------
  195. inline void
  196. module_del(void* v){delete (Module*)(v);}
  197. inline void*
  198. module_copy(void*){Bug("Not yet implemented");}
  199. inline string
  200. module_disp(void*){return "module";}
  201. inline int
  202. module_comp(void*,void*){Bug("Not yet implemented");}
  203. //--------
  204. // String
  205. //--------
  206. inline string
  207. string_disp(void* v){
  208. return "\033[32m"+*(string*)v+"\033[0m";
  209. }
  210. inline void
  211. string_del(void* v){delete (string*)v;}
  212. inline void*
  213. string_copy(void* v){return new string(*(string*)v);}
  214. //------
  215. // Type
  216. //------
  217. inline string
  218. type_disp(void* T){
  219. return "\033[1;32m"+((Type*)T)->name+"\033[0m";
  220. }
  221. inline void
  222. type_del(void*){}
  223. inline void*
  224. type_copy(void*){Bug("Not yet implemented");}
  225. //------
  226. // Void
  227. //------
  228. inline string
  229. void_disp(void*){return "";}
  230. inline void
  231. void_del(void*){}
  232. inline int
  233. void_comp(void*,void*){return 0;}
  234. inline void*
  235. void_copy(void*){return nullptr;}
  236. }
  237. #endif