misc/vim: inform the user when no results are found
[nit.git] / c_src / nit.common.h
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include "gc_chooser.h"
5 #ifdef ANDROID
6 #include <android/log.h>
7 #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, "Nit", __VA_ARGS__)
8 #else
9 #define PRINT_ERROR(...) fprintf(stderr, __VA_ARGS__)
10 #endif
11 typedef void(*nitmethod_t)(void); /* general C type representing a Nit method. */
12 typedef union {
13 void* val;
14 long l;
15 short int s;
16 char c;
17 double d;
18 void* str;
19 } nitattribute_t; /* general C type representing a Nit attribute. */
20 struct class { int box_kind; nitmethod_t vft[]; }; /* general C type representing a Nit class. */
21 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. */
22 struct instance { const struct type *type; const struct class *class; nitattribute_t attrs[]; }; /* general C type representing a Nit instance. */
23 struct types { int dummy; const struct type *types[]; }; /* a list types (used for vts, fts and unresolved lists). */
24 typedef struct instance val; /* general C type representing a Nit instance. */
25 struct nitni_instance {
26 struct nitni_instance *next,
27 *prev; /* adjacent global references in global list */
28 int count; /* number of time this global reference has been marked */
29 struct instance *value;
30 };
31
32 /* Native reference to Nit objects */
33 /* This structure is used to represent every Nit type in extern methods and custom C code. */
34 struct nitni_ref {
35 struct nitni_ref *next,
36 *prev; /* adjacent global references in global list */
37 int count; /* number of time this global reference has been marked */
38 };
39
40 /* List of global references from C code to Nit objects */
41 /* Instanciated empty at init of Nit system and filled explicitly by user in C code */
42 struct nitni_global_ref_list_t {
43 struct nitni_ref *head, *tail;
44 };
45 extern struct nitni_global_ref_list_t *nitni_global_ref_list;
46
47 /* Initializer of global reference list */
48 extern void nitni_global_ref_list_init();
49
50 /* Intern function to add a global reference to the list */
51 extern void nitni_global_ref_add( struct nitni_ref *ref );
52
53 /* Intern function to remove a global reference from the list */
54 extern void nitni_global_ref_remove( struct nitni_ref *ref );
55
56 /* Increase count on an existing global reference */
57 extern void nitni_global_ref_incr( struct nitni_ref *ref );
58
59 /* Decrease count on an existing global reference */
60 extern void nitni_global_ref_decr( struct nitni_ref *ref );
61
62 void show_backtrace(int) __attribute__ ((noreturn));
63 #define likely(x) __builtin_expect((x),1)
64 #define unlikely(x) __builtin_expect((x),0)
65 extern int glob_argc;
66 extern char **glob_argv;
67 extern val *glob_sys;
68 struct instance_standard__NativeString {
69 const struct type *type;
70 const struct class *class;
71 void* value;
72 };
73 struct instance_standard__Bool {
74 const struct type *type;
75 const struct class *class;
76 short int value;
77 };
78 struct instance_standard__Float {
79 const struct type *type;
80 const struct class *class;
81 double value;
82 };
83 struct instance_standard__Int {
84 const struct type *type;
85 const struct class *class;
86 long value;
87 };
88 struct instance_standard__Char {
89 const struct type *type;
90 const struct class *class;
91 char value;
92 };
93 struct instance_standard__Pointer {
94 const struct type *type;
95 const struct class *class;
96 void* value;
97 };
98 struct instance_standard__NativeArray {
99 const struct type *type;
100 const struct class *class;
101 int length;
102 val* values[0];
103 };