From af2a5372072e80113bf9a8d9d788ab1ab7a5f13b Mon Sep 17 00:00:00 2001 From: Julien Chevalier Date: Fri, 14 Aug 2009 12:49:04 -0400 Subject: [PATCH] compile: store instance size in class table This new information can be used by GC to visit the attributes of an object. Signed-off-by: Julien Chevalier Signed-off-by: Jean Privat --- src/compiling/compiling_global.nit | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/compiling/compiling_global.nit b/src/compiling/compiling_global.nit index 23f5791..2a686f2 100644 --- a/src/compiling/compiling_global.nit +++ b/src/compiling/compiling_global.nit @@ -177,6 +177,7 @@ redef class MMModule var itab = new Array[TableElt] ctab.add(new TableEltClassSelfId) + ctab.add(new TableEltClassObjectSize) itab.add(new TableEltVftPointer) itab.add(new TableEltObjectId) @@ -770,6 +771,28 @@ special TableElt end end + +# The element that represent the Object Size +class TableEltClassObjectSize +special TableElt + redef fun is_related_to(c) do return true + redef fun compile_to_c(v, c) + do + var nb = 0 + var ga = v.global_analysis + if c.name == "NativeArray".to_symbol then + nb = -1 + else + var cc = ga.compiled_classes[c.global] + var itab = cc.instance_table + for e in itab do + nb += 1 + end + end + return "{nb} /* {ga.color(self)}: Object size (-1 if a NativeArray)*/" + end +end + # The element that represent the object id class TableEltObjectId special TableElt -- 1.7.9.5