# HG changeset patch # User Paul Boddie # Date 1266787568 -3600 # Node ID 7dc22ce269e10f72db404212136c484975ce60f8 # Parent 505512c40ea55c716f9ace2a66c07f86f300d093 Added a CheckType instruction for specific class membership testing. diff -r 505512c40ea5 -r 7dc22ce269e1 micropython/data.py --- a/micropython/data.py Mon Feb 15 01:35:17 2010 +0100 +++ b/micropython/data.py Sun Feb 21 22:26:08 2010 +0100 @@ -387,13 +387,20 @@ all_users = self.all_attribute_users[-1] speculative = self.speculative_attributes[-1] - # This node overrides previous definitions. + # Record the current name usage as speculative since it will not be + # propagated any further. if not speculative.has_key(name): speculative[name] = defs.get(name, set()) + + # Where speculative usage has already been recorded, just note the usage + # for coverage purposes. + else: self.all_usage_shelves[-1].append({name : defs[name]}) + # This node overrides previous definitions. + all_users[name] = set([node]) users[name] = set([node]) defs[name] = set() diff -r 505512c40ea5 -r 7dc22ce269e1 micropython/rsvp.py --- a/micropython/rsvp.py Mon Feb 15 01:35:17 2010 +0100 +++ b/micropython/rsvp.py Sun Feb 21 22:26:08 2010 +0100 @@ -3,7 +3,7 @@ """ RSVP instruction and serialisation classes. -Copyright (C) 2007, 2008, 2009 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -433,7 +433,9 @@ class CheckContext(Instruction): "Check to see if the context is valid." class CheckClass(Instruction): "Check the current value to determine whether it is a class." -class CheckInstance(Instruction): "Check the current value as an instance of a specific class (used with 'self' in an invocation)." +class CheckInstance(Instruction): """Check the current value as an instance of a class or its subclasses (used with 'self' in an + invocation).""" +class CheckType(Instruction): "Check the current value as an instance of a specific class only." # Access to frames upon invocation. @@ -499,7 +501,7 @@ TestIdentity, TestIdentityAddress, CheckInstance, # as one of the operands CheckException, CheckFrame, FillDefaults, MakeInstance, - CheckContext, CheckClass, + CheckContext, CheckClass, CheckType, LoadContext # as the object providing the result ) diff -r 505512c40ea5 -r 7dc22ce269e1 rsvp.py --- a/rsvp.py Mon Feb 15 01:35:17 2010 +0100 +++ b/rsvp.py Sun Feb 21 22:26:08 2010 +0100 @@ -5,7 +5,7 @@ ignore low-level operations and merely concentrate on variable access, structure access, structure allocation and function invocations. -Copyright (C) 2007, 2008, 2009 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -662,6 +662,11 @@ self.status = self._CheckInstance(value.ref, target_value.ref) + def CheckType(self): + value = self.value + target_value = self.operand + self.status = self._CheckType(value.ref, target_value.ref) + def JumpInFrame(self): codeaddr = self.callable return self.jump(codeaddr, self.pc + 1) # return to the instruction after this one @@ -770,6 +775,22 @@ else: return 0 + def _CheckType(self, ref, cls): + data = self.load(ref) + target_data = self.load(cls) + + # Insist on instance vs. class. + + if data.attrcode is None: # absent attrcode == class/module + return 0 + + if target_data.attrcode is not None: # present attrcode == instance + return 0 + + # Return whether the types match. + + return data.classcode == target_data.classcode + def _MakeObject(self, size, ref): # Load the template. data = self.load(ref)