<s> from pycket import config <EOL> from pycket . arity import Arity <EOL> from pycket . base import W_Object , W_ProtoObject , UnhashableType <EOL> from pycket . cont import continuation , label , NilCont <EOL> from pycket . env import ConsEnv <EOL> from pycket . error import SchemeException <EOL> from pycket . prims . expose import make_call_method <EOL> from pycket . small_list import inline_small_list <EOL> from pycket . util import memoize_constructor <EOL> from rpython . tool . pairtype import extendabletype <EOL> from rpython . rlib import jit , runicode , rarithmetic <EOL> from rpython . rlib . rstring import StringBuilder <EOL> from rpython . rlib . objectmodel import always_inline , r_dict , compute_hash , we_are_translated <EOL> from rpython . rlib . objectmodel import specialize <EOL> from rpython . rlib . rarithmetic import r_longlong , intmask <EOL> import rpython . rlib . rweakref as weakref <EOL> from rpython . rlib . rbigint import rbigint , NULLRBIGINT <EOL> from rpython . rlib . debug import check_list_of_chars , make_sure_not_resized , check_regular_int <EOL> UNROLLING_CUTOFF = <NUM_LIT:5> <EOL> def elidable_iff ( pred ) : <EOL> def wrapper ( func ) : <EOL> func = jit . unroll_safe ( func ) <EOL> def trampoline ( * args ) : <EOL> if jit . we_are_jitted ( ) and pred ( * args ) : <EOL> return elidable_func ( * args ) <EOL> return func ( * args ) <EOL> return trampoline <EOL> return wrapper <EOL> @ inline_small_list ( immutable = True , attrname = "<STR_LIT>" , factoryname = "<STR_LIT>" ) <EOL> class Values ( W_ProtoObject ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ staticmethod <EOL> def make ( values_w ) : <EOL> if len ( values_w ) == <NUM_LIT:1> : <EOL> return Values . make1 ( values_w [ <NUM_LIT:0> ] ) <EOL> return Values . _make ( values_w ) <EOL> @ staticmethod <EOL> def make1 ( w_value ) : <EOL> assert w_value is not None <EOL> return w_value <EOL> @ staticmethod <EOL> def make2 ( w_value1 , w_value2 ) : <EOL> return Values . _make2 ( w_value1 , w_value2 ) <EOL> def num_values ( self ) : <EOL> return self . _get_size_list ( ) <EOL> def get_value ( self , index ) : <EOL> return self . _get_list ( index ) <EOL> def get_all_values ( self ) : <EOL> return self . _get_full_list ( ) <EOL> def tostring ( self ) : <EOL> vals = self . _get_full_list ( ) <EOL> if len ( vals ) == <NUM_LIT:1> : <EOL> return vals [ <NUM_LIT:0> ] . tostring ( ) <EOL> if len ( vals ) == <NUM_LIT:0> : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> class W_Cell ( W_Object ) : <EOL> def __init__ ( self , v ) : <EOL> assert not isinstance ( v , W_Cell ) <EOL> if isinstance ( v , W_Fixnum ) : <EOL> v = W_CellIntegerStrategy ( v . value ) <EOL> elif isinstance ( v , W_Flonum ) : <EOL> v = W_CellFloatStrategy ( v . value ) <EOL> self . w_value = v <EOL> def get_val ( self ) : <EOL> w_value = self . w_value <EOL> if isinstance ( w_value , W_CellIntegerStrategy ) : <EOL> return W_Fixnum ( w_value . value ) <EOL> elif isinstance ( w_value , W_CellFloatStrategy ) : <EOL> return W_Flonum ( w_value . value ) <EOL> return w_value <EOL> def set_val ( self , w_value ) : <EOL> from pycket import config <EOL> if not config . strategies : <EOL> self . w_value = w_value <EOL> return <EOL> if isinstance ( w_value , W_Fixnum ) : <EOL> w_v = self . w_value <EOL> if isinstance ( w_v , W_CellIntegerStrategy ) : <EOL> w_v . value = w_value . value <EOL> else : <EOL> self . w_value = W_CellIntegerStrategy ( w_value . value ) <EOL> elif isinstance ( w_value , W_Flonum ) : <EOL> w_v = self . w_value <EOL> if isinstance ( w_v , W_CellFloatStrategy ) : <EOL> w_v . value = w_value . value <EOL> else : <EOL> self . w_value = W_CellFloatStrategy ( w_value . value ) <EOL> else : <EOL> self . w_value = w_value <EOL> class W_CellIntegerStrategy ( W_Object ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> class W_CellFloatStrategy ( W_Object ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> class W_Undefined ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> w_unsafe_undefined = W_Undefined ( ) <EOL> class W_Syntax ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , o ) : <EOL> self . val = o <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . val . tostring ( ) <EOL> class W_ModulePathIndex ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_ResolvedModulePath ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT:name>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> class W_Logger ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , topic , parent , propagate_level , propagate_topic ) : <EOL> self . topic = topic <EOL> self . parent = parent <EOL> self . propagate_level = propagate_level <EOL> self . propagate_topic = propagate_topic <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_ContinuationPromptTag ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:name>" ] <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def tostring ( self ) : <EOL> if self . name is None : <EOL> return "<STR_LIT>" <EOL> name = self . name . utf8value <EOL> return "<STR_LIT>" % name <EOL> w_default_continuation_prompt_tag = W_ContinuationPromptTag ( None ) <EOL> class W_ContinuationMarkSet ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , cont , prompt_tag ) : <EOL> self . cont = cont <EOL> self . prompt_tag = prompt_tag <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_ContinuationMarkKey ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:name>" ] <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def get_cmk ( self , value , env , cont ) : <EOL> from pycket . interpreter import return_value <EOL> return return_value ( value , env , cont ) <EOL> def set_cmk ( self , body , value , update , env , cont ) : <EOL> update . update_cm ( self , value ) <EOL> return body . call ( [ ] , env , cont ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_VariableReference ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , varref ) : <EOL> self . varref = varref <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_VectorSuper ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _attrs_ = [ ] <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def vector_set ( self , i , new , env , cont , app = None ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def vector_ref ( self , i , env , cont , app = None ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def length ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def immutable ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def get_storage ( self ) : <EOL> raise NotImplementedError <EOL> def set_storage ( self , storage ) : <EOL> raise NotImplementedError <EOL> def get_strategy ( self ) : <EOL> raise NotImplementedError <EOL> def set_strategy ( self , strategy ) : <EOL> raise NotImplementedError <EOL> class W_MVector ( W_VectorSuper ) : <EOL> errorname = "<STR_LIT>" <EOL> class W_List ( W_Object ) : <EOL> errorname = "<STR_LIT:list>" <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class W_Cons ( W_List ) : <EOL> "<STR_LIT>" <EOL> errorname = "<STR_LIT>" <EOL> @ staticmethod <EOL> def make ( car , cdr ) : <EOL> from pycket import config <EOL> if not config . type_size_specialization : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_WrappedConsProper ( car , cdr ) <EOL> return W_WrappedCons ( car , cdr ) <EOL> elif isinstance ( car , W_Fixnum ) : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_UnwrappedFixnumConsProper ( car . value , cdr ) <EOL> return W_UnwrappedFixnumCons ( car . value , cdr ) <EOL> elif isinstance ( car , W_Flonum ) : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_UnwrappedFlonumConsProper ( car . value , cdr ) <EOL> return W_UnwrappedFlonumCons ( car . value , cdr ) <EOL> else : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_WrappedConsProper ( car , cdr ) <EOL> return W_WrappedCons ( car , cdr ) <EOL> def car ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def cdr ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def tostring ( self ) : <EOL> cur = self <EOL> acc = [ ] <EOL> while isinstance ( cur , W_Cons ) : <EOL> acc . append ( cur . car ( ) . tostring ( ) ) <EOL> cur = cur . cdr ( ) <EOL> if cur is w_null : <EOL> return "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( acc ) <EOL> return "<STR_LIT>" % ( "<STR_LIT:U+0020>" . join ( acc ) , cur . tostring ( ) ) <EOL> def immutable ( self ) : <EOL> return True <EOL> def hash_equal ( self , info = None ) : <EOL> x = <NUM_LIT> <EOL> while isinstance ( self , W_Cons ) : <EOL> car , self = self . car ( ) , self . cdr ( ) <EOL> y = car . hash_equal ( info = info ) <EOL> x = rarithmetic . intmask ( ( <NUM_LIT> * x ) ^ y ) <EOL> return x <EOL> def equal ( self , other ) : <EOL> if not isinstance ( other , W_Cons ) : <EOL> return False <EOL> if self is other : <EOL> return True <EOL> w_curr1 = self <EOL> w_curr2 = other <EOL> while isinstance ( w_curr1 , W_Cons ) and isinstance ( w_curr2 , W_Cons ) : <EOL> if not w_curr1 . car ( ) . equal ( w_curr2 . car ( ) ) : <EOL> return False <EOL> w_curr1 = w_curr1 . cdr ( ) <EOL> w_curr2 = w_curr2 . cdr ( ) <EOL> return w_curr1 . equal ( w_curr2 ) <EOL> class W_UnwrappedFixnumCons ( W_Cons ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , a , d ) : <EOL> self . _car = a <EOL> self . _cdr = d <EOL> def car ( self ) : <EOL> return W_Fixnum ( self . _car ) <EOL> def cdr ( self ) : <EOL> return self . _cdr <EOL> class W_UnwrappedFixnumConsProper ( W_UnwrappedFixnumCons ) : <EOL> def is_proper_list ( self ) : <EOL> return True <EOL> class W_UnwrappedFlonumCons ( W_Cons ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , a , d ) : <EOL> self . _car = a <EOL> self . _cdr = d <EOL> def car ( self ) : <EOL> return W_Flonum ( self . _car ) <EOL> def cdr ( self ) : <EOL> return self . _cdr <EOL> class W_UnwrappedFlonumConsProper ( W_UnwrappedFlonumCons ) : <EOL> def is_proper_list ( self ) : <EOL> return True <EOL> class W_WrappedCons ( W_Cons ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , a , d ) : <EOL> self . _car = a <EOL> self . _cdr = d <EOL> def car ( self ) : <EOL> return self . _car <EOL> def cdr ( self ) : <EOL> return self . _cdr <EOL> class W_WrappedConsProper ( W_WrappedCons ) : <EOL> def is_proper_list ( self ) : <EOL> return True <EOL> class W_WrappedConsMaybe ( W_WrappedCons ) : <EOL> def is_proper_list ( self ) : <EOL> return self . _cdr . is_proper_list ( ) <EOL> class W_Box ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def hash_equal ( self , info = None ) : <EOL> raise UnhashableType <EOL> def unbox ( self , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def set_box ( self , val , env , cont ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class W_MBox ( W_Box ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def unbox ( self , env , cont ) : <EOL> from pycket . interpreter import return_value <EOL> return return_value ( self . value , env , cont ) <EOL> def set_box ( self , val , env , cont ) : <EOL> from pycket . interpreter import return_value <EOL> self . value = val <EOL> return return_value ( w_void , env , cont ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . value . tostring ( ) <EOL> class W_IBox ( W_Box ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def immutable ( self ) : <EOL> return True <EOL> def unbox ( self , env , cont ) : <EOL> from pycket . interpreter import return_value <EOL> return return_value ( self . value , env , cont ) <EOL> def set_box ( self , val , env , cont ) : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . value . tostring ( ) <EOL> class W_WeakBox ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> def __init__ ( self , value ) : <EOL> assert isinstance ( value , W_Object ) <EOL> self . value = weakref . ref ( value ) <EOL> def get ( self ) : <EOL> return self . value ( ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_Ephemeron ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:key>" , "<STR_LIT>" ] <EOL> def __init__ ( self , key , value ) : <EOL> assert isinstance ( key , W_Object ) <EOL> assert isinstance ( value , W_Object ) <EOL> self . key = weakref . ref ( key ) <EOL> self . mapping = weakref . RWeakKeyDictionary ( W_Object , W_Object ) <EOL> self . mapping . set ( key , value ) <EOL> def get ( self ) : <EOL> return self . mapping . get ( self . key ( ) ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_Placeholder ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_HashTablePlaceholder ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , keys , vals ) : <EOL> pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_MList ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class W_MCons ( W_MList ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , a , d ) : <EOL> self . _car = a <EOL> self . _cdr = d <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % ( self . car ( ) . tostring ( ) , self . cdr ( ) . tostring ( ) ) <EOL> def car ( self ) : <EOL> return self . _car <EOL> def cdr ( self ) : <EOL> return self . _cdr <EOL> def set_car ( self , a ) : <EOL> self . _car = a <EOL> def set_cdr ( self , d ) : <EOL> self . _cdr = d <EOL> class W_Number ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def immutable ( self ) : <EOL> return True <EOL> def eqv ( self , other ) : <EOL> return self . equal ( other ) <EOL> def hash_eqv ( self ) : <EOL> return self . hash_equal ( info = None ) <EOL> class W_Rational ( W_Number ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , num , den ) : <EOL> assert isinstance ( num , rbigint ) <EOL> assert isinstance ( den , rbigint ) <EOL> self . _numerator = num <EOL> self . _denominator = den <EOL> assert den . gt ( NULLRBIGINT ) <EOL> @ staticmethod <EOL> def make ( num , den ) : <EOL> if isinstance ( num , W_Fixnum ) : <EOL> num = rbigint . fromint ( num . value ) <EOL> else : <EOL> assert isinstance ( num , W_Bignum ) <EOL> num = num . value <EOL> if isinstance ( den , W_Fixnum ) : <EOL> den = rbigint . fromint ( den . value ) <EOL> else : <EOL> assert isinstance ( den , W_Bignum ) <EOL> den = den . value <EOL> return W_Rational . frombigint ( num , den ) <EOL> @ staticmethod <EOL> def fromint ( n , d = <NUM_LIT:1> ) : <EOL> assert isinstance ( n , int ) <EOL> assert isinstance ( d , int ) <EOL> return W_Rational . frombigint ( rbigint . fromint ( n ) , rbigint . fromint ( d ) ) <EOL> @ staticmethod <EOL> def frombigint ( n , d = rbigint . fromint ( <NUM_LIT:1> ) ) : <EOL> from pycket . arithmetic import gcd <EOL> g = gcd ( n , d ) <EOL> n = n . floordiv ( g ) <EOL> d = d . floordiv ( g ) <EOL> if d . eq ( rbigint . fromint ( <NUM_LIT:1> ) ) : <EOL> return W_Bignum . frombigint ( n ) <EOL> return W_Rational ( n , d ) <EOL> @ staticmethod <EOL> def fromfloat ( f ) : <EOL> assert isinstance ( f , float ) <EOL> d = <NUM_LIT> <EOL> n = int ( f * d ) <EOL> from fractions import gcd <EOL> _gcd = gcd ( n , d ) <EOL> return W_Rational . fromint ( n / _gcd , d / _gcd ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % ( self . _numerator . str ( ) , self . _denominator . str ( ) ) <EOL> def equal ( self , other ) : <EOL> if not isinstance ( other , W_Rational ) : <EOL> return False <EOL> return ( self . _numerator . eq ( other . _numerator ) and <EOL> self . _denominator . eq ( other . _denominator ) ) <EOL> def hash_equal ( self , info = None ) : <EOL> hash1 = self . _numerator . hash ( ) <EOL> hash2 = self . _denominator . hash ( ) <EOL> return rarithmetic . intmask ( hash1 + <NUM_LIT> * hash2 ) <EOL> class W_Integer ( W_Number ) : <EOL> errorname = "<STR_LIT>" <EOL> def toint ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def frombigint ( value ) : <EOL> try : <EOL> num = value . toint ( ) <EOL> except OverflowError : <EOL> pass <EOL> else : <EOL> return W_Fixnum ( num ) <EOL> return W_Bignum ( value ) <EOL> @ staticmethod <EOL> def fromfloat ( value ) : <EOL> try : <EOL> val = rarithmetic . ovfcheck_float_to_int ( value ) <EOL> except OverflowError : <EOL> return W_Bignum ( rbigint . fromfloat ( value ) ) <EOL> return W_Fixnum ( val ) <EOL> @ memoize_constructor <EOL> class W_Fixnum ( W_Integer ) : <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> errorname = "<STR_LIT>" <EOL> def tostring ( self ) : <EOL> return str ( self . value ) <EOL> def __init__ ( self , val ) : <EOL> if not we_are_translated ( ) : <EOL> assert isinstance ( val , int ) <EOL> check_regular_int ( val ) <EOL> self . value = val <EOL> def toint ( self ) : <EOL> return self . value <EOL> def equal ( self , other ) : <EOL> if not isinstance ( other , W_Fixnum ) : <EOL> return False <EOL> return self . value == other . value <EOL> def hash_equal ( self , info = None ) : <EOL> return self . value <EOL> W_Fixnum . ZERO = W_Fixnum . make ( <NUM_LIT:0> ) <EOL> W_Fixnum . ONE = W_Fixnum . make ( <NUM_LIT:1> ) <EOL> W_Fixnum . TWO = W_Fixnum . make ( <NUM_LIT:2> ) <EOL> class W_Flonum ( W_Number ) : <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , val ) : <EOL> self . value = val <EOL> @ staticmethod <EOL> def make ( val ) : <EOL> return W_Flonum ( val ) <EOL> def tostring ( self ) : <EOL> from rpython . rlib . rfloat import formatd , DTSF_STR_PRECISION , DTSF_ADD_DOT_0 <EOL> return formatd ( self . value , '<STR_LIT:g>' , DTSF_STR_PRECISION , DTSF_ADD_DOT_0 ) <EOL> def hash_equal ( self , info = None ) : <EOL> return compute_hash ( self . value ) <EOL> def equal ( self , other ) : <EOL> from rpython . rlib . longlong2float import float2longlong <EOL> import math <EOL> if not isinstance ( other , W_Flonum ) : <EOL> return False <EOL> v1 = self . value <EOL> v2 = other . value <EOL> ll1 = float2longlong ( v1 ) <EOL> ll2 = float2longlong ( v2 ) <EOL> return ll1 == ll2 or ( math . isnan ( v1 ) and math . isnan ( v2 ) ) <EOL> W_Flonum . ZERO = W_Flonum ( <NUM_LIT:0.0> ) <EOL> W_Flonum . INF = W_Flonum ( float ( "<STR_LIT>" ) ) <EOL> W_Flonum . NEGINF = W_Flonum ( - float ( "<STR_LIT>" ) ) <EOL> W_Flonum . NAN = W_Flonum ( float ( "<STR_LIT>" ) ) <EOL> class W_Bignum ( W_Integer ) : <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> def tostring ( self ) : <EOL> return self . value . str ( ) <EOL> def __init__ ( self , val ) : <EOL> self . value = val <EOL> def toint ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . value . toint ( ) <EOL> def toflonum ( self ) : <EOL> bignum = self . value <EOL> try : <EOL> floatval = bignum . tofloat ( ) <EOL> except OverflowError : <EOL> return W_Flonum . NEGINF if bignum . sign < <NUM_LIT:0> else W_Flonum . INF <EOL> return W_Flonum ( floatval ) <EOL> def equal ( self , other ) : <EOL> if not isinstance ( other , W_Bignum ) : <EOL> return False <EOL> return self . value . eq ( other . value ) <EOL> def hash_equal ( self , info = None ) : <EOL> return self . value . hash ( ) <EOL> @ memoize_constructor <EOL> class W_Complex ( W_Number ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , re , im ) : <EOL> assert isinstance ( re , W_Number ) <EOL> assert isinstance ( im , W_Number ) <EOL> self . real = re <EOL> self . imag = im <EOL> @ staticmethod <EOL> def from_real_pair ( real , imag ) : <EOL> if W_Fixnum . ZERO . eqv ( imag ) : <EOL> return real <EOL> return W_Complex ( real , imag ) <EOL> def eqv ( self , other ) : <EOL> if not isinstance ( other , W_Complex ) : <EOL> return False <EOL> return self . real . eqv ( other . real ) and self . imag . eqv ( other . imag ) <EOL> def hash_equal ( self , info = None ) : <EOL> hash1 = self . real . hash_equal ( ) <EOL> hash2 = self . imag . hash_equal ( ) <EOL> return rarithmetic . intmask ( hash1 + <NUM_LIT> * hash2 ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % ( self . real . tostring ( ) , self . imag . tostring ( ) ) <EOL> @ memoize_constructor <EOL> class W_Character ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , val ) : <EOL> self . value = val <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % runicode . unicode_encode_utf_8 ( <EOL> self . value , len ( self . value ) , "<STR_LIT:strict>" ) <EOL> def immutable ( self ) : <EOL> return True <EOL> def eqv ( self , other ) : <EOL> if not isinstance ( other , W_Character ) : <EOL> return False <EOL> return self . value == other . value <EOL> def hash_eqv ( self ) : <EOL> return ord ( self . value ) <EOL> def hash_equal ( self , info = None ) : <EOL> return self . hash_eqv ( ) <EOL> class W_Thread ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_Semaphore ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , n ) : <EOL> self . n = n <EOL> def post ( self ) : <EOL> self . n += <NUM_LIT:1> <EOL> def wait ( self ) : <EOL> if self . n >= <NUM_LIT:1> : <EOL> return <EOL> else : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_Evt ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> class W_SemaphorePeekEvt ( W_Evt ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" ] <EOL> def __init__ ( self , sema ) : <EOL> self . sema = sema <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_PseudoRandomGenerator ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> class W_Path ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT:path>" ] <EOL> errorname = "<STR_LIT:path>" <EOL> def __init__ ( self , p ) : <EOL> self . path = p <EOL> def equal ( self , other ) : <EOL> if not isinstance ( other , W_Path ) : <EOL> return False <EOL> return self . path == other . path <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . path <EOL> class W_Void ( W_Object ) : <EOL> def __init__ ( self ) : pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_Null ( W_List ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> def is_proper_list ( self ) : <EOL> return True <EOL> w_void = W_Void ( ) <EOL> w_null = W_Null ( ) <EOL> class W_Bool ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> @ staticmethod <EOL> def make ( b ) : <EOL> if b : return w_true <EOL> else : return w_false <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" if self is w_true else "<STR_LIT>" <EOL> w_false = W_Bool ( ) <EOL> w_true = W_Bool ( ) <EOL> class W_ThreadCellValues ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . assoc = { } <EOL> for c in W_ThreadCell . _table : <EOL> if c . preserved : <EOL> self . assoc [ c ] = c . value <EOL> class W_ThreadCell ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> errorname = "<STR_LIT>" <EOL> _table = [ ] <EOL> def __init__ ( self , val , preserved ) : <EOL> self . value = val <EOL> self . initial = val <EOL> self . preserved = preserved <EOL> W_ThreadCell . _table . append ( self ) <EOL> def set ( self , val ) : <EOL> self . value = val <EOL> def get ( self ) : <EOL> return self . value <EOL> @ memoize_constructor <EOL> class W_Bytes ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ '<STR_LIT:value>' ] <EOL> _attrs_ = [ '<STR_LIT:value>' ] <EOL> @ staticmethod <EOL> def from_string ( str , immutable = True ) : <EOL> if immutable : <EOL> return W_ImmutableBytes ( list ( str ) ) <EOL> else : <EOL> return W_MutableBytes ( list ( str ) ) <EOL> def __init__ ( self , bs ) : <EOL> assert bs is not None <EOL> self . value = check_list_of_chars ( bs ) <EOL> make_sure_not_resized ( self . value ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % "<STR_LIT>" . join ( [ "<STR_LIT>" % ord ( i ) for i in self . value ] ) <EOL> def equal ( self , other ) : <EOL> if not isinstance ( other , W_Bytes ) : <EOL> return False <EOL> return len ( self . value ) == len ( other . value ) and str ( self . value ) == str ( other . value ) <EOL> def hash_equal ( self , info = None ) : <EOL> from rpython . rlib . rarithmetic import intmask <EOL> s = self . value <EOL> length = len ( s ) <EOL> if length == <NUM_LIT:0> : <EOL> return - <NUM_LIT:1> <EOL> x = ord ( s [ <NUM_LIT:0> ] ) << <NUM_LIT:7> <EOL> i = <NUM_LIT:0> <EOL> while i < length : <EOL> x = intmask ( ( <NUM_LIT> * x ) ^ ord ( s [ i ] ) ) <EOL> i += <NUM_LIT:1> <EOL> x ^= length <EOL> return intmask ( x ) <EOL> def immutable ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def ref ( self , n ) : <EOL> l = len ( self . value ) <EOL> if n < <NUM_LIT:0> or n >= l : <EOL> raise SchemeException ( "<STR_LIT>" % ( n , l ) ) <EOL> return W_Fixnum ( ord ( self . value [ n ] ) ) <EOL> def set ( self , n , v ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def as_str ( self ) : <EOL> return "<STR_LIT>" . join ( self . value ) <EOL> class W_MutableBytes ( W_Bytes ) : <EOL> errorname = "<STR_LIT>" <EOL> def immutable ( self ) : <EOL> return False <EOL> def set ( self , n , v ) : <EOL> l = len ( self . value ) <EOL> if n < <NUM_LIT:0> or n >= l : <EOL> raise SchemeException ( "<STR_LIT>" % ( n , l ) ) <EOL> self . value [ n ] = chr ( v ) <EOL> class W_ImmutableBytes ( W_Bytes ) : <EOL> errorname = "<STR_LIT>" <EOL> def immutable ( self ) : <EOL> return True <EOL> def set ( self , n , v ) : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> class W_Symbol ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT:value>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> errorname = "<STR_LIT>" <EOL> all_symbols = { } <EOL> unreadable_symbols = { } <EOL> def __init__ ( self , val , unreadable = False ) : <EOL> assert isinstance ( val , unicode ) <EOL> self . unicodevalue = val <EOL> self . unreadable = unreadable <EOL> try : <EOL> self . asciivalue = val . encode ( "<STR_LIT:ascii>" ) <EOL> except UnicodeEncodeError : <EOL> self . asciivalue = None <EOL> self . utf8value = val . encode ( "<STR_LIT:utf-8>" ) <EOL> @ staticmethod <EOL> @ jit . elidable <EOL> def make ( string ) : <EOL> w_result = W_Symbol . all_symbols . get ( string , None ) <EOL> if w_result is None : <EOL> value = string . decode ( "<STR_LIT:utf-8>" ) <EOL> W_Symbol . all_symbols [ string ] = w_result = W_Symbol ( value ) <EOL> return w_result <EOL> @ staticmethod <EOL> def make_unreadable ( string ) : <EOL> if string in W_Symbol . unreadable_symbols : <EOL> return W_Symbol . unreadable_symbols [ string ] <EOL> else : <EOL> value = string . decode ( "<STR_LIT:utf-8>" ) <EOL> W_Symbol . unreadable_symbols [ string ] = w_result = W_Symbol ( value , True ) <EOL> return w_result <EOL> def __repr__ ( self ) : <EOL> return self . utf8value <EOL> def is_interned ( self ) : <EOL> string = self . utf8value <EOL> if string in W_Symbol . all_symbols : <EOL> return W_Symbol . all_symbols [ string ] is self <EOL> if string in W_Symbol . unreadable_symbols : <EOL> return W_Symbol . unreadable_symbols [ string ] is self <EOL> return False <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . utf8value <EOL> def variable_name ( self ) : <EOL> return self . utf8value <EOL> break_enabled_key = W_Symbol ( u"<STR_LIT>" ) <EOL> exn_handler_key = W_Symbol ( u"<STR_LIT>" ) <EOL> parameterization_key = W_Symbol ( u"<STR_LIT>" ) <EOL> class W_Keyword ( W_Object ) : <EOL> _immutable_fields_ = [ "<STR_LIT:value>" ] <EOL> errorname = "<STR_LIT>" <EOL> all_symbols = { } <EOL> @ staticmethod <EOL> def make ( string ) : <EOL> w_result = W_Keyword . all_symbols . get ( string , None ) <EOL> if w_result is None : <EOL> W_Keyword . all_symbols [ string ] = w_result = W_Keyword ( string ) <EOL> return w_result <EOL> def __repr__ ( self ) : <EOL> return self . value <EOL> def __init__ ( self , val ) : <EOL> self . value = val <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . value <EOL> class W_Procedure ( W_Object ) : <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def iscallable ( self ) : <EOL> return True <EOL> def immutable ( self ) : <EOL> return True <EOL> def call ( self , args , env , cont ) : <EOL> return self . call_with_extra_info ( args , env , cont , None ) <EOL> def call_with_extra_info ( self , args , env , cont , app ) : <EOL> return self . call ( args , env , cont ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_AssignmentTransformer ( W_Object ) : <EOL> def __init__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class W_ThunkBodyCMK ( W_Procedure ) : <EOL> _immutable_fields_ = [ "<STR_LIT:body>" ] <EOL> def __init__ ( self , body ) : <EOL> self . body = body <EOL> @ make_call_method ( [ ] , simple = False ) <EOL> def call ( self , env , cont ) : <EOL> return self . body , env , cont <EOL> class W_ThunkProcCMK ( W_Procedure ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT:args>" ] <EOL> def __init__ ( self , proc , args ) : <EOL> self . proc = proc <EOL> self . args = args <EOL> @ label <EOL> @ make_call_method ( [ ] , simple = False ) <EOL> def call ( self , env , cont ) : <EOL> return self . proc . call ( self . args , env , cont ) <EOL> class W_Prim ( W_Procedure ) : <EOL> _immutable_fields_ = [ "<STR_LIT:name>" , "<STR_LIT:code>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , name , code , arity = Arity . unknown , result_arity = None , simple1 = None , simple2 = None ) : <EOL> self . name = W_Symbol . make ( name ) <EOL> self . code = code <EOL> assert isinstance ( arity , Arity ) <EOL> self . arity = arity <EOL> self . result_arity = result_arity <EOL> self . simple1 = simple1 <EOL> self . simple2 = simple2 <EOL> def get_arity ( self ) : <EOL> return self . arity <EOL> def get_result_arity ( self ) : <EOL> return self . result_arity <EOL> def call_with_extra_info ( self , args , env , cont , extra_call_info ) : <EOL> jit . promote ( self ) <EOL> return self . code ( args , env , cont , extra_call_info ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" % self . name . variable_name ( ) <EOL> def to_list ( l ) : return to_improper ( l , w_null ) <EOL> @ jit . look_inside_iff ( <EOL> lambda l , curr : jit . loop_unrolling_heuristic ( l , len ( l ) , UNROLLING_CUTOFF ) ) <EOL> def to_improper ( l , curr ) : <EOL> for i in range ( len ( l ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> curr = W_Cons . make ( l [ i ] , curr ) <EOL> return curr <EOL> @ jit . look_inside_iff ( <EOL> lambda v , curr : jit . loop_unrolling_heuristic ( v , v . len , UNROLLING_CUTOFF ) ) <EOL> def vector_to_improper ( v , curr ) : <EOL> for i in range ( v . len - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> curr = W_Cons . make ( v . ref ( i ) , curr ) <EOL> return curr <EOL> def to_mlist ( l ) : return to_mimproper ( l , w_null ) <EOL> @ jit . look_inside_iff ( <EOL> lambda l , curr : jit . loop_unrolling_heuristic ( l , len ( l ) , UNROLLING_CUTOFF ) ) <EOL> def to_mimproper ( l , curr ) : <EOL> for i in range ( len ( l ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> curr = W_MCons ( l [ i ] , curr ) <EOL> return curr <EOL> @ always_inline <EOL> def from_list_unroll_pred ( lst , idx , unroll_to = <NUM_LIT:0> ) : <EOL> if not jit . we_are_jitted ( ) : <EOL> return False <EOL> if unroll_to == - <NUM_LIT:1> : <EOL> return False <EOL> return not jit . isvirtual ( lst ) and idx > unroll_to <EOL> @ jit . elidable <EOL> def from_list_elidable ( w_curr ) : <EOL> result = [ ] <EOL> while isinstance ( w_curr , W_Cons ) : <EOL> result . append ( w_curr . car ( ) ) <EOL> w_curr = w_curr . cdr ( ) <EOL> if w_curr is w_null : <EOL> return result [ : ] <EOL> else : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> @ jit . unroll_safe <EOL> def from_list ( w_curr , unroll_to = <NUM_LIT:0> ) : <EOL> result = [ ] <EOL> n = <NUM_LIT:0> <EOL> while isinstance ( w_curr , W_Cons ) : <EOL> if from_list_unroll_pred ( w_curr , n , unroll_to = unroll_to ) : <EOL> return result + from_list_elidable ( w_curr ) <EOL> result . append ( w_curr . car ( ) ) <EOL> w_curr = w_curr . cdr ( ) <EOL> n += <NUM_LIT:1> <EOL> if w_curr is w_null : <EOL> return result [ : ] <EOL> else : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> def from_list_iter ( lst ) : <EOL> if not lst . is_proper_list ( ) : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> while isinstance ( lst , W_Cons ) : <EOL> val , lst = lst . car ( ) , lst . cdr ( ) <EOL> yield val <EOL> assert lst is w_null , "<STR_LIT>" <EOL> class W_Continuation ( W_Procedure ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , cont , prompt_tag = None ) : <EOL> self . cont = cont <EOL> self . prompt_tag = prompt_tag <EOL> def get_arity ( self ) : <EOL> return Arity . unknown <EOL> def call ( self , args , env , cont ) : <EOL> from pycket . prims . control import install_continuation <EOL> return install_continuation ( self . cont , self . prompt_tag , args , env , cont ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_ComposableContinuation ( W_Procedure ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def __init__ ( self , cont , prompt_tag = None ) : <EOL> self . cont = cont <EOL> self . prompt_tag = prompt_tag <EOL> def get_arity ( self ) : <EOL> return Arity . unknown <EOL> def call ( self , args , env , cont ) : <EOL> from pycket . prims . control import install_continuation <EOL> return install_continuation ( <EOL> self . cont , self . prompt_tag , args , env , cont , extend = True ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> @ inline_small_list ( immutable = True , attrname = "<STR_LIT>" , factoryname = "<STR_LIT>" ) <EOL> class W_Closure ( W_Procedure ) : <EOL> _immutable_fields_ = [ "<STR_LIT>" ] <EOL> @ jit . unroll_safe <EOL> def __init__ ( self , caselam , env ) : <EOL> self . caselam = caselam <EOL> for ( i , lam ) in enumerate ( caselam . lams ) : <EOL> vals = lam . collect_frees ( caselam . recursive_sym , env , self ) <EOL> self . _set_list ( i , ConsEnv . make ( vals , env . toplevel_env ( ) ) ) <EOL> def enable_jitting ( self ) : <EOL> self . caselam . enable_jitting ( ) <EOL> def tostring ( self ) : <EOL> return self . caselam . tostring_as_closure ( ) <EOL> @ staticmethod <EOL> @ jit . unroll_safe <EOL> def make ( caselam , env ) : <EOL> from pycket . interpreter import CaseLambda <EOL> assert isinstance ( caselam , CaseLambda ) <EOL> num_lams = len ( caselam . lams ) <EOL> if num_lams == <NUM_LIT:1> and caselam . any_frees : <EOL> env_size = len ( caselam . lams [ <NUM_LIT:0> ] . frees . elems ) <EOL> vals = caselam . lams [ <NUM_LIT:0> ] . collect_frees_without_recursive ( <EOL> caselam . recursive_sym , env ) <EOL> return W_Closure1AsEnv . make ( vals , caselam , env . toplevel_env ( ) ) <EOL> envs = [ None ] * num_lams <EOL> return W_Closure . _make ( envs , caselam , env ) <EOL> def get_arity ( self ) : <EOL> return self . caselam . get_arity ( ) <EOL> @ jit . unroll_safe <EOL> def _find_lam ( self , args ) : <EOL> jit . promote ( self . caselam ) <EOL> for i , lam in enumerate ( self . caselam . lams ) : <EOL> actuals = lam . match_args ( args ) <EOL> if actuals is not None : <EOL> frees = self . _get_list ( i ) <EOL> return actuals , frees , lam <EOL> if len ( self . caselam . lams ) == <NUM_LIT:1> : <EOL> single_lambda = self . caselam . lams [ <NUM_LIT:0> ] <EOL> single_lambda . raise_nice_error ( args ) <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> def call_with_extra_info ( self , args , env , cont , calling_app ) : <EOL> env_structure = None <EOL> if calling_app is not None : <EOL> env_structure = calling_app . env_structure <EOL> jit . promote ( self . caselam ) <EOL> jit . promote ( env_structure ) <EOL> ( actuals , frees , lam ) = self . _find_lam ( args ) <EOL> if not jit . we_are_jitted ( ) and env . pycketconfig ( ) . callgraph : <EOL> env . toplevel_env ( ) . callgraph . register_call ( lam , calling_app , cont , env ) <EOL> prev = lam . env_structure . prev . find_env_in_chain_speculate ( <EOL> frees , env_structure , env ) <EOL> return lam . make_begin_cont ( <EOL> ConsEnv . make ( actuals , prev ) , <EOL> cont ) <EOL> def call ( self , args , env , cont ) : <EOL> return self . call_with_extra_info ( args , env , cont , None ) <EOL> @ inline_small_list ( immutable = True , attrname = "<STR_LIT>" , factoryname = "<STR_LIT>" , unbox_num = True ) <EOL> class W_Closure1AsEnv ( ConsEnv ) : <EOL> _immutable_fields_ = [ '<STR_LIT>' ] <EOL> def __init__ ( self , caselam , prev ) : <EOL> ConsEnv . __init__ ( self , prev ) <EOL> self . caselam = caselam <EOL> @ staticmethod <EOL> @ jit . unroll_safe <EOL> def make ( vals , caselam , prev ) : <EOL> recursive_sym = caselam . recursive_sym <EOL> if not vals : <EOL> for s in caselam . lams [ <NUM_LIT:0> ] . frees . elems : <EOL> assert s is recursive_sym <EOL> return W_Closure1AsEnv . _make ( vals , caselam , prev ) <EOL> def iscallable ( self ) : <EOL> return True <EOL> def enable_jitting ( self ) : <EOL> self . caselam . enable_jitting ( ) <EOL> def immutable ( self ) : <EOL> return True <EOL> def tostring ( self ) : <EOL> return self . caselam . tostring_as_closure ( ) <EOL> def get_arity ( self ) : <EOL> return self . caselam . get_arity ( ) <EOL> def call_with_extra_info ( self , args , env , cont , calling_app ) : <EOL> env_structure = None <EOL> if calling_app is not None : <EOL> env_structure = calling_app . env_structure <EOL> jit . promote ( self . caselam ) <EOL> jit . promote ( env_structure ) <EOL> lam = self . caselam . lams [ <NUM_LIT:0> ] <EOL> if not jit . we_are_jitted ( ) and env . pycketconfig ( ) . callgraph : <EOL> env . toplevel_env ( ) . callgraph . register_call ( lam , calling_app , cont , env ) <EOL> actuals = lam . match_args ( args ) <EOL> if actuals is None : <EOL> lam . raise_nice_error ( args ) <EOL> prev = lam . env_structure . prev . find_env_in_chain_speculate ( <EOL> self , env_structure , env ) <EOL> return lam . make_begin_cont ( <EOL> ConsEnv . make ( actuals , prev ) , <EOL> cont ) <EOL> def call ( self , args , env , cont ) : <EOL> return self . call_with_extra_info ( args , env , cont , None ) <EOL> @ jit . unroll_safe <EOL> def consenv_get_size ( self ) : <EOL> result = self . _get_size_list ( ) <EOL> for s in self . caselam . lams [ <NUM_LIT:0> ] . frees . elems : <EOL> result += s is self . caselam . recursive_sym <EOL> return result <EOL> @ jit . unroll_safe <EOL> def lookup ( self , sym , env_structure ) : <EOL> jit . promote ( env_structure ) <EOL> if len ( env_structure . elems ) == self . _get_size_list ( ) : <EOL> return ConsEnv . lookup ( self , sym , env_structure ) <EOL> recursive_sym = jit . promote ( self . caselam ) . recursive_sym <EOL> if sym is recursive_sym : <EOL> return self <EOL> i = <NUM_LIT:0> <EOL> for s in env_structure . elems : <EOL> if s is recursive_sym : <EOL> continue <EOL> if s is sym : <EOL> v = self . _get_list ( i ) <EOL> assert v is not None <EOL> return v <EOL> i += <NUM_LIT:1> <EOL> prev = self . get_prev ( env_structure ) <EOL> return prev . lookup ( sym , env_structure . prev ) <EOL> class W_PromotableClosure ( W_Procedure ) : <EOL> """<STR_LIT>""" <EOL> _immutable_fields_ = [ "<STR_LIT>" ] <EOL> def __init__ ( self , caselam , toplevel_env ) : <EOL> self . closure = W_Closure . _make ( [ ConsEnv . make ( [ ] , toplevel_env ) ] * len ( caselam . lams ) , caselam , toplevel_env ) <EOL> def enable_jitting ( self ) : <EOL> self . closure . enable_jitting ( ) <EOL> def call ( self , args , env , cont ) : <EOL> jit . promote ( self ) <EOL> return self . closure . call ( args , env , cont ) <EOL> def call_with_extra_info ( self , args , env , cont , calling_app ) : <EOL> jit . promote ( self ) <EOL> return self . closure . call_with_extra_info ( args , env , cont , calling_app ) <EOL> def get_arity ( self ) : <EOL> return self . closure . get_arity ( ) <EOL> def tostring ( self ) : <EOL> return self . closure . tostring ( ) <EOL> class W_EnvVarSet ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : pass <EOL> class W_EOF ( W_Object ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : pass <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> eof_object = W_EOF ( ) <EOL> class W_Port ( W_Object ) : <EOL> errorname = "<STR_LIT:port>" <EOL> _attrs_ = [ '<STR_LIT>' ] <EOL> def __init__ ( self ) : <EOL> self . closed = False <EOL> def tostring ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def close ( self ) : <EOL> self . closed = True <EOL> def seek ( self , offset , end = False ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def tell ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class W_OutputPort ( W_Port ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def write ( self , str ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def flush ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> class W_StringOutputPort ( W_OutputPort ) : <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . closed = False <EOL> self . str = StringBuilder ( ) <EOL> def write ( self , s ) : <EOL> self . str . append ( s ) <EOL> def contents ( self ) : <EOL> return self . str . build ( ) <EOL> def seek ( self , offset , end = False ) : <EOL> if end or offset == self . str . getlength ( ) : <EOL> return <EOL> if offset > self . str . getlength ( ) : <EOL> self . str . append ( "<STR_LIT>" * ( self . str . getlength ( ) - offset ) ) <EOL> else : <EOL> content = self . contents ( ) <EOL> self . str = StringBuilder ( offset ) <EOL> self . str . append_slice ( content , <NUM_LIT:0> , offset ) <EOL> def tell ( self ) : <EOL> return self . str . getlength ( ) <EOL> class W_InputPort ( W_Port ) : <EOL> errorname = "<STR_LIT>" <EOL> _attrs_ = [ ] <EOL> def read ( self , n ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def peek ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def readline ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def tostring ( self ) : <EOL> return "<STR_LIT>" <EOL> def _length_up_to_end ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class W_StringInputPort ( W_InputPort ) : <EOL> _immutable_fields_ = [ "<STR_LIT:str>" ] <EOL> errorname = "<STR_LIT>" <EOL> def __init__ ( self , str ) : <EOL> self . closed = False <EOL> self . str = str <EOL> self . ptr = <NUM_LIT:0> <EOL> def readline ( self ) : <EOL> from rpython . rlib . rstring import find <EOL> start = self . ptr <EOL> assert start >= <NUM_LIT:0> <EOL> pos = find ( self . str , "<STR_LIT:\n>" , start , len ( self . str ) ) <EOL> if pos < <NUM_LIT:0> : <EOL> return self . read ( ) <EOL> else : <EOL> pos += <NUM_LIT:1> <EOL> stop = self . ptr = pos <EOL> return self . str [ start : stop ] <EOL> return line <EOL> def peek ( self ) : <EOL> if self . ptr >= len ( self . str ) : <EOL> return "<STR_LIT>" <EOL> return self . str [ self . ptr ] <EOL> def read ( self , n = - <NUM_LIT:1> ) : <EOL> if self . ptr >= len ( self . str ) : <EOL> return "<STR_LIT>" <EOL> p = self . ptr <EOL> assert p >= <NUM_LIT:0> <EOL> if n == - <NUM_LIT:1> or n >= ( len ( self . str ) - self . ptr ) : <EOL> self . ptr = len ( self . str ) <EOL> assert self . ptr >= <NUM_LIT:0> <EOL> return self . str [ p : ] <EOL> else : <EOL> self . ptr += n <EOL> stop = self . ptr <EOL> assert stop < len ( self . str ) <EOL> assert stop >= <NUM_LIT:0> <EOL> return self . str [ p : stop ] <EOL> def seek ( self , offset , end = False ) : <EOL> if end or offset == self . ptr : <EOL> self . ptr = len ( self . str ) <EOL> return <EOL> if offset > len ( self . str ) : <EOL> raise SchemeException ( "<STR_LIT>" ) <EOL> else : <EOL> self . ptr = offset <EOL> def tell ( self ) : <EOL> return self . ptr <EOL> def _length_up_to_end ( self ) : <EOL> return len ( self . str ) - self . ptr <EOL> class W_FileInputPort ( W_InputPort ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:file>" ] <EOL> def __init__ ( self , f ) : <EOL> self . closed = False <EOL> self . file = f <EOL> def close ( self ) : <EOL> self . closed = True <EOL> self . file . close ( ) <EOL> def read ( self , n ) : <EOL> return self . file . read ( n ) <EOL> def readline ( self ) : <EOL> return self . file . readline ( ) <EOL> def peek ( self ) : <EOL> offset , string = self . file . peek ( ) <EOL> if offset < len ( string ) : <EOL> return string [ offset ] <EOL> pos = self . file . tell ( ) <EOL> res = self . file . read ( <NUM_LIT:1> ) <EOL> self . file . seek ( pos , <NUM_LIT:0> ) <EOL> return res <EOL> def seek ( self , offset , end = False ) : <EOL> if end : <EOL> self . file . seek ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> else : <EOL> self . file . seek ( offset , <NUM_LIT:0> ) <EOL> def tell ( self ) : <EOL> return int ( intmask ( self . file . tell ( ) ) ) <EOL> def _length_up_to_end ( self ) : <EOL> old_ptr = self . tell ( ) <EOL> self . seek ( <NUM_LIT:0> , end = True ) <EOL> new_ptr = self . tell ( ) <EOL> self . seek ( old_ptr ) <EOL> return new_ptr - old_ptr <EOL> class W_FileOutputPort ( W_OutputPort ) : <EOL> errorname = "<STR_LIT>" <EOL> _immutable_fields_ = [ "<STR_LIT:file>" ] <EOL> def __init__ ( self , f ) : <EOL> self . closed = False <EOL> self . file = f <EOL> def write ( self , str ) : <EOL> self . file . write ( str ) <EOL> def flush ( self ) : <EOL> self . file . flush ( ) <EOL> def close ( self ) : <EOL> self . closed = True <EOL> self . file . close ( ) <EOL> def seek ( self , offset , end = False ) : <EOL> if end : <EOL> self . file . seek ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> else : <EOL> self . file . seek ( offset , <NUM_LIT:0> ) <EOL> def tell ( self ) : <EOL> return int ( intmask ( self . file . tell ( ) ) ) <EOL> @ specialize . call_location ( ) <EOL> def wrap_list ( pyval ) : <EOL> assert isinstance ( pyval , list ) <EOL> acc = w_null <EOL> for val in reversed ( pyval ) : <EOL> acc = wrap ( val , acc ) <EOL> return acc <EOL> @ specialize . ll ( ) <EOL> def wrap ( * _pyval ) : <EOL> if len ( _pyval ) == <NUM_LIT:1> : <EOL> pyval = _pyval [ <NUM_LIT:0> ] <EOL> if isinstance ( pyval , bool ) : <EOL> return w_true if pyval else w_false <EOL> if isinstance ( pyval , int ) : <EOL> return W_Fixnum ( pyval ) <EOL> if isinstance ( pyval , float ) : <EOL> return W_Flonum ( pyval ) <EOL> if isinstance ( pyval , W_Object ) : <EOL> return pyval <EOL> elif len ( _pyval ) == <NUM_LIT:2> : <EOL> car = _pyval [ <NUM_LIT:0> ] <EOL> cdr = wrap ( _pyval [ <NUM_LIT:1> ] ) <EOL> if isinstance ( car , bool ) : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_WrappedConsProper ( wrap ( car ) , cdr ) <EOL> return W_WrappedCons ( wrap ( car ) , cdr ) <EOL> if isinstance ( car , int ) : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_UnwrappedFixnumConsProper ( car , cdr ) <EOL> return W_UnwrappedFixnumCons ( car , cdr ) <EOL> if isinstance ( car , float ) : <EOL> if cdr . is_proper_list ( ) : <EOL> return W_UnwrappedFlonumConsProper ( car , cdr ) <EOL> return W_UnwrappedFlonumCons ( car , cdr ) <EOL> if isinstance ( car , W_Object ) : <EOL> return W_Cons . make ( car , cdr ) <EOL> assert False </s>
