<s> from pycket import values <EOL> from pycket import values_struct <EOL> from pycket . cont import continuation , label , guarded_loop , call_cont , call_extra_cont <EOL> from pycket . error import SchemeException <EOL> from pycket . hash . base import W_HashTable <EOL> from pycket . impersonators . base import ( <EOL> ChaperoneMixin , <EOL> EMPTY_PROPERTY_MAP , <EOL> ImpersonatorMixin , <EOL> InlineProxyMixin , <EOL> ProxyMixin , <EOL> W_ImpPropertyDescriptor , <EOL> chaperone_reference_cont , <EOL> check_chaperone_results , <EOL> get_base_object , <EOL> impersonate_reference_cont , <EOL> make_specialized_property_map <EOL> ) <EOL> from pycket . prims . expose import make_call_method <EOL> from pycket . small_list import inline_small_list <EOL> from pycket . values import UNROLLING_CUTOFF <EOL> from rpython . rlib import jit <EOL> from rpython . rlib . objectmodel import import_from_mixin , specialize <EOL> @ specialize . arg ( <NUM_LIT:0> ) <EOL> def make_interpose_vector ( cls , vector , refh , seth , prop_keys , prop_vals ) : <EOL> map = make_specialized_property_map ( prop_keys , EMPTY_PROPERTY_MAP ) <EOL> fixed = prop_vals [ : ] if prop_vals is not None else None <EOL> return cls . make ( fixed , vector , refh , seth , map ) <EOL> class W_InterposeBox ( values . W_Box ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> import_from_mixin ( ProxyMixin ) <EOL> def __init__ ( self , box , unboxh , seth , prop_keys , prop_vals ) : <EOL> assert isinstance ( box , values . W_Box ) <EOL> self . unboxh = unboxh <EOL> self . seth = seth <EOL> self . init_proxy ( box , prop_keys , prop_vals ) <EOL> def immutable ( self ) : <EOL> return self . inner . immutable ( ) <EOL> def post_unbox_cont ( self , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def post_set_box_cont ( self , val , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def unbox ( self , env , cont ) : <EOL> while isinstance ( self , W_InterposeBox ) : <EOL> cont = self . post_unbox_cont ( env , cont ) <EOL> self = self . inner <EOL> return self . unbox ( env , cont ) <EOL> def set_box ( self , val , env , cont ) : <EOL> after = self . post_set_box_cont ( val , env , cont ) <EOL> return self . seth . call ( [ self . inner , val ] , env , after ) <EOL> class W_ChpBox ( W_InterposeBox ) : <EOL> errorname = "<STR_LIT>" <EOL> import_from_mixin ( ChaperoneMixin ) <EOL> def post_unbox_cont ( self , env , cont ) : <EOL> inner = values . Values . make1 ( self . inner ) <EOL> return chaperone_reference_cont ( self . unboxh , inner , None , env , cont ) <EOL> def post_set_box_cont ( self , val , env , cont ) : <EOL> vals = values . Values . make1 ( val ) <EOL> return check_chaperone_results ( vals , env , imp_box_set_cont ( self . inner , env , cont ) ) <EOL> def immutable ( self ) : <EOL> return self . inner . immutable ( ) <EOL> @ continuation <EOL> def imp_box_set_cont ( b , env , cont , vals ) : <EOL> from pycket . interpreter import check_one_val <EOL> return b . set_box ( check_one_val ( vals ) , env , cont ) <EOL> class W_ImpBox ( W_InterposeBox ) : <EOL> import_from_mixin ( ImpersonatorMixin ) <EOL> errorname = "<STR_LIT>" <EOL> def post_unbox_cont ( self , env , cont ) : <EOL> return impersonate_reference_cont ( self . unboxh , [ self . inner ] , None , env , cont ) <EOL> def post_set_box_cont ( self , val , env , cont ) : <EOL> return imp_box_set_cont ( self . inner , env , cont ) <EOL> @ continuation <EOL> def imp_vec_set_cont ( v , i , app , env , cont , vals ) : <EOL> from pycket . interpreter import check_one_val <EOL> return v . vector_set ( i , check_one_val ( vals ) , env , cont , app = app ) <EOL> @ continuation <EOL> @ jit . unroll_safe <EOL> def impersonate_vector_reference_cont ( f , inner , idx , app , env , cont , _vals ) : <EOL> numargs = _vals . num_values ( ) <EOL> args = [ None ] * ( numargs + <NUM_LIT:2> ) <EOL> args [ <NUM_LIT:0> ] = inner <EOL> args [ <NUM_LIT:1> ] = idx <EOL> for i in range ( numargs ) : <EOL> args [ i + <NUM_LIT:2> ] = _vals . get_value ( i ) <EOL> return f . call_with_extra_info ( args , env , cont , app ) <EOL> class W_InterposeVector ( values . W_MVector ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> import_from_mixin ( InlineProxyMixin ) <EOL> def __init__ ( self , vector , refh , seth , map ) : <EOL> assert isinstance ( vector , values . W_MVector ) <EOL> self . refh = refh <EOL> self . seth = seth <EOL> self . init_proxy ( vector , map ) <EOL> def length ( self ) : <EOL> return get_base_object ( self . base ) . length ( ) <EOL> def post_set_cont ( self , new , i , env , cont , app = None ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def post_ref_cont ( self , i , env , cont , app = None ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def vector_set ( self , i , new , env , cont , app = None ) : <EOL> idx = values . W_Fixnum ( i ) <EOL> after = self . post_set_cont ( new , i , env , cont , app = app ) <EOL> return self . seth . call_with_extra_info ( [ self . inner , idx , new ] , env , after , app ) <EOL> @ jit . unroll_safe <EOL> def vector_ref ( self , i , env , cont , app = None ) : <EOL> idx = values . W_Fixnum ( i ) <EOL> while isinstance ( self , W_InterposeVector ) : <EOL> cont = self . post_ref_cont ( idx , env , cont , app = app ) <EOL> self = self . inner <EOL> return self . vector_ref ( i , env , cont , app = app ) <EOL> @ inline_small_list ( immutable = True , unbox_num = True ) <EOL> class W_ImpVector ( W_InterposeVector ) : <EOL> import_from_mixin ( ImpersonatorMixin ) <EOL> errorname = "<STR_LIT>" <EOL> def post_set_cont ( self , new , i , env , cont , app = None ) : <EOL> return imp_vec_set_cont ( self . inner , i , app , env , cont ) <EOL> def post_ref_cont ( self , i , env , cont , app = None ) : <EOL> return impersonate_vector_reference_cont ( <EOL> self . refh , self . inner , i , app , env , cont ) <EOL> @ inline_small_list ( immutable = True , unbox_num = True ) <EOL> class W_ChpVector ( W_InterposeVector ) : <EOL> import_from_mixin ( ChaperoneMixin ) <EOL> errorname = "<STR_LIT>" <EOL> def post_set_cont ( self , new , i , env , cont , app = None ) : <EOL> vals = values . Values . make1 ( new ) <EOL> return check_chaperone_results ( vals , env , <EOL> imp_vec_set_cont ( self . inner , i , app , env , cont ) ) <EOL> def post_ref_cont ( self , i , env , cont , app = None ) : <EOL> args = values . Values . make2 ( self . inner , i ) <EOL> return chaperone_reference_cont ( self . refh , args , app , env , cont ) <EOL> def valid_struct_proc ( x ) : <EOL> v = get_base_object ( x ) <EOL> return ( isinstance ( v , values_struct . W_StructFieldAccessor ) or <EOL> isinstance ( v , values_struct . W_StructFieldMutator ) or <EOL> isinstance ( v , values_struct . W_StructPropertyAccessor ) ) <EOL> @ continuation <EOL> def imp_struct_set_cont ( orig_struct , setter , field , app , env , cont , _vals ) : <EOL> from pycket . interpreter import check_one_val <EOL> val = check_one_val ( _vals ) <EOL> if setter is values . w_false : <EOL> return orig_struct . set_with_extra_info ( field , val , app , env , cont ) <EOL> return setter . call_with_extra_info ( [ orig_struct , val ] , env , cont , app ) <EOL> class W_InterposeContinuationMarkKey ( values . W_ContinuationMarkKey ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> import_from_mixin ( ProxyMixin ) <EOL> def __init__ ( self , mark , get_proc , set_proc , prop_keys , prop_vals ) : <EOL> assert get_proc . iscallable ( ) <EOL> assert set_proc . iscallable ( ) <EOL> self . get_proc = get_proc <EOL> self . set_proc = set_proc <EOL> self . init_proxy ( mark , prop_keys , prop_vals ) <EOL> def post_set_cont ( self , body , value , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def post_get_cont ( self , value , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ label <EOL> def get_cmk ( self , value , env , cont ) : <EOL> return self . get_proc . call ( [ value ] , env , <EOL> self . post_get_cont ( value , env , cont ) ) <EOL> @ label <EOL> def set_cmk ( self , body , value , update , env , cont ) : <EOL> return self . set_proc . call ( [ value ] , env , <EOL> self . post_set_cont ( body , value , env , cont ) ) <EOL> @ continuation <EOL> def imp_cmk_post_set_cont ( body , inner , env , cont , _vals ) : <EOL> from pycket . interpreter import check_one_val <EOL> val = check_one_val ( _vals ) <EOL> return inner . set_cmk ( body , val , cont , env , cont ) <EOL> @ continuation <EOL> def imp_cmk_post_get_cont ( key , env , cont , _vals ) : <EOL> from pycket . interpreter import check_one_val <EOL> val = check_one_val ( _vals ) <EOL> return key . get_cmk ( val , env , cont ) <EOL> class W_ChpContinuationMarkKey ( W_InterposeContinuationMarkKey ) : <EOL> import_from_mixin ( ChaperoneMixin ) <EOL> def post_get_cont ( self , value , env , cont ) : <EOL> vals = values . Values . make1 ( value ) <EOL> return check_chaperone_results ( vals , env , <EOL> imp_cmk_post_get_cont ( self . inner , env , cont ) ) <EOL> def post_set_cont ( self , body , value , env , cont ) : <EOL> vals = values . Values . make1 ( value ) <EOL> return check_chaperone_results ( vals , env , <EOL> imp_cmk_post_set_cont ( body , self . inner , env , cont ) ) <EOL> class W_ImpContinuationMarkKey ( W_InterposeContinuationMarkKey ) : <EOL> import_from_mixin ( ImpersonatorMixin ) <EOL> def post_get_cont ( self , value , env , cont ) : <EOL> return imp_cmk_post_get_cont ( self . inner , env , cont ) <EOL> def post_set_cont ( self , body , value , env , cont ) : <EOL> return imp_cmk_post_set_cont ( body , self . inner , env , cont ) <EOL> class W_InterposeHashTable ( W_HashTable ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> import_from_mixin ( ProxyMixin ) <EOL> def __init__ ( self , inner , ref_proc , set_proc , remove_proc , key_proc , <EOL> clear_proc , prop_keys , prop_vals ) : <EOL> assert isinstance ( inner , W_HashTable ) <EOL> assert set_proc . iscallable ( ) <EOL> assert ref_proc . iscallable ( ) <EOL> assert remove_proc . iscallable ( ) <EOL> assert key_proc . iscallable ( ) <EOL> assert clear_proc is values . w_false or clear_proc . iscallable ( ) <EOL> self . set_proc = set_proc <EOL> self . ref_proc = ref_proc <EOL> self . remove_proc = remove_proc <EOL> self . key_proc = key_proc <EOL> self . clear_proc = clear_proc <EOL> self . init_proxy ( inner , prop_keys , prop_vals ) <EOL> def post_ref_cont ( self , key , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def post_set_cont ( self , key , val , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def hash_keys ( self ) : <EOL> return get_base_object ( self ) . hash_keys ( ) <EOL> @ label <EOL> def hash_set ( self , key , val , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ label <EOL> def hash_ref ( self , key , env , cont ) : <EOL> after = self . post_ref_cont ( key , env , cont ) <EOL> return self . ref_proc . call ( [ self . inner , key ] , env , after ) <EOL> @ continuation <EOL> def imp_hash_table_ref_cont ( ht , old , env , cont , _vals ) : <EOL> if _vals . num_values ( ) != <NUM_LIT:2> : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> key , post = _vals . get_all_values ( ) <EOL> after = imp_hash_table_post_ref_cont ( post , ht , old , env , cont ) <EOL> return ht . hash_ref ( key , env , after ) <EOL> @ continuation <EOL> def imp_hash_table_post_ref_cont ( post , ht , old , env , cont , _vals ) : <EOL> from pycket . interpreter import check_one_val , return_multi_vals <EOL> val = check_one_val ( _vals ) <EOL> if val is None : <EOL> return return_multi_vals ( _vals , env , cont ) <EOL> return post . call ( [ ht , old , val ] , env , cont ) <EOL> @ continuation <EOL> def chp_hash_table_ref_cont ( ht , old , env , cont , _vals ) : <EOL> if _vals . num_values ( ) != <NUM_LIT:2> : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> key = _vals . get_value ( <NUM_LIT:0> ) <EOL> post = _vals . get_value ( <NUM_LIT:1> ) <EOL> key = values . Values . make1 ( key ) <EOL> after = check_chaperone_results ( key , env , <EOL> imp_hash_table_post_ref_cont ( post , ht , old , env , cont ) ) <EOL> return ht . hash_ref ( key , env , after ) <EOL> class W_ImpHashTable ( W_InterposeHashTable ) : <EOL> import_from_mixin ( ImpersonatorMixin ) <EOL> def post_set_cont ( self , key , val , env , cont ) : <EOL> pass <EOL> def post_ref_cont ( self , key , env , cont ) : <EOL> return imp_hash_table_ref_cont ( self . inner , key , env , cont ) <EOL> class W_ChpHashTable ( W_InterposeHashTable ) : <EOL> import_from_mixin ( ChaperoneMixin ) <EOL> def post_set_cont ( self , key , val , env , cont ) : <EOL> pass <EOL> def post_ref_cont ( self , key , env , cont ) : <EOL> return chp_hash_table_ref_cont ( self . inner , key , env , cont ) </s>
