kernel.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. // Value* getType(Value*,Context*);
  116. //------
  117. // Void
  118. //------
  119. string void_disp(void*);
  120. void void_del(void*);
  121. void* void_copy(void*);
  122. int void_comp(void*,void*);
  123. //***********************
  124. //* Auxiliary functions *
  125. //***********************
  126. //! Init the kernel
  127. //! \param context evaluation context
  128. //! \param interpreter the interpreter used for evaluation
  129. void init_kernel(Context& context,Interpreter& interpreter);
  130. //! Display Signature signature
  131. string disp_signature(const Signature& signaure);
  132. //! Load a module
  133. Value load_module(Context& context,Value& v);
  134. //! Unload a module
  135. Value unload(Context& context,Value& v);
  136. //! Reload a module
  137. Value reload(Context& context,Value& v);
  138. //***********************
  139. //* Inline declarations *
  140. //***********************
  141. //---------
  142. // Boolean
  143. //----------
  144. inline void
  145. boolean_del(void* v){delete (char*)v;}
  146. inline void*
  147. boolean_copy(void* v){return new char(*(char*)v);}
  148. //---------
  149. // Context
  150. //---------
  151. inline string
  152. context_disp(void*){return "Context";}
  153. inline void
  154. context_del(void*){}
  155. inline void*
  156. context_copy(void*){Bug("Not yet implemented");}
  157. inline int
  158. context_comp(void*,void*){Bug("Not yet implemented");}
  159. //--------------------
  160. // ContextualFunction
  161. //--------------------
  162. inline void
  163. contextual_function_del(void*){Bug("Not yet implemented");}
  164. inline void*
  165. contextual_function_copy(void*){Bug("Not yet implemented");}
  166. inline int
  167. contextual_function_comp(void*,void*){Bug("Not yet implemented");}
  168. //----------
  169. // Function
  170. //----------
  171. inline void
  172. function_del(void*){Bug("Not yet implemented");}
  173. inline void*
  174. function_copy(void*){Bug("Not yet implemented");}
  175. inline int
  176. function_comp(void*,void*){Bug("Not yet implemented");}
  177. //---------
  178. // Integer
  179. //---------
  180. inline void
  181. integer_del(void* v){fmpz_clear((fmpz*)v);}
  182. inline int
  183. integer_comp(void* v1,void* v2){return fmpz_cmp((fmpz*)v1,(fmpz*)v2);}
  184. //--------------
  185. // MetaFunction
  186. //--------------
  187. inline void
  188. meta_function_del(void*){}
  189. inline void*
  190. meta_function_copy(void*){Bug("Not yet implemented");}
  191. inline int
  192. meta_function_comp(void*,void*){Bug("Not yet implemented");}
  193. //--------
  194. // Module
  195. //--------
  196. inline void
  197. module_del(void* v){delete (Module*)(v);}
  198. inline void*
  199. module_copy(void*){Bug("Not yet implemented");}
  200. inline string
  201. module_disp(void*){return "module";}
  202. inline int
  203. module_comp(void*,void*){Bug("Not yet implemented");}
  204. //--------
  205. // String
  206. //--------
  207. inline string
  208. string_disp(void* v){
  209. return "\033[32m"+*(string*)v+"\033[0m";
  210. }
  211. inline void
  212. string_del(void* v){delete (string*)v;}
  213. inline void*
  214. string_copy(void* v){return new string(*(string*)v);}
  215. //------
  216. // Type
  217. //------
  218. inline string
  219. type_disp(void* T){
  220. return "\033[1;32m"+((Type*)T)->name+"\033[0m";
  221. }
  222. inline void
  223. type_del(void*){}
  224. inline void*
  225. type_copy(void*){Bug("Not yet implemented");}
  226. //------
  227. // Void
  228. //------
  229. inline string
  230. void_disp(void*){return "";}
  231. inline void
  232. void_del(void*){}
  233. inline int
  234. void_comp(void*,void*){return 0;}
  235. inline void*
  236. void_copy(void*){return nullptr;}
  237. }
  238. #endif