compile: store instance size in class table
authorJulien Chevalier <chevjulien@gmail.com>
Fri, 14 Aug 2009 16:49:04 +0000 (12:49 -0400)
committerJean Privat <jean@pryen.org>
Mon, 17 Aug 2009 20:15:29 +0000 (16:15 -0400)
This new information can be used by GC to visit the attributes of an object.

Signed-off-by: Julien Chevalier <chevjulien@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiling/compiling_global.nit

index 23f5791..2a686f2 100644 (file)
@@ -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