17 #include "gc_chooser.h"
19 #include <TargetConditionals.h>
21 #include <libkern/OSByteOrder.h>
22 #define be32toh(x) OSSwapBigToHostInt32(x)
25 #define be32toh(val) _byteswap_ulong(val)
28 #define be16toh(val) (((val) >> 8) | ((val) << 8))
29 #define be32toh(val) ((be16toh((val) << 16) | (be16toh((val) >> 16))))
33 #define be32toh(val) betoh32(val)
35 #include <android/log.h>
36 #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, "Nit", __VA_ARGS__)
37 #elif TARGET_OS_IPHONE
38 #define PRINT_ERROR(...) syslog(LOG_ERR, __VA_ARGS__)
40 #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)
42 typedef void(*nitmethod_t
)(void); /* general C type representing a Nit method. */
56 } nitattribute_t
; /* general C type representing a Nit attribute. */
57 struct class { int box_kind
; nitmethod_t vft
[]; }; /* general C type representing a Nit class. */
58 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. */
59 struct instance
{ const struct type
*type
; const struct class *class; nitattribute_t attrs
[]; }; /* general C type representing a Nit instance. */
60 struct types
{ int dummy
; const struct type
*types
[]; }; /* a list types (used for vts, fts and unresolved lists). */
61 typedef struct instance val
; /* general C type representing a Nit instance. */
62 extern const struct class *class_info
[];
63 extern const struct type
*type_info
[];
64 struct nitni_instance
{
65 struct nitni_instance
*next
,
66 *prev
; /* adjacent global references in global list */
67 int count
; /* number of time this global reference has been marked */
68 struct instance
*value
;
71 /* Native reference to Nit objects */
72 /* This structure is used to represent every Nit type in extern methods and custom C code. */
74 struct nitni_ref
*next
,
75 *prev
; /* adjacent global references in global list */
76 int count
; /* number of time this global reference has been marked */
79 /* List of global references from C code to Nit objects */
80 /* Instanciated empty at init of Nit system and filled explicitly by user in C code */
81 struct nitni_global_ref_list_t
{
82 struct nitni_ref
*head
, *tail
;
84 extern struct nitni_global_ref_list_t
*nitni_global_ref_list
;
86 /* Initializer of global reference list */
87 extern void nitni_global_ref_list_init();
89 /* Intern function to add a global reference to the list */
90 extern void nitni_global_ref_add( struct nitni_ref
*ref
);
92 /* Intern function to remove a global reference from the list */
93 extern void nitni_global_ref_remove( struct nitni_ref
*ref
);
95 /* Increase count on an existing global reference */
96 extern void nitni_global_ref_incr( struct nitni_ref
*ref
);
98 /* Decrease count on an existing global reference */
99 extern void nitni_global_ref_decr( struct nitni_ref
*ref
);
101 struct catch_stack_t
{
105 extern struct catch_stack_t catchStack
;
107 void fatal_exit(int) __attribute__ ((noreturn
));
108 #define likely(x) __builtin_expect((x),1)
109 #define unlikely(x) __builtin_expect((x),0)
110 extern int glob_argc
;
111 extern char **glob_argv
;
112 extern val
*glob_sys
;
113 struct instance_core__CString
{
114 const struct type
*type
;
115 const struct class *class;
118 struct instance_core__Float
{
119 const struct type
*type
;
120 const struct class *class;
123 struct instance_core__Byte
{
124 const struct type
*type
;
125 const struct class *class;
128 struct instance_core__Pointer
{
129 const struct type
*type
;
130 const struct class *class;
133 struct instance_core__NativeArray
{
134 const struct type
*type
;
135 const struct class *class;
139 struct instance_core__Int8
{
140 const struct type
*type
;
141 const struct class *class;
144 struct instance_core__Int16
{
145 const struct type
*type
;
146 const struct class *class;
149 struct instance_core__UInt16
{
150 const struct type
*type
;
151 const struct class *class;
154 struct instance_core__Int32
{
155 const struct type
*type
;
156 const struct class *class;
159 struct instance_core__UInt32
{
160 const struct type
*type
;
161 const struct class *class;