15 #include "gc_chooser.h"
17 #include <libkern/OSByteOrder.h>
18 #define be32toh(x) OSSwapBigToHostInt32(x)
21 #define be16toh(val) (((val) >> 8) | ((val) << 8))
22 #define be32toh(val) ((be16toh((val) << 16) | (be16toh((val) >> 16))))
25 #define be32toh(val) betoh32(val)
26 #include <android/log.h>
27 #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, "Nit", __VA_ARGS__)
29 #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)
31 typedef void(*nitmethod_t
)(void); /* general C type representing a Nit method. */
45 } nitattribute_t
; /* general C type representing a Nit attribute. */
46 struct class { int box_kind
; nitmethod_t vft
[]; }; /* general C type representing a Nit class. */
47 struct type
{ int id
; const char *name
; int color
; short int is_nullable
; const struct types
*resolution_table
; int table_size
; int type_table
[]; }; /* general C type representing a Nit type. */
48 struct instance
{ const struct type
*type
; const struct class *class; nitattribute_t attrs
[]; }; /* general C type representing a Nit instance. */
49 struct types
{ int dummy
; const struct type
*types
[]; }; /* a list types (used for vts, fts and unresolved lists). */
50 typedef struct instance val
; /* general C type representing a Nit instance. */
51 extern const struct class *class_info
[];
52 extern const struct type
*type_info
[];
53 struct nitni_instance
{
54 struct nitni_instance
*next
,
55 *prev
; /* adjacent global references in global list */
56 int count
; /* number of time this global reference has been marked */
57 struct instance
*value
;
60 /* Native reference to Nit objects */
61 /* This structure is used to represent every Nit type in extern methods and custom C code. */
63 struct nitni_ref
*next
,
64 *prev
; /* adjacent global references in global list */
65 int count
; /* number of time this global reference has been marked */
68 /* List of global references from C code to Nit objects */
69 /* Instanciated empty at init of Nit system and filled explicitly by user in C code */
70 struct nitni_global_ref_list_t
{
71 struct nitni_ref
*head
, *tail
;
73 extern struct nitni_global_ref_list_t
*nitni_global_ref_list
;
75 /* Initializer of global reference list */
76 extern void nitni_global_ref_list_init();
78 /* Intern function to add a global reference to the list */
79 extern void nitni_global_ref_add( struct nitni_ref
*ref
);
81 /* Intern function to remove a global reference from the list */
82 extern void nitni_global_ref_remove( struct nitni_ref
*ref
);
84 /* Increase count on an existing global reference */
85 extern void nitni_global_ref_incr( struct nitni_ref
*ref
);
87 /* Decrease count on an existing global reference */
88 extern void nitni_global_ref_decr( struct nitni_ref
*ref
);
90 void fatal_exit(int) __attribute__ ((noreturn
));
91 #define likely(x) __builtin_expect((x),1)
92 #define unlikely(x) __builtin_expect((x),0)
94 extern char **glob_argv
;
96 struct instance_core__NativeString
{
97 const struct type
*type
;
98 const struct class *class;
101 struct instance_core__Float
{
102 const struct type
*type
;
103 const struct class *class;
106 struct instance_core__Byte
{
107 const struct type
*type
;
108 const struct class *class;
111 struct instance_core__Pointer
{
112 const struct type
*type
;
113 const struct class *class;
116 struct instance_core__NativeArray
{
117 const struct type
*type
;
118 const struct class *class;
122 struct instance_core__Int8
{
123 const struct type
*type
;
124 const struct class *class;
127 struct instance_core__Int16
{
128 const struct type
*type
;
129 const struct class *class;
132 struct instance_core__UInt16
{
133 const struct type
*type
;
134 const struct class *class;
137 struct instance_core__Int32
{
138 const struct type
*type
;
139 const struct class *class;
142 struct instance_core__UInt32
{
143 const struct type
*type
;
144 const struct class *class;