PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/hotpy/tracing_opcode_gen.py

https://bitbucket.org/markshannon/hotpy_2
Python | 67 lines | 66 code | 1 blank | 0 comment | 1 complexity | 1e01e42696d11d9f9434469891a289ef MD5 | raw file
Possible License(s): BSD-3-Clause, 0BSD
  1. from surrogate_opcode_gen import binary_operators, unary_operators
  2. for iname, opname, sname in binary_operators:
  3. print('''
  4. TARGET(BINARY_%s)
  5. {
  6. int b;
  7. RECORD_SET_LASTI(f->f_lasti);
  8. w = POP();
  9. v = POP();
  10. REQUIRE_TYPE(1, Py_TYPE(w));
  11. REQUIRE_TYPE(2, Py_TYPE(v));
  12. b = _PyLookupBinaryFastFunction(nb_%s, v, w);
  13. if (b) {
  14. COMMENT("%s");
  15. x = _PyCallBinaryFastFunction(b, v, w);
  16. PUSH(x);
  17. RECORD_BINARY(b, x);
  18. Py_DECREF(v);
  19. Py_DECREF(w);
  20. }
  21. else {
  22. CALL_SURROGATE(surrogate_%s, 2);
  23. }
  24. if (x != NULL) DISPATCH();
  25. break;
  26. }
  27. ''' % (iname.upper(), opname, opname, sname))
  28. print('''
  29. TARGET(INPLACE_%s)
  30. {
  31. int b;
  32. RECORD_SET_LASTI(f->f_lasti);
  33. w = POP();
  34. v = POP();
  35. REQUIRE_TYPE(1, Py_TYPE(w));
  36. REQUIRE_TYPE(2, Py_TYPE(v));
  37. b = _PyLookupBinaryFastFunction(nb_inplace_%s, v, w);
  38. if (b) {
  39. COMMENT("%s");
  40. x = _PyCallBinaryFastFunction(b, v, w);
  41. PUSH(x);
  42. RECORD_BINARY(b, x);
  43. Py_DECREF(v);
  44. Py_DECREF(w);
  45. }
  46. else {
  47. CALL_SURROGATE(surrogate_inplace_%s, 2);
  48. }
  49. if (x != NULL) DISPATCH();
  50. break;
  51. }
  52. ''' % (iname.upper(), opname, opname, sname))
  53. for opname in unary_operators:
  54. print(''' TARGET(UNARY_%s)
  55. RECORD_SET_LASTI(f->f_lasti);
  56. w = POP();
  57. REQUIRE_TYPE(1, Py_TYPE(w));
  58. CALL_SURROGATE(surrogate_%s, 1);
  59. if (x != NULL) DISPATCH();
  60. break;
  61. ''' % (opname.upper(), opname))