Warning: now, two objects of the same class can have the same object_id.
It is unlikely, but possible.
Trivially-hacked-by: Jean Privat <jean@pryen.org>
Signed-off-by: Julien Chevalier <chevjulien@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>
typedef bigint (*fun_t) (bigint); /* generic function pointer */
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; val_t attr;} *obj_t; /* standard object */
+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 classtable_elt_t * classtable_t; /* classtable */
+extern bigint object_id_counter;
+
/*****************************************************************************
* Types macros (primitive and less primitives) ******************************
*****************************************************************************
/* O = Non nil object ; N = Object or nil ; P = Primitive */
#define OBJ_IS_BOX(x) ((VAL2OBJ(x)->vft->i) < 0)
#define IS_BOX(x) (ISOBJ(x) && OBJ_IS_BOX(x))
-#define IS_EQUAL_BOX(x, y) (ISOBJ(y) && (VAL2OBJ(x)[1].vft==VAL2OBJ(y)[1].vft) && (VAL2OBJ(x)->vft==VAL2OBJ(y)->vft))
+#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))))
#define IS_EQUAL_ON(x, y) ((x)==(y) || (IS_BOX(x) && !ISNULL(y) && IS_EQUAL_BOX((x), (y))))
#define IS_EQUAL_NN(x, y) ((x)==(y) || (!ISNULL(x) && IS_BOX(x) && !ISNULL(y) && IS_EQUAL_BOX((x), (y))))
#include "nit_common.h"
#include <signal.h>
#include <stdarg.h>
+bigint object_id_counter = 1000000;
#ifdef WITH_LIBGC
#define GC_DEBUG
ctab.add(new TableEltClassSelfId)
itab.add(new TableEltVftPointer)
+ itab.add(new TableEltObjectId)
var pclassid = -1
var classid = 3
end
end
+# The element that represent the object id
+class TableEltObjectId
+special TableElt
+ redef fun is_related_to(c) do return true
+ redef fun compile_to_c(v, c)
+ do
+ var ga = v.global_analysis
+ return "/* {ga.color(self)}: Object_id */"
+ end
+end
+
# The element that
class TableEltVftPointer
special TableElt
else if not pi.tagged then
var t = pi.cname
var tbox = "struct TBOX_{name}"
- v.add_decl("{tbox} \{ const classtable_elt_t * vft; {t} val;};")
+ v.add_decl("{tbox} \{ const classtable_elt_t * vft; bigint object_id; {t} val;};")
v.add_decl("val_t BOX_{name}({t} val);")
v.add_decl("#define UNBOX_{name}(x) ((({tbox} *)(VAL2OBJ(x)))->val)")
end
v.add_decl("obj_t obj;")
v.add_instr("obj = alloc(sizeof(val_t) * {itab.length});")
v.add_instr("obj->vft = (classtable_elt_t*)VFT_{name};")
+ v.add_instr("obj[1].object_id = object_id_counter;")
+ v.add_instr("object_id_counter = object_id_counter + 1;")
var r = iroutine.compile_to_c(v, cname, args).as(not null)
v.add_instr("return {r};")
ctx_old.append(v.ctx)
v.add_instr("{tbox} *box = ({tbox}*)alloc(sizeof({tbox}));")
v.add_instr("box->vft = VFT_{name};")
v.add_instr("box->val = val;")
+ v.add_instr("box->object_id = object_id_counter;")
+ v.add_instr("object_id_counter = object_id_counter + 1;")
v.add_instr("return OBJ2VAL(box);")
v.unindent
v.add_instr("}")
s = "(void)memcpy(UNBOX_NativeString(@@@)+UNTAG_Int(@@@), UNBOX_NativeString(@@@)+UNTAG_Int(@@@), UNTAG_Int(@@@));"
end
else if n == once "object_id".to_symbol then
- s = "TAG_Int((bigint)@@@)"
+ s = "TAG_Int((bigint)((obj_t)@@@)[1].object_id)"
else if n == once "sys".to_symbol then
s = "(G_sys)"
else if n == once "is_same_type".to_symbol then