gc: add Nit GC
[nit.git] / clib / nit_common.h
index c3b056f..8bf9cfc 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
-#ifdef WITH_LIBGC
-#include <gc/gc.h>
-#define malloc(x) GC_MALLOC((x))
-#define calloc(x,y) GC_MALLOC((x)*(y))
-#endif
-
-
-
 /* *** Types *** */
 typedef signed long int bigint;        /* standard int value, must be larger that any poiner */
 typedef bigint (*fun_t) (bigint);                                      /* generic function pointer */
@@ -33,6 +25,7 @@ typedef bigint cid_t;                                 /* class identifier */
 typedef bigint val_t;  /* value (everything is a val_t) */
 typedef union obj_tu {union classtable_elt_tu * vft; bigint object_id; val_t objectSize;} *obj_t; /* standard object */
 typedef union classtable_elt_tu { bigint i; fun_t f; cid_t cid;} classtable_elt_t;     /* classtable element */
+typedef struct Nit_NativeArray {const classtable_elt_t * vft; bigint object_id; bigint size; val_t val[1];} * Nit_NativeArray;
 
 typedef classtable_elt_t * classtable_t;                       /* classtable */
 
@@ -86,6 +79,7 @@ extern bigint object_id_counter;
 
 #define ISOBJ(x) (TAG((x)) == OBJTAG)
 #define VAL2OBJ(x) ((obj_t)(x))
+#define VAL2ARRAY(x) ((Nit_NativeArray)(x))
 #define OBJ2VAL(o) ((val_t)(o))
 #define VAL2VFT(x) (ISOBJ(x) ? VAL2OBJ(x)->vft : TAG2VFT[TAG(x)])
 /*#define VAL2CID(x) (ISOBJ(x) ? (VAL2OBJ(x)->vft->cid) : (-TAG(x)))*/
@@ -97,6 +91,7 @@ extern bigint object_id_counter;
 /* Equal comparaison */
 /* O = Non nil object ; N = Object or nil ; P = Primitive */
 #define OBJ_IS_BOX(x) ((VAL2OBJ(x)->vft->i) < 0)
+#define OBJ_IS_ARRAY(x) ((VAL2ARRAY(x)->vft[1].i) == -1)
 #define IS_BOX(x) (ISOBJ(x) && OBJ_IS_BOX(x))
 #define IS_EQUAL_BOX(x, y) (ISOBJ(y) && (VAL2OBJ(x)[2].vft==VAL2OBJ(y)[2].vft) && (VAL2OBJ(x)->vft==VAL2OBJ(y)->vft))
 #define IS_EQUAL_OO(x, y) ((x)==(y) || (IS_BOX(x) && IS_EQUAL_BOX((x), (y))))
@@ -113,7 +108,11 @@ extern bigint object_id_counter;
 
 #define VAL_ISA(e, c, i) (VAL2VFT((e))[(c)].cid == (cid_t)(i))
 
-void * alloc(size_t);
+/* GC and memory management */
+void *alloc(size_t); /* allocate memory to store an object with an object header */
+void *raw_alloc(size_t); /* allocate raw memory to store a raw stram of byte */
+void register_static_object(val_t*); /* mark that something is a global or once object */
+
 extern val_t G_args;
 extern val_t G_stdin;
 extern val_t G_stdout;
@@ -128,6 +127,8 @@ struct trace_t {
        const char *file; /* source filename */
        int line; /* line number */
        const char *meth; /* method name */
+       int REG_size;
+       val_t **REG_pointer;
 };
 extern struct trace_t *tracehead;
 typedef enum {true = (1==1),false = (0==1)} bool;