| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,3 +77,5 @@ PyAPI_FUNC(int) PyUnstable_OpcodeHasFree(int opcode); | |||
| 77 | 77 | PyAPI_FUNC(int) PyUnstable_OpcodeHasLocal(int opcode); | |
| 78 | 78 | PyAPI_FUNC(int) PyUnstable_OpcodeHasExc(int opcode); | |
| 79 | 79 | ||
| 80 | + PyAPI_FUNC(PyObject*) _PyUnstable_GetUnaryIntrinsicName(int index); | ||
| 81 | + PyAPI_FUNC(PyObject*) _PyUnstable_GetBinaryIntrinsicName(int index); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - // Auto-generated by Tools/build/generate_opcode_h.py from Lib/opcode.py | ||
| 2 | 1 | ||
| 3 | 2 | /* Unary Functions: */ | |
| 4 | 3 | #define INTRINSIC_1_INVALID 0 | |
@@ -26,7 +25,18 @@ | |||
| 26 | 25 | ||
| 27 | 26 | #define MAX_INTRINSIC_2 4 | |
| 28 | 27 | ||
| 29 | - typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value); | ||
| 30 | - typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2); | ||
| 31 | - extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[]; | ||
| 32 | - extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[]; | ||
| 28 | + typedef PyObject *(*intrinsic_func1)(PyThreadState* tstate, PyObject *value); | ||
| 29 | + typedef PyObject *(*intrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2); | ||
| 30 | + | ||
| 31 | + typedef struct { | ||
| 32 | + intrinsic_func1 func; | ||
| 33 | + const char *name; | ||
| 34 | + } intrinsic_func1_info; | ||
| 35 | + | ||
| 36 | + typedef struct { | ||
| 37 | + intrinsic_func2 func; | ||
| 38 | + const char *name; | ||
| 39 | + } intrinsic_func2_info; | ||
| 40 | + | ||
| 41 | + extern const intrinsic_func1_info _PyIntrinsics_UnaryFunctions[]; | ||
| 42 | + extern const intrinsic_func2_info _PyIntrinsics_BinaryFunctions[]; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,6 +257,9 @@ def pseudo_op(name, op, real_ops): | |||
| 257 | 257 | __all__.extend(["hasarg", "hasconst", "hasname", "hasjump", "hasjrel", | |
| 258 | 258 | "hasjabs", "hasfree", "haslocal", "hasexc"]) | |
| 259 | 259 | ||
| 260 | + _intrinsic_1_descs = _opcode.get_intrinsic1_descs() | ||
| 261 | + _intrinsic_2_descs = _opcode.get_intrinsic2_descs() | ||
| 262 | + | ||
| 260 | 263 | hascompare = [opmap["COMPARE_OP"]] | |
| 261 | 264 | ||
| 262 | 265 | _nb_ops = [ | |
@@ -288,29 +291,6 @@ def pseudo_op(name, op, real_ops): | |||
| 288 | 291 | ("NB_INPLACE_XOR", "^="), | |
| 289 | 292 | ] | |
| 290 | 293 | ||
| 291 | - _intrinsic_1_descs = [ | ||
| 292 | - "INTRINSIC_1_INVALID", | ||
| 293 | - "INTRINSIC_PRINT", | ||
| 294 | - "INTRINSIC_IMPORT_STAR", | ||
| 295 | - "INTRINSIC_STOPITERATION_ERROR", | ||
| 296 | - "INTRINSIC_ASYNC_GEN_WRAP", | ||
| 297 | - "INTRINSIC_UNARY_POSITIVE", | ||
| 298 | - "INTRINSIC_LIST_TO_TUPLE", | ||
| 299 | - "INTRINSIC_TYPEVAR", | ||
| 300 | - "INTRINSIC_PARAMSPEC", | ||
| 301 | - "INTRINSIC_TYPEVARTUPLE", | ||
| 302 | - "INTRINSIC_SUBSCRIPT_GENERIC", | ||
| 303 | - "INTRINSIC_TYPEALIAS", | ||
| 304 | - ] | ||
| 305 | - | ||
| 306 | - _intrinsic_2_descs = [ | ||
| 307 | - "INTRINSIC_2_INVALID", | ||
| 308 | - "INTRINSIC_PREP_RERAISE_STAR", | ||
| 309 | - "INTRINSIC_TYPEVAR_WITH_BOUND", | ||
| 310 | - "INTRINSIC_TYPEVAR_WITH_CONSTRAINTS", | ||
| 311 | - "INTRINSIC_SET_FUNCTION_TYPE_PARAMS", | ||
| 312 | - ] | ||
| 313 | - | ||
| 314 | 294 | ||
| 315 | 295 | _cache_format = { | |
| 316 | 296 | "LOAD_GLOBAL": { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1427,11 +1427,9 @@ regen-opcode: | |||
| 1427 | 1427 | $(srcdir)/Lib/opcode.py \ | |
| 1428 | 1428 | $(srcdir)/Lib/_opcode_metadata.py \ | |
| 1429 | 1429 | $(srcdir)/Include/opcode.h.new \ | |
| 1430 | - $(srcdir)/Include/internal/pycore_opcode.h.new \ | ||
| 1431 | - $(srcdir)/Include/internal/pycore_intrinsics.h.new | ||
| 1430 | + $(srcdir)/Include/internal/pycore_opcode.h.new | ||
| 1432 | 1431 | $(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new | |
| 1433 | 1432 | $(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode.h $(srcdir)/Include/internal/pycore_opcode.h.new | |
| 1434 | - $(UPDATE_FILE) $(srcdir)/Include/internal/pycore_intrinsics.h $(srcdir)/Include/internal/pycore_intrinsics.h.new | ||
| 1435 | 1433 | ||
| 1436 | 1434 | .PHONY: regen-token | |
| 1437 | 1435 | regen-token: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | #include "compile.h" | |
| 3 | 3 | #include "opcode.h" | |
| 4 | 4 | #include "internal/pycore_code.h" | |
| 5 | + #include "internal/pycore_intrinsics.h" | ||
| 5 | 6 | ||
| 6 | 7 | /*[clinic input] | |
| 7 | 8 | module _opcode | |
@@ -220,6 +221,60 @@ _opcode_get_specialization_stats_impl(PyObject *module) | |||
| 220 | 221 | #endif | |
| 221 | 222 | } | |
| 222 | 223 | ||
| 224 | + /*[clinic input] | ||
| 225 | + | ||
| 226 | + _opcode.get_intrinsic1_descs | ||
| 227 | + | ||
| 228 | + Return a list of names of the unary intrinsics. | ||
| 229 | + [clinic start generated code]*/ | ||
| 230 | + | ||
| 231 | + static PyObject * | ||
| 232 | + _opcode_get_intrinsic1_descs_impl(PyObject *module) | ||
| 233 | + /*[clinic end generated code: output=bd1ddb6b4447d18b input=13b51c712618459b]*/ | ||
| 234 | + { | ||
| 235 | + PyObject *list = PyList_New(MAX_INTRINSIC_1 + 1); | ||
| 236 | + if (list == NULL) { | ||
| 237 | + return NULL; | ||
| 238 | + } | ||
| 239 | + for (int i=0; i <= MAX_INTRINSIC_1; i++) { | ||
| 240 | + PyObject *name = _PyUnstable_GetUnaryIntrinsicName(i); | ||
| 241 | + if (name == NULL) { | ||
| 242 | + Py_DECREF(list); | ||
| 243 | + return NULL; | ||
| 244 | + } | ||
| 245 | + PyList_SET_ITEM(list, i, name); | ||
| 246 | + } | ||
| 247 | + return list; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + | ||
| 251 | + /*[clinic input] | ||
| 252 | + | ||
| 253 | + _opcode.get_intrinsic2_descs | ||
| 254 | + | ||
| 255 | + Return a list of names of the binary intrinsics. | ||
| 256 | + [clinic start generated code]*/ | ||
| 257 | + | ||
| 258 | + static PyObject * | ||
| 259 | + _opcode_get_intrinsic2_descs_impl(PyObject *module) | ||
| 260 | + /*[clinic end generated code: output=40e62bc27584c8a0 input=e83068f249f5471b]*/ | ||
| 261 | + { | ||
| 262 | + PyObject *list = PyList_New(MAX_INTRINSIC_2 + 1); | ||
| 263 | + if (list == NULL) { | ||
| 264 | + return NULL; | ||
| 265 | + } | ||
| 266 | + for (int i=0; i <= MAX_INTRINSIC_2; i++) { | ||
| 267 | + PyObject *name = _PyUnstable_GetBinaryIntrinsicName(i); | ||
| 268 | + if (name == NULL) { | ||
| 269 | + Py_DECREF(list); | ||
| 270 | + return NULL; | ||
| 271 | + } | ||
| 272 | + PyList_SET_ITEM(list, i, name); | ||
| 273 | + } | ||
| 274 | + return list; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + | ||
| 223 | 278 | static PyMethodDef | |
| 224 | 279 | opcode_functions[] = { | |
| 225 | 280 | _OPCODE_STACK_EFFECT_METHODDEF | |
@@ -232,6 +287,8 @@ opcode_functions[] = { | |||
| 232 | 287 | _OPCODE_HAS_LOCAL_METHODDEF | |
| 233 | 288 | _OPCODE_HAS_EXC_METHODDEF | |
| 234 | 289 | _OPCODE_GET_SPECIALIZATION_STATS_METHODDEF | |
| 290 | + _OPCODE_GET_INTRINSIC1_DESCS_METHODDEF | ||
| 291 | + _OPCODE_GET_INTRINSIC2_DESCS_METHODDEF | ||
| 235 | 292 | {NULL, NULL, 0, NULL} | |
| 236 | 293 | }; | |
| 237 | 294 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -698,14 +698,14 @@ dummy_func( | |||
| 698 | 698 | ||
| 699 | 699 | inst(CALL_INTRINSIC_1, (value -- res)) { | |
| 700 | 700 | assert(oparg <= MAX_INTRINSIC_1); | |
| 701 | - res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value); | ||
| 701 | + res = _PyIntrinsics_UnaryFunctions[oparg].func(tstate, value); | ||
| 702 | 702 | DECREF_INPUTS(); | |
| 703 | 703 | ERROR_IF(res == NULL, error); | |
| 704 | 704 | } | |
| 705 | 705 | ||
| 706 | 706 | inst(CALL_INTRINSIC_2, (value2, value1 -- res)) { | |
| 707 | 707 | assert(oparg <= MAX_INTRINSIC_2); | |
| 708 | - res = _PyIntrinsics_BinaryFunctions[oparg](tstate, value2, value1); | ||
| 708 | + res = _PyIntrinsics_BinaryFunctions[oparg].func(tstate, value2, value1); | ||
| 709 | 709 | DECREF_INPUTS(); | |
| 710 | 710 | ERROR_IF(res == NULL, error); | |
| 711 | 711 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ | |||
| 14 | 14 | /******** Unary functions ********/ | |
| 15 | 15 | ||
| 16 | 16 | static PyObject * | |
| 17 | - no_intrinsic(PyThreadState* tstate, PyObject *unused) | ||
| 17 | + no_intrinsic1(PyThreadState* tstate, PyObject *unused) | ||
| 18 | 18 | { | |
| 19 | 19 | _PyErr_SetString(tstate, PyExc_SystemError, "invalid intrinsic function"); | |
| 20 | 20 | return NULL; | |
@@ -203,25 +203,35 @@ make_typevar(PyThreadState* Py_UNUSED(ignored), PyObject *v) | |||
| 203 | 203 | return _Py_make_typevar(v, NULL, NULL); | |
| 204 | 204 | } | |
| 205 | 205 | ||
| 206 | - const instrinsic_func1 | ||
| 206 | + | ||
| 207 | + #define INTRINSIC_FUNC_ENTRY(N, F) \ | ||
| 208 | + [N] = {F, #N}, | ||
| 209 | + | ||
| 210 | + const intrinsic_func1_info | ||
| 207 | 211 | _PyIntrinsics_UnaryFunctions[] = { | |
| 208 | - [0] = no_intrinsic, | ||
| 209 | - [INTRINSIC_PRINT] = print_expr, | ||
| 210 | - [INTRINSIC_IMPORT_STAR] = import_star, | ||
| 211 | - [INTRINSIC_STOPITERATION_ERROR] = stopiteration_error, | ||
| 212 | - [INTRINSIC_ASYNC_GEN_WRAP] = _PyAsyncGenValueWrapperNew, | ||
| 213 | - [INTRINSIC_UNARY_POSITIVE] = unary_pos, | ||
| 214 | - [INTRINSIC_LIST_TO_TUPLE] = list_to_tuple, | ||
| 215 | - [INTRINSIC_TYPEVAR] = make_typevar, | ||
| 216 | - [INTRINSIC_PARAMSPEC] = _Py_make_paramspec, | ||
| 217 | - [INTRINSIC_TYPEVARTUPLE] = _Py_make_typevartuple, | ||
| 218 | - [INTRINSIC_SUBSCRIPT_GENERIC] = _Py_subscript_generic, | ||
| 219 | - [INTRINSIC_TYPEALIAS] = _Py_make_typealias, | ||
| 212 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_1_INVALID, no_intrinsic1) | ||
| 213 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_PRINT, print_expr) | ||
| 214 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_IMPORT_STAR, import_star) | ||
| 215 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_STOPITERATION_ERROR, stopiteration_error) | ||
| 216 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_ASYNC_GEN_WRAP, _PyAsyncGenValueWrapperNew) | ||
| 217 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_UNARY_POSITIVE, unary_pos) | ||
| 218 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_LIST_TO_TUPLE, list_to_tuple) | ||
| 219 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR, make_typevar) | ||
| 220 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_PARAMSPEC, _Py_make_paramspec) | ||
| 221 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVARTUPLE, _Py_make_typevartuple) | ||
| 222 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_SUBSCRIPT_GENERIC, _Py_subscript_generic) | ||
| 223 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEALIAS, _Py_make_typealias) | ||
| 220 | 224 | }; | |
| 221 | 225 | ||
| 222 | 226 | ||
| 223 | 227 | /******** Binary functions ********/ | |
| 224 | 228 | ||
| 229 | + static PyObject * | ||
| 230 | + no_intrinsic2(PyThreadState* tstate, PyObject *unused1, PyObject *unused2) | ||
| 231 | + { | ||
| 232 | + _PyErr_SetString(tstate, PyExc_SystemError, "invalid intrinsic function"); | ||
| 233 | + return NULL; | ||
| 234 | + } | ||
| 225 | 235 | ||
| 226 | 236 | static PyObject * | |
| 227 | 237 | prep_reraise_star(PyThreadState* unused, PyObject *orig, PyObject *excs) | |
@@ -246,10 +256,31 @@ make_typevar_with_constraints(PyThreadState* Py_UNUSED(ignored), PyObject *name, | |||
| 246 | 256 | return _Py_make_typevar(name, NULL, evaluate_constraints); | |
| 247 | 257 | } | |
| 248 | 258 | ||
| 249 | - const instrinsic_func2 | ||
| 259 | + const intrinsic_func2_info | ||
| 250 | 260 | _PyIntrinsics_BinaryFunctions[] = { | |
| 251 | - [INTRINSIC_PREP_RERAISE_STAR] = prep_reraise_star, | ||
| 252 | - [INTRINSIC_TYPEVAR_WITH_BOUND] = make_typevar_with_bound, | ||
| 253 | - [INTRINSIC_TYPEVAR_WITH_CONSTRAINTS] = make_typevar_with_constraints, | ||
| 254 | - [INTRINSIC_SET_FUNCTION_TYPE_PARAMS] = _Py_set_function_type_params, | ||
| 261 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_2_INVALID, no_intrinsic2) | ||
| 262 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_PREP_RERAISE_STAR, prep_reraise_star) | ||
| 263 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR_WITH_BOUND, make_typevar_with_bound) | ||
| 264 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR_WITH_CONSTRAINTS, make_typevar_with_constraints) | ||
| 265 | + INTRINSIC_FUNC_ENTRY(INTRINSIC_SET_FUNCTION_TYPE_PARAMS, _Py_set_function_type_params) | ||
| 255 | 266 | }; | |
| 267 | + | ||
| 268 | + #undef INTRINSIC_FUNC_ENTRY | ||
| 269 | + | ||
| 270 | + PyObject* | ||
| 271 | + _PyUnstable_GetUnaryIntrinsicName(int index) | ||
| 272 | + { | ||
| 273 | + if (index < 0 || index > MAX_INTRINSIC_1) { | ||
| 274 | + return NULL; | ||
| 275 | + } | ||
| 276 | + return PyUnicode_FromString(_PyIntrinsics_UnaryFunctions[index].name); | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + PyObject* | ||
| 280 | + _PyUnstable_GetBinaryIntrinsicName(int index) | ||
| 281 | + { | ||
| 282 | + if (index < 0 || index > MAX_INTRINSIC_2) { | ||
| 283 | + return NULL; | ||
| 284 | + } | ||
| 285 | + return PyUnicode_FromString(_PyIntrinsics_BinaryFunctions[index].name); | ||
| 286 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments