<s> import autopath <EOL> import sys <EOL> import os <EOL> from pypy . lang . smalltalk import model , interpreter , primitives , shadow <EOL> from pypy . lang . smalltalk import squeakimage <EOL> from pypy . lang . smalltalk import constants <EOL> def tinyBenchmarks ( space , image ) : <EOL> interp = interpreter . Interpreter ( space ) <EOL> w_object = model . W_SmallInteger ( <NUM_LIT:0> ) <EOL> s_class = w_object . shadow_of_my_class ( space ) <EOL> w_method = s_class . lookup ( "<STR_LIT>" ) <EOL> assert w_method <EOL> w_frame = w_method . create_frame ( space , w_object , [ ] ) <EOL> interp . store_w_active_context ( w_frame ) <EOL> counter = <NUM_LIT:0> <EOL> from pypy . lang . smalltalk . interpreter import BYTECODE_TABLE <EOL> return interp <EOL> def run_benchmarks ( interp ) : <EOL> counter = <NUM_LIT:0> <EOL> try : <EOL> while True : <EOL> counter += <NUM_LIT:1> <EOL> interp . step ( ) <EOL> if counter == <NUM_LIT> : <EOL> counter = <NUM_LIT:0> <EOL> os . write ( <NUM_LIT:2> , '<STR_LIT:#>' ) <EOL> except interpreter . ReturnFromTopLevel , e : <EOL> w_result = e . object <EOL> assert isinstance ( w_result , model . W_BytesObject ) <EOL> print w_result . as_string ( ) <EOL> return <NUM_LIT:0> <EOL> from pypy . lang . smalltalk import objspace <EOL> space = objspace . ObjSpace ( ) <EOL> def entry_point ( argv ) : <EOL> if len ( argv ) > <NUM_LIT:1> : <EOL> filename = argv [ <NUM_LIT:1> ] <EOL> else : <EOL> print "<STR_LIT>" , argv [ <NUM_LIT:0> ] , "<STR_LIT>" <EOL> return - <NUM_LIT:1> <EOL> reader = squeakimage . ImageReader ( space , squeakimage . Stream ( DummyFile ( filename ) ) ) <EOL> reader . initialize ( ) <EOL> image = squeakimage . SqueakImage ( ) <EOL> image . from_reader ( space , reader ) <EOL> interp = tinyBenchmarks ( space , image ) <EOL> run_benchmarks ( interp ) <EOL> return <NUM_LIT:0> <EOL> def target ( * args ) : <EOL> return entry_point , None <EOL> class DummyFile : <EOL> def __init__ ( self , filename ) : <EOL> import os <EOL> fd = os . open ( filename , os . O_RDONLY , <NUM_LIT:0> <NUM_LIT> ) <EOL> try : <EOL> content = [ ] <EOL> while <NUM_LIT:1> : <EOL> s = os . read ( fd , <NUM_LIT> ) <EOL> if not s : <EOL> break <EOL> content . append ( s ) <EOL> self . content = "<STR_LIT>" . join ( content ) <EOL> finally : <EOL> os . close ( fd ) <EOL> def read ( self ) : <EOL> return self . content <EOL> def close ( self ) : <EOL> pass <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> entry_point ( sys . argv ) </s>
