compile: store instance size in class table
[nit.git] / 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