PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/rpython/jit/metainterp/test/test_call.py

https://bitbucket.org/oberstet/pypy
Python | 58 lines | 43 code | 15 blank | 0 comment | 2 complexity | 4615e76bb27485ad64c909f70aa83a50 MD5 | raw file
Possible License(s): Apache-2.0
  1. from rpython.jit.metainterp.test.support import LLJitMixin
  2. from rpython.rlib import jit
  3. class TestCall(LLJitMixin):
  4. def test_indirect_call(self):
  5. @jit.dont_look_inside
  6. def f1(x):
  7. return x + 1
  8. @jit.dont_look_inside
  9. def f2(x):
  10. return x + 2
  11. @jit.dont_look_inside
  12. def choice(i):
  13. if i:
  14. return f1
  15. return f2
  16. def f(i):
  17. func = choice(i)
  18. return func(i)
  19. res = self.interp_operations(f, [3])
  20. assert res == f(3)
  21. def test_call_elidable_none(self):
  22. d = {}
  23. @jit.elidable
  24. def f(a):
  25. return d.get(a, None)
  26. driver = jit.JitDriver(greens = [], reds = ['n'])
  27. def main(n):
  28. while n > 0:
  29. driver.jit_merge_point(n=n)
  30. f(n)
  31. f(n)
  32. n -= 1
  33. return 3
  34. self.meta_interp(main, [10])
  35. def test_cond_call(self):
  36. def f(l, n):
  37. l.append(n)
  38. def main(n):
  39. l = []
  40. jit.conditional_call(n == 10, f, l, n)
  41. return len(l)
  42. assert self.interp_operations(main, [10]) == 1
  43. assert self.interp_operations(main, [5]) == 0