/Lib/hotpy/tracing_opcode_gen.py
Python | 67 lines | 66 code | 1 blank | 0 comment | 1 complexity | 1e01e42696d11d9f9434469891a289ef MD5 | raw file
Possible License(s): BSD-3-Clause, 0BSD
- from surrogate_opcode_gen import binary_operators, unary_operators
- for iname, opname, sname in binary_operators:
- print('''
- TARGET(BINARY_%s)
- {
- int b;
- RECORD_SET_LASTI(f->f_lasti);
- w = POP();
- v = POP();
- REQUIRE_TYPE(1, Py_TYPE(w));
- REQUIRE_TYPE(2, Py_TYPE(v));
- b = _PyLookupBinaryFastFunction(nb_%s, v, w);
- if (b) {
- COMMENT("%s");
- x = _PyCallBinaryFastFunction(b, v, w);
- PUSH(x);
- RECORD_BINARY(b, x);
- Py_DECREF(v);
- Py_DECREF(w);
- }
- else {
- CALL_SURROGATE(surrogate_%s, 2);
- }
- if (x != NULL) DISPATCH();
- break;
- }
- ''' % (iname.upper(), opname, opname, sname))
- print('''
- TARGET(INPLACE_%s)
- {
- int b;
- RECORD_SET_LASTI(f->f_lasti);
- w = POP();
- v = POP();
- REQUIRE_TYPE(1, Py_TYPE(w));
- REQUIRE_TYPE(2, Py_TYPE(v));
- b = _PyLookupBinaryFastFunction(nb_inplace_%s, v, w);
- if (b) {
- COMMENT("%s");
- x = _PyCallBinaryFastFunction(b, v, w);
- PUSH(x);
- RECORD_BINARY(b, x);
- Py_DECREF(v);
- Py_DECREF(w);
- }
- else {
- CALL_SURROGATE(surrogate_inplace_%s, 2);
- }
- if (x != NULL) DISPATCH();
- break;
- }
- ''' % (iname.upper(), opname, opname, sname))
- for opname in unary_operators:
- print(''' TARGET(UNARY_%s)
- RECORD_SET_LASTI(f->f_lasti);
- w = POP();
- REQUIRE_TYPE(1, Py_TYPE(w));
- CALL_SURROGATE(surrogate_%s, 1);
- if (x != NULL) DISPATCH();
- break;
- ''' % (opname.upper(), opname))