aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/intrinsics.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/intrinsics.c')
-rw-r--r--Python/intrinsics.c69
1 files changed, 50 insertions, 19 deletions
diff --git a/Python/intrinsics.c b/Python/intrinsics.c
index 037b74ca820..61a8e75872d 100644
--- a/Python/intrinsics.c
+++ b/Python/intrinsics.c
@@ -14,7 +14,7 @@
/******** Unary functions ********/
static PyObject *
-no_intrinsic(PyThreadState* tstate, PyObject *unused)
+no_intrinsic1(PyThreadState* tstate, PyObject *unused)
{
_PyErr_SetString(tstate, PyExc_SystemError, "invalid intrinsic function");
return NULL;
@@ -203,25 +203,35 @@ make_typevar(PyThreadState* Py_UNUSED(ignored), PyObject *v)
return _Py_make_typevar(v, NULL, NULL);
}
-const instrinsic_func1
+
+#define INTRINSIC_FUNC_ENTRY(N, F) \
+ [N] = {F, #N},
+
+const intrinsic_func1_info
_PyIntrinsics_UnaryFunctions[] = {
- [0] = no_intrinsic,
- [INTRINSIC_PRINT] = print_expr,
- [INTRINSIC_IMPORT_STAR] = import_star,
- [INTRINSIC_STOPITERATION_ERROR] = stopiteration_error,
- [INTRINSIC_ASYNC_GEN_WRAP] = _PyAsyncGenValueWrapperNew,
- [INTRINSIC_UNARY_POSITIVE] = unary_pos,
- [INTRINSIC_LIST_TO_TUPLE] = list_to_tuple,
- [INTRINSIC_TYPEVAR] = make_typevar,
- [INTRINSIC_PARAMSPEC] = _Py_make_paramspec,
- [INTRINSIC_TYPEVARTUPLE] = _Py_make_typevartuple,
- [INTRINSIC_SUBSCRIPT_GENERIC] = _Py_subscript_generic,
- [INTRINSIC_TYPEALIAS] = _Py_make_typealias,
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_1_INVALID, no_intrinsic1)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_PRINT, print_expr)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_IMPORT_STAR, import_star)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_STOPITERATION_ERROR, stopiteration_error)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_ASYNC_GEN_WRAP, _PyAsyncGenValueWrapperNew)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_UNARY_POSITIVE, unary_pos)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_LIST_TO_TUPLE, list_to_tuple)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR, make_typevar)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_PARAMSPEC, _Py_make_paramspec)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVARTUPLE, _Py_make_typevartuple)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_SUBSCRIPT_GENERIC, _Py_subscript_generic)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEALIAS, _Py_make_typealias)
};
/******** Binary functions ********/
+static PyObject *
+no_intrinsic2(PyThreadState* tstate, PyObject *unused1, PyObject *unused2)
+{
+ _PyErr_SetString(tstate, PyExc_SystemError, "invalid intrinsic function");
+ return NULL;
+}
static PyObject *
prep_reraise_star(PyThreadState* unused, PyObject *orig, PyObject *excs)
@@ -246,10 +256,31 @@ make_typevar_with_constraints(PyThreadState* Py_UNUSED(ignored), PyObject *name,
return _Py_make_typevar(name, NULL, evaluate_constraints);
}
-const instrinsic_func2
+const intrinsic_func2_info
_PyIntrinsics_BinaryFunctions[] = {
- [INTRINSIC_PREP_RERAISE_STAR] = prep_reraise_star,
- [INTRINSIC_TYPEVAR_WITH_BOUND] = make_typevar_with_bound,
- [INTRINSIC_TYPEVAR_WITH_CONSTRAINTS] = make_typevar_with_constraints,
- [INTRINSIC_SET_FUNCTION_TYPE_PARAMS] = _Py_set_function_type_params,
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_2_INVALID, no_intrinsic2)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_PREP_RERAISE_STAR, prep_reraise_star)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR_WITH_BOUND, make_typevar_with_bound)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_TYPEVAR_WITH_CONSTRAINTS, make_typevar_with_constraints)
+ INTRINSIC_FUNC_ENTRY(INTRINSIC_SET_FUNCTION_TYPE_PARAMS, _Py_set_function_type_params)
};
+
+#undef INTRINSIC_FUNC_ENTRY
+
+PyObject*
+_PyUnstable_GetUnaryIntrinsicName(int index)
+{
+ if (index < 0 || index > MAX_INTRINSIC_1) {
+ return NULL;
+ }
+ return PyUnicode_FromString(_PyIntrinsics_UnaryFunctions[index].name);
+}
+
+PyObject*
+_PyUnstable_GetBinaryIntrinsicName(int index)
+{
+ if (index < 0 || index > MAX_INTRINSIC_2) {
+ return NULL;
+ }
+ return PyUnicode_FromString(_PyIntrinsics_BinaryFunctions[index].name);
+}