nitvm: Handles isset expression
authorJulien Pagès <julien.projet@gmail.com>
Sun, 14 Sep 2014 10:31:17 +0000 (12:31 +0200)
committerJulien Pagès <julien.projet@gmail.com>
Sun, 14 Sep 2014 10:31:17 +0000 (12:31 +0200)
Signed-off-by: Julien Pagès <julien.projet@gmail.com>

src/vm.nit

index 92d2d1f..a58a4a8 100644 (file)
@@ -239,6 +239,21 @@ class VirtualMachine super NaiveInterpreter
                ((Instance *)instance)[absolute_offset + offset] = value;
                Instance_incr_ref(value);
        `}
+
+       # Is the attribute `mproperty` initialized in the instance `recv`?
+       redef fun isset_attribute(mproperty: MAttribute, recv: Instance): Bool
+       do
+               assert recv isa MutableInstance
+
+               # Read the attribute value with internal perfect hashing read
+               # because we do not want to throw an error if the value is `initialization_value`
+               var id = mproperty.intro_mclassdef.mclass.vtable.id
+
+               var i = read_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable,
+                                       recv.vtable.mask, id, mproperty.offset)
+
+               return i != initialization_value
+       end
 end
 
 redef class MClass