<s> import py <EOL> from pypy . rlib . jit import JitDriver , OPTIMIZER_SIMPLE <EOL> from pypy . jit . metainterp . policy import StopAtXPolicy <EOL> from pypy . jit . metainterp . test . test_basic import OOJitMixin , LLJitMixin <EOL> class ToyLanguageTests : <EOL> def test_tlr ( self ) : <EOL> from pypy . jit . tl . tlr import interpret , SQUARE <EOL> codes = [ "<STR_LIT>" , SQUARE ] <EOL> def main ( n , a ) : <EOL> code = codes [ n ] <EOL> return interpret ( code , a ) <EOL> res = self . meta_interp ( main , [ <NUM_LIT:1> , <NUM_LIT:10> ] ) <EOL> assert res == <NUM_LIT:100> <EOL> def _get_main ( self ) : <EOL> from pypy . jit . tl . tl import interp_without_call <EOL> from pypy . jit . tl . tlopcode import compile <EOL> code = compile ( '''<STR_LIT>''' ) <EOL> code2 = compile ( '''<STR_LIT>''' ) <EOL> codes = [ code , code2 ] <EOL> def main ( n , inputarg ) : <EOL> code = codes [ n ] <EOL> return interp_without_call ( code , inputarg = inputarg ) <EOL> return main <EOL> def test_tl_base ( self ) : <EOL> main = self . _get_main ( ) <EOL> res = self . meta_interp ( main , [ <NUM_LIT:0> , <NUM_LIT:6> ] , listops = True , <EOL> backendopt = True ) <EOL> assert res == <NUM_LIT> <EOL> self . check_loops ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> def test_tl_2 ( self ) : <EOL> main = self . _get_main ( ) <EOL> res = self . meta_interp ( main , [ <NUM_LIT:1> , <NUM_LIT:10> ] , listops = True , <EOL> backendopt = True ) <EOL> assert res == main ( <NUM_LIT:1> , <NUM_LIT:10> ) <EOL> self . check_loops ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> def test_tl_call ( self , listops = True , policy = None ) : <EOL> from pypy . jit . tl . tl import interp <EOL> from pypy . jit . tl . tlopcode import compile <EOL> from pypy . jit . metainterp import simple_optimize <EOL> code = compile ( '''<STR_LIT>''' ) <EOL> assert interp ( code , inputarg = <NUM_LIT:100> ) == <NUM_LIT:0> <EOL> codes = [ code , '<STR_LIT>' ] <EOL> def main ( num , arg ) : <EOL> return interp ( codes [ num ] , inputarg = arg ) <EOL> res = self . meta_interp ( main , [ <NUM_LIT:0> , <NUM_LIT:20> ] , optimizer = OPTIMIZER_SIMPLE , <EOL> listops = listops , backendopt = True , policy = policy ) <EOL> assert res == <NUM_LIT:0> <EOL> def test_tl_call_full_of_residuals ( self ) : <EOL> from pypy . jit . tl . tl import Stack <EOL> methods = [ Stack . put , <EOL> Stack . pick , <EOL> Stack . roll , <EOL> Stack . append , <EOL> Stack . pop ] <EOL> for meth in methods : <EOL> meth_func = meth . im_func <EOL> assert not hasattr ( meth_func , '<STR_LIT>' ) <EOL> meth_func . _jit_look_inside_ = False <EOL> try : <EOL> self . test_tl_call ( listops = False ) <EOL> finally : <EOL> for meth in methods : <EOL> meth_func = meth . im_func <EOL> del meth_func . _jit_look_inside_ <EOL> class TestOOtype ( ToyLanguageTests , OOJitMixin ) : <EOL> pass <EOL> class TestLLtype ( ToyLanguageTests , LLJitMixin ) : <EOL> pass </s>
