From ac7f2c9d5921b9d43a899c6fe1a354da56f733fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julien=20Pag=C3=A8s?= Date: Sun, 14 Sep 2014 12:31:17 +0200 Subject: [PATCH] nitvm: Handles isset expression MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Pagès --- src/vm.nit | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/vm.nit b/src/vm.nit index 92d2d1f..a58a4a8 100644 --- a/src/vm.nit +++ b/src/vm.nit @@ -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 -- 1.7.9.5