<s> from pypy . annotation import model as annmodel <EOL> from pypy . tool . pairtype import pairtype <EOL> from pypy . annotation . binaryop import _make_none_union , SomePBC <EOL> from pypy . annotation . bookkeeper import getbookkeeper <EOL> from pypy . rpython . extregistry import ExtRegistryEntry <EOL> from pypy . rpython . annlowlevel import cachedtype <EOL> from pypy . rpython . error import TyperError <EOL> class ControllerEntry ( ExtRegistryEntry ) : <EOL> def compute_result_annotation ( self , * args_s , ** kwds_s ) : <EOL> controller = self . getcontroller ( * args_s , ** kwds_s ) <EOL> return controller . ctrl_new_ex ( self . bookkeeper , * args_s , ** kwds_s ) <EOL> def getcontroller ( self , * args_s , ** kwds_s ) : <EOL> return self . _controller_ ( ) <EOL> def specialize_call ( self , hop , ** kwds_i ) : <EOL> if hop . s_result == annmodel . s_ImpossibleValue : <EOL> raise TyperError ( "<STR_LIT>" % ( <EOL> hop . spaceop , ) ) <EOL> controller = hop . s_result . controller <EOL> return controller . rtype_new ( hop , ** kwds_i ) <EOL> def controlled_instance_box ( controller , obj ) : <EOL> XXX <EOL> def controlled_instance_unbox ( controller , obj ) : <EOL> XXX <EOL> def controlled_instance_is_box ( controller , obj ) : <EOL> XXX <EOL> class ControllerEntryForPrebuilt ( ExtRegistryEntry ) : <EOL> def compute_annotation ( self ) : <EOL> controller = self . getcontroller ( ) <EOL> real_obj = controller . convert ( self . instance ) <EOL> s_real_obj = self . bookkeeper . immutablevalue ( real_obj ) <EOL> return SomeControlledInstance ( s_real_obj , controller ) <EOL> def getcontroller ( self ) : <EOL> return self . _controller_ ( ) <EOL> class Controller ( object ) : <EOL> __metaclass__ = cachedtype <EOL> can_be_None = False <EOL> def _freeze_ ( self ) : <EOL> return True <EOL> def box ( self , obj ) : <EOL> return controlled_instance_box ( self , obj ) <EOL> box . _annspecialcase_ = '<STR_LIT>' <EOL> def unbox ( self , obj ) : <EOL> return controlled_instance_unbox ( self , obj ) <EOL> unbox . _annspecialcase_ = '<STR_LIT>' <EOL> def is_box ( self , obj ) : <EOL> return controlled_instance_is_box ( self , obj ) <EOL> is_box . _annspecialcase_ = '<STR_LIT>' <EOL> def ctrl_new ( self , * args_s , ** kwds_s ) : <EOL> if kwds_s : <EOL> raise TypeError ( "<STR_LIT>" % ( <EOL> self . new , ) ) <EOL> s_real_obj = delegate ( self . new , * args_s ) <EOL> if s_real_obj == annmodel . s_ImpossibleValue : <EOL> return annmodel . s_ImpossibleValue <EOL> else : <EOL> return SomeControlledInstance ( s_real_obj , controller = self ) <EOL> def ctrl_new_ex ( self , bookkeeper , * args_s , ** kwds_s ) : <EOL> return self . ctrl_new ( * args_s , ** kwds_s ) <EOL> def rtype_new ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . new , hop , revealargs = [ ] , revealresult = True ) <EOL> def getattr ( self , obj , attr ) : <EOL> return getattr ( self , '<STR_LIT>' + attr ) ( obj ) <EOL> getattr . _annspecialcase_ = '<STR_LIT>' <EOL> def ctrl_getattr ( self , s_obj , s_attr ) : <EOL> return delegate ( self . getattr , s_obj , s_attr ) <EOL> def rtype_getattr ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . getattr , hop ) <EOL> def setattr ( self , obj , attr , value ) : <EOL> return getattr ( self , '<STR_LIT>' + attr ) ( obj , value ) <EOL> setattr . _annspecialcase_ = '<STR_LIT>' <EOL> def ctrl_setattr ( self , s_obj , s_attr , s_value ) : <EOL> return delegate ( self . setattr , s_obj , s_attr , s_value ) <EOL> def rtype_setattr ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . setattr , hop ) <EOL> def ctrl_getitem ( self , s_obj , s_key ) : <EOL> return delegate ( self . getitem , s_obj , s_key ) <EOL> def rtype_getitem ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . getitem , hop ) <EOL> def ctrl_setitem ( self , s_obj , s_key , s_value ) : <EOL> return delegate ( self . setitem , s_obj , s_key , s_value ) <EOL> def rtype_setitem ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . setitem , hop ) <EOL> def ctrl_delitem ( self , s_obj , s_key ) : <EOL> return delegate ( self . delitem , s_obj , s_key ) <EOL> def rtype_delitem ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . delitem , hop ) <EOL> def ctrl_is_true ( self , s_obj ) : <EOL> return delegate ( self . is_true , s_obj ) <EOL> def rtype_is_true ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . is_true , hop ) <EOL> def ctrl_call ( self , s_obj , * args_s ) : <EOL> return delegate ( self . call , s_obj , * args_s ) <EOL> def rtype_call ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import rtypedelegate <EOL> return rtypedelegate ( self . call , hop ) <EOL> def delegate ( boundmethod , * args_s ) : <EOL> bk = getbookkeeper ( ) <EOL> s_meth = bk . immutablevalue ( boundmethod ) <EOL> return bk . emulate_pbc_call ( bk . position_key , s_meth , args_s , <EOL> callback = bk . position_key ) <EOL> class BoxEntry ( ExtRegistryEntry ) : <EOL> _about_ = controlled_instance_box <EOL> def compute_result_annotation ( self , s_controller , s_real_obj ) : <EOL> if s_real_obj == annmodel . s_ImpossibleValue : <EOL> return annmodel . s_ImpossibleValue <EOL> else : <EOL> assert s_controller . is_constant ( ) <EOL> controller = s_controller . const <EOL> return SomeControlledInstance ( s_real_obj , controller = controller ) <EOL> def specialize_call ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import ControlledInstanceRepr <EOL> if not isinstance ( hop . r_result , ControlledInstanceRepr ) : <EOL> raise TyperError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( hop . r_result , ) ) <EOL> hop . exception_cannot_occur ( ) <EOL> return hop . inputarg ( hop . r_result . r_real_obj , arg = <NUM_LIT:1> ) <EOL> class UnboxEntry ( ExtRegistryEntry ) : <EOL> _about_ = controlled_instance_unbox <EOL> def compute_result_annotation ( self , s_controller , s_obj ) : <EOL> if s_obj == annmodel . s_ImpossibleValue : <EOL> return annmodel . s_ImpossibleValue <EOL> else : <EOL> assert isinstance ( s_obj , SomeControlledInstance ) <EOL> return s_obj . s_real_obj <EOL> def specialize_call ( self , hop ) : <EOL> from pypy . rpython . rcontrollerentry import ControlledInstanceRepr <EOL> if not isinstance ( hop . args_r [ <NUM_LIT:1> ] , ControlledInstanceRepr ) : <EOL> raise TyperError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( hop . args_r [ <NUM_LIT:1> ] , ) ) <EOL> hop . exception_cannot_occur ( ) <EOL> v = hop . inputarg ( hop . args_r [ <NUM_LIT:1> ] , arg = <NUM_LIT:1> ) <EOL> return hop . llops . convertvar ( v , hop . args_r [ <NUM_LIT:1> ] . r_real_obj , hop . r_result ) <EOL> class IsBoxEntry ( ExtRegistryEntry ) : <EOL> _about_ = controlled_instance_is_box <EOL> def compute_result_annotation ( self , s_controller , s_obj ) : <EOL> if s_obj == annmodel . s_ImpossibleValue : <EOL> return annmodel . s_ImpossibleValue <EOL> else : <EOL> assert s_controller . is_constant ( ) <EOL> controller = s_controller . const <EOL> result = ( isinstance ( s_obj , SomeControlledInstance ) and <EOL> s_obj . controller == controller ) <EOL> return self . bookkeeper . immutablevalue ( result ) <EOL> def specialize_call ( self , hop ) : <EOL> from pypy . rpython . lltypesystem import lltype <EOL> assert hop . s_result . is_constant ( ) <EOL> return hop . inputconst ( lltype . Bool , hop . s_result . const ) <EOL> class SomeControlledInstance ( annmodel . SomeObject ) : <EOL> def __init__ ( self , s_real_obj , controller ) : <EOL> self . s_real_obj = s_real_obj <EOL> self . controller = controller <EOL> self . knowntype = controller . knowntype <EOL> def can_be_none ( self ) : <EOL> return self . controller . can_be_None <EOL> def rtyper_makerepr ( self , rtyper ) : <EOL> from pypy . rpython . rcontrollerentry import ControlledInstanceRepr <EOL> return ControlledInstanceRepr ( rtyper , self . s_real_obj , self . controller ) <EOL> def rtyper_makekey_ex ( self , rtyper ) : <EOL> real_key = rtyper . makekey ( self . s_real_obj ) <EOL> return self . __class__ , real_key , self . controller <EOL> _make_none_union ( "<STR_LIT>" , "<STR_LIT>" , globals ( ) ) <EOL> class __extend__ ( SomeControlledInstance ) : <EOL> def getattr ( s_cin , s_attr ) : <EOL> assert s_attr . is_constant ( ) <EOL> return s_cin . controller . ctrl_getattr ( s_cin . s_real_obj , s_attr ) <EOL> def setattr ( s_cin , s_attr , s_value ) : <EOL> assert s_attr . is_constant ( ) <EOL> s_cin . controller . ctrl_setattr ( s_cin . s_real_obj , s_attr , s_value ) <EOL> def is_true ( s_cin ) : <EOL> return s_cin . controller . ctrl_is_true ( s_cin . s_real_obj ) <EOL> def simple_call ( s_cin , * args_s ) : <EOL> return s_cin . controller . ctrl_call ( s_cin . s_real_obj , * args_s ) <EOL> class __extend__ ( pairtype ( SomeControlledInstance , annmodel . SomeObject ) ) : <EOL> def getitem ( ( s_cin , s_key ) ) : <EOL> return s_cin . controller . ctrl_getitem ( s_cin . s_real_obj , s_key ) <EOL> def setitem ( ( s_cin , s_key ) , s_value ) : <EOL> s_cin . controller . ctrl_setitem ( s_cin . s_real_obj , s_key , s_value ) <EOL> def delitem ( ( s_cin , s_key ) ) : <EOL> s_cin . controller . ctrl_delitem ( s_cin . s_real_obj , s_key ) <EOL> class __extend__ ( pairtype ( SomeControlledInstance , SomeControlledInstance ) ) : <EOL> def union ( ( s_cin1 , s_cin2 ) ) : <EOL> if s_cin1 . controller is not s_cin2 . controller : <EOL> raise annmodel . UnionError ( "<STR_LIT>" ) <EOL> return SomeControlledInstance ( annmodel . unionof ( s_cin1 . s_real_obj , <EOL> s_cin2 . s_real_obj ) , <EOL> s_cin1 . controller ) </s>
