PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tool/gec/runtime/c/ge_types.h

http://github.com/gobo-eiffel/gobo
C Header | 544 lines | 297 code | 58 blank | 189 comment | 3 complexity | 50b9eee7db1b72356dc194e3d8ead9bf MD5 | raw file
  1. /*
  2. description:
  3. "C functions used to implement type information"
  4. system: "Gobo Eiffel Compiler"
  5. copyright: "Copyright (c) 2016-2018, Eric Bezault and others"
  6. license: "MIT License"
  7. date: "$Date$"
  8. revision: "$Revision$"
  9. */
  10. #ifndef GE_TYPES_H
  11. #define GE_TYPES_H
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  13. #pragma once
  14. #endif
  15. #ifndef GE_EIFFEL_H
  16. #include "ge_eiffel.h"
  17. #endif
  18. #ifndef GE_EXCEPTION_H
  19. #include "ge_exception.h"
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. * Type annotations.
  26. * When a type has no annotation, it means a detachable, non-separate, variant type.
  27. * In all other cases, there will be an annotation.
  28. */
  29. #define ANNOTATION_MASK 0x007F /* All possible annotations. */
  30. #define ATTACHED_FLAG 0x0001
  31. #define DETACHABLE_FLAG 0x0002 /* Only present when overriding an attached type. */
  32. #define SEPARATE_FLAG 0x0004
  33. #define VARIANT_FLAG 0x0008 /* Only present when overriding a frozen/poly type. */
  34. #define UNUSABLE_FLAG 0x0010 /* Reserved for backward compatibility for storables. */
  35. #define FROZEN_FLAG 0x0020
  36. #define POLY_FLAG 0x0040
  37. /*
  38. * Type flags.
  39. */
  40. #define GE_TYPE_FLAG_SPECIAL 0x0010
  41. #define GE_TYPE_FLAG_TUPLE 0x0020
  42. #define GE_TYPE_FLAG_EXPANDED 0x0040
  43. #define GE_TYPE_FLAG_DEFERRED 0x0080
  44. #define GE_TYPE_FLAG_NONE 0x0100
  45. #define GE_TYPE_FLAG_BASIC_MASK 0x000F /* One of "BOOLEAN", "CHARACTER_8", "CHARACTER_32", "INTEGER_8", "INTEGER_16", "INTEGER_32", "INTEGER_64", "NATURAL_8", "NATURAL_16", "NATURAL_32", "NATURAL_64", "POINTER", "REAL_32", "REAL_64" */
  46. #define GE_TYPE_FLAG_BOOLEAN 0x0001
  47. #define GE_TYPE_FLAG_CHARACTER_8 0x0002
  48. #define GE_TYPE_FLAG_CHARACTER_32 0x0003
  49. #define GE_TYPE_FLAG_INTEGER_8 0x0004
  50. #define GE_TYPE_FLAG_INTEGER_16 0x0005
  51. #define GE_TYPE_FLAG_INTEGER_32 0x0006
  52. #define GE_TYPE_FLAG_INTEGER_64 0x0007
  53. #define GE_TYPE_FLAG_NATURAL_8 0x0008
  54. #define GE_TYPE_FLAG_NATURAL_16 0x0009
  55. #define GE_TYPE_FLAG_NATURAL_32 0x000A
  56. #define GE_TYPE_FLAG_NATURAL_64 0x000B
  57. #define GE_TYPE_FLAG_POINTER 0x000C
  58. #define GE_TYPE_FLAG_REAL_32 0x000D
  59. #define GE_TYPE_FLAG_REAL_64 0x000E
  60. /*
  61. * Convention for attribute types.
  62. * The values are in sync with REFLECTOR_CONSTANTS.
  63. */
  64. #define GE_TYPE_KIND_INVALID -1
  65. #define GE_TYPE_KIND_POINTER 0
  66. #define GE_TYPE_KIND_REFERENCE 1
  67. #define GE_TYPE_KIND_CHARACTER_8 2
  68. #define GE_TYPE_KIND_BOOLEAN 3
  69. #define GE_TYPE_KIND_INTEGER_32 4
  70. #define GE_TYPE_KIND_REAL_32 5
  71. #define GE_TYPE_KIND_REAL_64 6
  72. #define GE_TYPE_KIND_EXPANDED 7
  73. #define GE_TYPE_KIND_INTEGER_8 9
  74. #define GE_TYPE_KIND_INTEGER_16 10
  75. #define GE_TYPE_KIND_INTEGER_64 11
  76. #define GE_TYPE_KIND_CHARACTER_32 12
  77. #define GE_TYPE_KIND_NATURAL_8 13
  78. #define GE_TYPE_KIND_NATURAL_16 14
  79. #define GE_TYPE_KIND_NATURAL_32 15
  80. #define GE_TYPE_KIND_NATURAL_64 16
  81. /*
  82. * Object flags.
  83. */
  84. #define GE_OBJECT_FLAG_MARKED 0x0001
  85. /*
  86. * Ancestor relationship between two types X and Y.
  87. */
  88. #ifdef GE_USE_ANCESTORS
  89. typedef struct {
  90. EIF_TYPE_INDEX type_id; /* Type id of Y */
  91. EIF_BOOLEAN conforms; /* Does X conform to Y? */
  92. void (**qualified_calls)(); /* Function pointers, indexed by call id, when the static type of the target is Y and the dynamic type is X */
  93. } GE_ancestor;
  94. #endif
  95. /*
  96. * Attribute.
  97. */
  98. #ifdef GE_USE_ATTRIBUTES
  99. typedef struct {
  100. #ifdef GE_USE_ATTRIBUTE_NAME
  101. const char* name; /* Attribute name */
  102. #endif
  103. #ifdef GE_USE_ATTRIBUTE_TYPE_ID
  104. EIF_ENCODED_TYPE type_id; /* Static type id */
  105. #endif
  106. #ifdef GE_USE_ATTRIBUTE_OFFSET
  107. uint32_t offset; /* Address offset in object */
  108. #endif
  109. } GE_attribute;
  110. #endif
  111. /*
  112. * Type information.
  113. */
  114. typedef struct {
  115. EIF_TYPE_INDEX type_id;
  116. uint16_t flags;
  117. #ifdef GE_USE_TYPE_GENERATOR
  118. const char* generator; /* Generator class name */
  119. #endif
  120. #ifdef GE_USE_TYPE_NAME
  121. const char* name; /* Full type name */
  122. #endif
  123. #ifdef GE_USE_TYPE_GENERIC_PARAMETERS
  124. EIF_ENCODED_TYPE* generic_parameters;
  125. uint32_t generic_parameter_count;
  126. #endif
  127. #ifdef GE_USE_ANCESTORS
  128. GE_ancestor** ancestors;
  129. uint32_t ancestor_count;
  130. #endif
  131. #ifdef GE_USE_ATTRIBUTES
  132. GE_attribute** attributes;
  133. uint32_t attribute_count;
  134. #endif
  135. #ifdef GE_USE_TYPE_OBJECT_SIZE
  136. uint64_t object_size;
  137. #endif
  138. EIF_REFERENCE (*new_instance)();
  139. void (*dispose)(GE_context*, EIF_REFERENCE);
  140. } GE_type_info;
  141. typedef struct {
  142. EIF_TYPE_INDEX id; /* Type id of the "TYPE [X]" object */
  143. EIF_INTEGER type_id; /* Type id of the type "X" */
  144. EIF_BOOLEAN is_special;
  145. void (*dispose)(GE_context*, EIF_REFERENCE);
  146. EIF_REFERENCE a1; /* internal_name */
  147. EIF_REFERENCE a2; /* internal_name_32 */
  148. } EIF_TYPE_OBJ;
  149. /*
  150. * Types indexed by type id.
  151. * Generated by the compiler.
  152. */
  153. extern EIF_TYPE_OBJ GE_types[][2];
  154. extern GE_type_info GE_type_infos[];
  155. /*
  156. * Number of type infos in `GE_type_infos'.
  157. * Do not take into account the fake item at index 0.
  158. */
  159. extern int GE_type_info_count;
  160. /*
  161. * Encode a EIF_TYPE into a EIF_ENCODED_TYPE.
  162. * The lower part of EIF_ENCODED_TYPE contains the .id field,
  163. * and the upper part the .annotations.
  164. */
  165. extern EIF_ENCODED_TYPE GE_encoded_type(EIF_TYPE a_type);
  166. /*
  167. * Decode a EIF_ENCODED_TYPE into a EIF_TYPE.
  168. * The lower part of EIF_ENCODED_TYPE contains the .id field,
  169. * and the upper part the .annotations.
  170. */
  171. extern EIF_TYPE GE_decoded_type(EIF_ENCODED_TYPE a_type);
  172. /*
  173. * Type with `a_id' and `a_annotations'.
  174. */
  175. extern EIF_TYPE GE_new_type(EIF_TYPE_INDEX a_id, EIF_TYPE_INDEX a_annotations);
  176. /*
  177. * Type of object `obj'.
  178. */
  179. #define GE_object_type(obj) GE_new_type(((EIF_REFERENCE)(obj))->id, 0x0)
  180. #define GE_object_encoded_type(obj) GE_encoded_type(GE_object_type(obj))
  181. /*
  182. * Attachment status of `a_type'.
  183. */
  184. #define GE_is_attached_type(a_type) EIF_TEST(((a_type).annotations & ATTACHED_FLAG) || GE_is_expanded_type_index((a_type).id))
  185. #define GE_is_attached_encoded_type(a_type) GE_is_attached_type(GE_decoded_type(a_type))
  186. /*
  187. * Associated detachable type of `a_type' if any,
  188. * otherwise `a_type'.
  189. */
  190. extern EIF_TYPE GE_non_attached_type(EIF_TYPE a_type);
  191. #define GE_non_attached_encoded_type(a_type) GE_encoded_type(GE_non_attached_type(GE_decoded_type(a_type)))
  192. /*
  193. * Associated attached type of `a_type' if any,
  194. * otherwise `a_type'.
  195. */
  196. extern EIF_TYPE GE_attached_type(EIF_TYPE a_type);
  197. #define GE_attached_encoded_type(t) GE_encoded_type(GE_attached_type(GE_decoded_type(t)))
  198. /*
  199. * Is `a_type' a SPECIAL type?
  200. */
  201. #define GE_is_special_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_SPECIAL)
  202. #define GE_is_special_encoded_type(a_type) GE_is_special_type_index(GE_decoded_type(a_type).id)
  203. #define GE_is_special_object(obj) GE_is_special_type_index(((EIF_REFERENCE)(obj))->id)
  204. /*
  205. * Is `a_type' a SPECIAL type of user-defined expanded type?
  206. */
  207. extern EIF_BOOLEAN GE_is_special_of_expanded_type_index(EIF_TYPE_INDEX a_type);
  208. #define GE_is_special_of_expanded_encoded_type(a_type) GE_is_special_of_expanded_type_index(GE_decoded_type(a_type).id)
  209. #define GE_is_special_of_expanded_object(obj) GE_is_special_of_expanded_type_index(((EIF_REFERENCE)(obj))->id)
  210. /*
  211. * Is `a_type' a SPECIAL type of reference type?
  212. */
  213. extern EIF_BOOLEAN GE_is_special_of_reference_type_index(EIF_TYPE_INDEX a_type);
  214. #define GE_is_special_of_reference_encoded_type(a_type) GE_is_special_of_reference_type_index(GE_decoded_type(a_type).id)
  215. #define GE_is_special_of_reference_object(obj) GE_is_special_of_reference_type_index(((EIF_REFERENCE)(obj))->id)
  216. /*
  217. * Is `a_type' a SPECIAL type of reference type or basic expanded type?
  218. * (Note that user-defined expanded types are excluded.)
  219. */
  220. extern EIF_BOOLEAN GE_is_special_of_reference_or_basic_expanded_type_index(EIF_TYPE_INDEX a_type);
  221. #define GE_is_special_of_reference_or_basic_expanded_encoded_type(a_type) GE_is_special_of_reference_or_basic_expanded_type_index(GE_decoded_type(a_type).id)
  222. #define GE_is_special_of_reference_or_basic_expanded_object(obj) GE_is_special_of_reference_or_basic_expanded_type_index(((EIF_REFERENCE)(obj))->id)
  223. /*
  224. * Is `a_type' a TUPLE type?
  225. */
  226. #define GE_is_tuple_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_TUPLE)
  227. #define GE_is_tuple_encoded_type(a_type) GE_is_tuple_type_index(GE_decoded_type(a_type).id)
  228. #define GE_is_tuple_object(obj) GE_is_tuple_type_index(((EIF_REFERENCE)(obj))->id)
  229. /*
  230. * Is `a_type' an expanded type?
  231. */
  232. #define GE_is_expanded_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_EXPANDED)
  233. #define GE_is_expanded_encoded_type(a_type) GE_is_expanded_type_index(GE_decoded_type(a_type).id)
  234. #define GE_is_expanded_object(obj) GE_is_expanded_type_index(((EIF_REFERENCE)(obj))->id)
  235. /*
  236. * Is `a_type' a type whose base class is deferred?
  237. */
  238. #define GE_is_deferred_type_index(a_type) EIF_TEST(GE_type_infos[a_type].flags & GE_TYPE_FLAG_DEFERRED)
  239. #define GE_is_deferred_encoded_type(a_type) GE_is_deferred_type_index(GE_decoded_type(a_type).id)
  240. /*
  241. * Does `i'-th field of `a_object + a_physical_offset' (which is expected to be reference)
  242. * denote a reference with copy semantics?
  243. */
  244. extern EIF_BOOLEAN GE_is_copy_semantics_field(EIF_INTEGER i, EIF_POINTER a_object, EIF_INTEGER a_physical_offset);
  245. /*
  246. * Does `i'-th item of special `a_object' (which is expected to be reference)
  247. * denote a reference with copy semantics?
  248. */
  249. extern EIF_BOOLEAN GE_is_special_copy_semantics_item(EIF_INTEGER i, EIF_POINTER a_object);
  250. /*
  251. * Generator class name of `a_type'.
  252. */
  253. extern EIF_REFERENCE GE_generator_of_type_index(EIF_TYPE_INDEX a_type);
  254. #define GE_generator_of_encoded_type(a_type) GE_generator_of_type_index(GE_decoded_type(a_type).id)
  255. extern EIF_REFERENCE GE_generator_8_of_type_index(EIF_TYPE_INDEX a_type);
  256. #define GE_generator_8_of_encoded_type(a_type) GE_generator_8_of_type_index(GE_decoded_type(a_type).id)
  257. /*
  258. * Full name of `a_type'.
  259. */
  260. extern EIF_REFERENCE GE_generating_type_of_encoded_type(EIF_ENCODED_TYPE a_type);
  261. extern EIF_REFERENCE GE_generating_type_8_of_encoded_type(EIF_ENCODED_TYPE a_type);
  262. /*
  263. * Encoded type whose name is `a_name'.
  264. * -1 if no such type.
  265. */
  266. extern EIF_ENCODED_TYPE GE_encoded_type_from_name(EIF_POINTER a_name);
  267. /*
  268. * Does `a_type_1' conform to `a_type_2'?
  269. */
  270. extern EIF_BOOLEAN GE_encoded_type_conforms_to(EIF_ENCODED_TYPE a_type_1, EIF_ENCODED_TYPE a_type_2);
  271. /*
  272. * Number of generic parameters.
  273. */
  274. extern EIF_INTEGER GE_generic_parameter_count_of_type_index(EIF_TYPE_INDEX a_type);
  275. #define GE_generic_parameter_count_of_encoded_type(a_type) GE_generic_parameter_count_of_type_index(GE_decoded_type(a_type).id)
  276. /*
  277. * Type of `i'-th generic parameter of `a_type'.
  278. */
  279. extern EIF_INTEGER GE_generic_parameter_of_type_index(EIF_TYPE_INDEX a_type, EIF_INTEGER i);
  280. #define GE_generic_parameter_of_encoded_type(a_type,i) GE_generic_parameter_of_type_index(GE_decoded_type(a_type).id, (i))
  281. /*
  282. * Number of fields of an object of dynamic type `a_type'.
  283. */
  284. extern EIF_INTEGER GE_field_count_of_type_index(EIF_TYPE_INDEX a_type);
  285. #define GE_field_count_of_encoded_type(a_type) GE_field_count_of_type_index(GE_decoded_type(a_type).id)
  286. /*
  287. * Physical offset of the `i'-th field for an object of dynamic type `a_type'.
  288. */
  289. extern EIF_INTEGER GE_field_offset_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  290. #define GE_field_offset_of_encoded_type(i, a_type) GE_field_offset_of_type_index((i), GE_decoded_type(a_type).id)
  291. /*
  292. * Name of the `i'-th field for an object of dynamic type `a_type'.
  293. */
  294. extern EIF_POINTER GE_field_name_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  295. #define GE_field_name_of_encoded_type(i, a_type) GE_field_name_of_type_index((i), GE_decoded_type(a_type).id)
  296. /*
  297. * Static type of the `i'-th field for an object of dynamic type `a_type'.
  298. */
  299. extern EIF_INTEGER GE_field_static_type_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  300. #define GE_field_static_type_of_encoded_type(i, a_type) GE_field_static_type_of_type_index((i), GE_decoded_type(a_type).id)
  301. /*
  302. * Kind of type of the `i'-th field for an object of dynamic type `a_type'.
  303. */
  304. extern EIF_INTEGER GE_field_type_kind_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  305. #define GE_field_type_kind_of_encoded_type(i, a_type) GE_field_type_kind_of_type_index((i), GE_decoded_type(a_type).id)
  306. /*
  307. * Physical size of `a_object'.
  308. */
  309. extern EIF_NATURAL_64 GE_object_size(EIF_POINTER a_object);
  310. /*
  311. * Is `i'-th field of objects of type `a_type' a user-defined expanded attribute?
  312. */
  313. extern EIF_BOOLEAN GE_is_field_expanded_of_type_index(EIF_INTEGER i, EIF_TYPE_INDEX a_type);
  314. #define GE_is_field_expanded_of_encoded_type(i, a_type) GE_is_field_expanded_of_type_index((i), GE_decoded_type(a_type).id)
  315. #define GE_field_address_at(a_field_offset, a_object, a_physical_offset) ((char*)(a_object) + (a_physical_offset) + (a_field_offset))
  316. #define GE_object_at_offset(a_enclosing, a_physical_offset) (EIF_REFERENCE)(GE_field_address_at(0, (a_enclosing), (a_physical_offset)))
  317. #define GE_raw_object_at_offset(a_enclosing, a_physical_offset) (EIF_POINTER)(GE_field_address_at(0, (a_enclosing), (a_physical_offset)))
  318. #define GE_object_encoded_type_at_offset(a_enclosing, a_physical_offset) GE_object_encoded_type(GE_raw_object_at_offset((a_enclosing), (a_physical_offset)))
  319. #define GE_boolean_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_BOOLEAN*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  320. #define GE_character_8_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_CHARACTER_8*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  321. #define GE_character_32_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_CHARACTER_32*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  322. #define GE_integer_8_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_INTEGER_8*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  323. #define GE_integer_16_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_INTEGER_16*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  324. #define GE_integer_32_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_INTEGER_32*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  325. #define GE_integer_64_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_INTEGER_64*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  326. #define GE_natural_8_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_NATURAL_8*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  327. #define GE_natural_16_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_NATURAL_16*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  328. #define GE_natural_32_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_NATURAL_32*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  329. #define GE_natural_64_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_NATURAL_64*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  330. #define GE_pointer_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_POINTER*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  331. #define GE_real_32_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_REAL_32*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  332. #define GE_real_64_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_REAL_64*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  333. #define GE_raw_reference_field_at(a_field_offset, a_object, a_physical_offset) (EIF_POINTER)*(EIF_REFERENCE*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  334. #define GE_reference_field_at(a_field_offset, a_object, a_physical_offset) *(EIF_REFERENCE*)(GE_field_address_at((a_field_offset), (a_object), (a_physical_offset)))
  335. #define GE_set_boolean_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_boolean_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  336. #define GE_set_character_8_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_character_8_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  337. #define GE_set_character_32_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_character_32_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  338. #define GE_set_integer_8_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_integer_8_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  339. #define GE_set_integer_16_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_integer_16_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  340. #define GE_set_integer_32_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_integer_32_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  341. #define GE_set_integer_64_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_integer_64_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  342. #define GE_set_natural_8_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_natural_8_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  343. #define GE_set_natural_16_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_natural_16_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  344. #define GE_set_natural_32_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_natural_32_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  345. #define GE_set_natural_64_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_natural_64_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  346. #define GE_set_pointer_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_pointer_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  347. #define GE_set_real_32_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_real_32_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  348. #define GE_set_real_64_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_real_64_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  349. #define GE_set_reference_field_at(a_field_offset, a_object, a_physical_offset, a_value) GE_reference_field_at((a_field_offset), (a_object), (a_physical_offset)) = a_value
  350. #if defined(GE_USE_ATTRIBUTES) && defined(GE_USE_ATTRIBUTE_OFFSET)
  351. #define GE_field_address(i, a_object, a_physical_offset) GE_field_address_at(GE_type_infos[((EIF_REFERENCE)(a_object))->id].attributes[(i) - 1]->offset, (a_object), (a_physical_offset))
  352. #define GE_boolean_field(i, a_object, a_physical_offset) *(EIF_BOOLEAN*)(GE_field_address((i), (a_object), (a_physical_offset)))
  353. #define GE_character_8_field(i, a_object, a_physical_offset) *(EIF_CHARACTER_8*)(GE_field_address((i), (a_object), (a_physical_offset)))
  354. #define GE_character_32_field(i, a_object, a_physical_offset) *(EIF_CHARACTER_32*)(GE_field_address((i), (a_object), (a_physical_offset)))
  355. #define GE_integer_8_field(i, a_object, a_physical_offset) *(EIF_INTEGER_8*)(GE_field_address((i), (a_object), (a_physical_offset)))
  356. #define GE_integer_16_field(i, a_object, a_physical_offset) *(EIF_INTEGER_16*)(GE_field_address((i), (a_object), (a_physical_offset)))
  357. #define GE_integer_32_field(i, a_object, a_physical_offset) *(EIF_INTEGER_32*)(GE_field_address((i), (a_object), (a_physical_offset)))
  358. #define GE_integer_64_field(i, a_object, a_physical_offset) *(EIF_INTEGER_64*)(GE_field_address((i), (a_object), (a_physical_offset)))
  359. #define GE_natural_8_field(i, a_object, a_physical_offset) *(EIF_NATURAL_8*)(GE_field_address((i), (a_object), (a_physical_offset)))
  360. #define GE_natural_16_field(i, a_object, a_physical_offset) *(EIF_NATURAL_16*)(GE_field_address((i), (a_object), (a_physical_offset)))
  361. #define GE_natural_32_field(i, a_object, a_physical_offset) *(EIF_NATURAL_32*)(GE_field_address((i), (a_object), (a_physical_offset)))
  362. #define GE_natural_64_field(i, a_object, a_physical_offset) *(EIF_NATURAL_64*)(GE_field_address((i), (a_object), (a_physical_offset)))
  363. #define GE_pointer_field(i, a_object, a_physical_offset) *(EIF_POINTER*)(GE_field_address((i), (a_object), (a_physical_offset)))
  364. #define GE_real_32_field(i, a_object, a_physical_offset) *(EIF_REAL_32*)(GE_field_address((i), (a_object), (a_physical_offset)))
  365. #define GE_real_64_field(i, a_object, a_physical_offset) *(EIF_REAL_64*)(GE_field_address((i), (a_object), (a_physical_offset)))
  366. #define GE_reference_field(i, a_object, a_physical_offset) *(EIF_REFERENCE*)(GE_field_address((i), (a_object), (a_physical_offset)))
  367. #define GE_set_boolean_field(i, a_object, a_physical_offset, a_value) GE_boolean_field((i), (a_object), (a_physical_offset)) = (a_value)
  368. #define GE_set_character_8_field(i, a_object, a_physical_offset, a_value) GE_character_8_field((i), (a_object), (a_physical_offset)) = (a_value)
  369. #define GE_set_character_32_field(i, a_object, a_physical_offset, a_value) GE_character_32_field((i), (a_object), (a_physical_offset)) = (a_value)
  370. #define GE_set_integer_8_field(i, a_object, a_physical_offset, a_value) GE_integer_8_field((i), (a_object), (a_physical_offset)) = (a_value)
  371. #define GE_set_integer_16_field(i, a_object, a_physical_offset, a_value) GE_integer_16_field((i), (a_object), (a_physical_offset)) = (a_value)
  372. #define GE_set_integer_32_field(i, a_object, a_physical_offset, a_value) GE_integer_32_field((i), (a_object), (a_physical_offset)) = (a_value)
  373. #define GE_set_integer_64_field(i, a_object, a_physical_offset, a_value) GE_integer_64_field((i), (a_object), (a_physical_offset)) = (a_value)
  374. #define GE_set_natural_8_field(i, a_object, a_physical_offset, a_value) GE_natural_8_field((i), (a_object), (a_physical_offset)) = (a_value)
  375. #define GE_set_natural_16_field(i, a_object, a_physical_offset, a_value) GE_natural_16_field((i), (a_object), (a_physical_offset)) = (a_value)
  376. #define GE_set_natural_32_field(i, a_object, a_physical_offset, a_value) GE_natural_32_field((i), (a_object), (a_physical_offset)) = (a_value)
  377. #define GE_set_natural_64_field(i, a_object, a_physical_offset, a_value) GE_natural_64_field((i), (a_object), (a_physical_offset)) = (a_value)
  378. #define GE_set_pointer_field(i, a_object, a_physical_offset, a_value) GE_pointer_field((i), (a_object), (a_physical_offset)) = (a_value)
  379. #define GE_set_real_32_field(i, a_object, a_physical_offset, a_value) GE_real_32_field((i), (a_object), (a_physical_offset)) = (a_value)
  380. #define GE_set_real_64_field(i, a_object, a_physical_offset, a_value) GE_real_64_field((i), (a_object), (a_physical_offset)) = (a_value)
  381. #define GE_set_reference_field(i, a_object, a_physical_offset, a_value) GE_reference_field((i), (a_object), (a_physical_offset)) = (a_value)
  382. #else
  383. #define GE_boolean_field(i, a_object, a_physical_offset) (EIF_BOOLEAN)0
  384. #define GE_character_8_field(i, a_object, a_physical_offset) (EIF_CHARACTER_8)0
  385. #define GE_character_32_field(i, a_object, a_physical_offset) (EIF_CHARACTER_32)0
  386. #define GE_integer_8_field(i, a_object, a_physical_offset) (EIF_INTEGER_8)0
  387. #define GE_integer_16_field(i, a_object, a_physical_offset) (EIF_INTEGER_16)0
  388. #define GE_integer_32_field(i, a_object, a_physical_offset) (EIF_INTEGER_32)0
  389. #define GE_integer_64_field(i, a_object, a_physical_offset) (EIF_INTEGER_64)0
  390. #define GE_natural_8_field(i, a_object, a_physical_offset) (EIF_NATURAL_8)0
  391. #define GE_natural_16_field(i, a_object, a_physical_offset) (EIF_NATURAL_16)0
  392. #define GE_natural_32_field(i, a_object, a_physical_offset) (EIF_NATURAL_32)0
  393. #define GE_natural_64_field(i, a_object, a_physical_offset) (EIF_NATURAL_64)0
  394. #define GE_pointer_field(i, a_object, a_physical_offset) (EIF_POINTER)0
  395. #define GE_real_32_field(i, a_object, a_physical_offset) (EIF_REAL_32)0
  396. #define GE_real_64_field(i, a_object, a_physical_offset) (EIF_REAL_64)0
  397. #define GE_reference_field(i, a_object, a_physical_offset) (EIF_REFERENCE)0
  398. #define GE_set_boolean_field(i, a_object, a_physical_offset, a_value)
  399. #define GE_set_character_8_field(i, a_object, a_physical_offset, a_value)
  400. #define GE_set_character_32_field(i, a_object, a_physical_offset, a_value)
  401. #define GE_set_integer_8_field(i, a_object, a_physical_offset, a_value)
  402. #define GE_set_integer_16_field(i, a_object, a_physical_offset, a_value)
  403. #define GE_set_integer_32_field(i, a_object, a_physical_offset, a_value)
  404. #define GE_set_integer_64_field(i, a_object, a_physical_offset, a_value)
  405. #define GE_set_natural_8_field(i, a_object, a_physical_offset, a_value)
  406. #define GE_set_natural_16_field(i, a_object, a_physical_offset, a_value)
  407. #define GE_set_natural_32_field(i, a_object, a_physical_offset, a_value)
  408. #define GE_set_natural_64_field(i, a_object, a_physical_offset, a_value)
  409. #define GE_set_pointer_field(i, a_object, a_physical_offset, a_value)
  410. #define GE_set_real_32_field(i, a_object, a_physical_offset, a_value)
  411. #define GE_set_real_64_field(i, a_object, a_physical_offset, a_value)
  412. #define GE_set_reference_field(i, a_object, a_physical_offset, a_value)
  413. #endif
  414. /*
  415. * Number of non-transient fields of an object of dynamic type `a_type'.
  416. * TODO: storable not implemented yet.
  417. */
  418. #define GE_persistent_field_count_of_type_index(a_type) GE_field_count_of_type_index(a_type)
  419. #define GE_persistent_field_count_of_encoded_type(a_type) GE_persistent_field_count_of_type_index(GE_decoded_type(a_type).id)
  420. /*
  421. * Is `i'-th field of objects of type `a_type' a transient field?
  422. * TODO: storable not implemented yet.
  423. */
  424. #define GE_is_field_transient_of_type_index(i, a_type) EIF_FALSE
  425. #define GE_is_field_transient_of_encoded_type(i, a_type) GE_is_field_transient_of_type_index((i), GE_decoded_type(a_type).id)
  426. /*
  427. * Storable version of objects of type `a_type'.
  428. * TODO: storable not implemented yet.
  429. */
  430. #define GE_storable_version_of_type_index(a_type) EIF_VOID
  431. #define GE_storable_version_of_encoded_type(a_type) GE_storable_version_of_type_index(GE_decoded_type(a_type).id)
  432. /*
  433. * Get a lock on `GE_mark_object' and `GE_unmark_object' routines so that
  434. * 2 threads cannot `GE_mark_object' and `GE_unmark_object' at the same time.
  435. */
  436. extern void GE_lock_marking(void);
  437. /*
  438. * Release a lock on `GE_mark_object' and `GE_unmark_object', so that another
  439. * thread can use `GE_mark_object' and `GE_unmark_object'.
  440. */
  441. extern void GE_unlock_marking(void);
  442. /*
  443. * Is `obj' marked?
  444. */
  445. extern EIF_BOOLEAN GE_is_object_marked(EIF_POINTER obj);
  446. /*
  447. * Mark `obj'.
  448. */
  449. extern void GE_mark_object(EIF_POINTER obj);
  450. /*
  451. * Unmark `obj'.
  452. */
  453. extern void GE_unmark_object(EIF_POINTER obj);
  454. /*
  455. * New instance of dynamic `a_type'.
  456. * Note: returned object is not initialized and may
  457. * hence violate its invariant.
  458. * `a_type' cannot represent a SPECIAL type, use
  459. * `GE_new_special_of_reference_instance_of_type_index' instead.
  460. */
  461. extern EIF_REFERENCE GE_new_instance_of_type_index(EIF_TYPE_INDEX a_type);
  462. #define GE_new_instance_of_encoded_type(a_type) GE_new_instance_of_type_index(GE_decoded_type(a_type).id)
  463. /*
  464. * New instance of dynamic `a_type' that represents
  465. * a SPECIAL with can contain `a_capacity' elements of reference type.
  466. * To create a SPECIAL of basic type, use class SPECIAL directly.
  467. */
  468. extern EIF_REFERENCE GE_new_special_of_reference_instance_of_type_index(EIF_TYPE_INDEX a_type, EIF_INTEGER a_capacity);
  469. #define GE_new_special_of_reference_instance_of_encoded_type(a_type, a_capacity) GE_new_special_of_reference_instance_of_type_index(GE_decoded_type(a_type).id, (a_capacity))
  470. /*
  471. * New instance of tuple of type `a_type'.
  472. * Note: returned object is not initialized and may
  473. * hence violate its invariant.
  474. */
  475. #define GE_new_tuple_instance_of_type_index(a_type) GE_new_instance_of_type_index(a_type)
  476. #define GE_new_tuple_instance_of_encoded_type(a_type) GE_new_tuple_instance_of_type_index(GE_decoded_type(a_type).id)
  477. /*
  478. * New instance of TYPE for object of type `a_type'.
  479. */
  480. extern EIF_REFERENCE GE_new_type_instance_of_encoded_type(EIF_ENCODED_TYPE a_type);
  481. #ifdef __cplusplus
  482. }
  483. #endif
  484. #endif