From: Julien Chevalier Date: Fri, 14 Aug 2009 16:49:04 +0000 (-0400) Subject: compile: store instance size in class table X-Git-Tag: v0.3~51 X-Git-Url: http://nitlanguage.org 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 --- 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