Skip to content

Commit 74fc92e

Browse files
committed
do not generate Include/internal/pycore_intrinsics.h
1 parent 009e8f0 commit 74fc92e

File tree

11 files changed

+172
-91
lines changed

11 files changed

+172
-91
lines changed

Include/cpython/compile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ PyAPI_FUNC(int) PyUnstable_OpcodeHasFree(int opcode);
7777
PyAPI_FUNC(int) PyUnstable_OpcodeHasLocal(int opcode);
7878
PyAPI_FUNC(int) PyUnstable_OpcodeHasExc(int opcode);
7979

80+
PyAPI_FUNC(PyObject*) _PyUnstable_GetUnaryIntrinsicName(int index);
81+
PyAPI_FUNC(PyObject*) _PyUnstable_GetBinaryIntrinsicName(int index);

Include/internal/pycore_intrinsics.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Auto-generated by Tools/build/generate_opcode_h.py from Lib/opcode.py
21

32
/* Unary Functions: */
43
#define INTRINSIC_1_INVALID 0
@@ -26,7 +25,18 @@
2625

2726
#define MAX_INTRINSIC_2 4
2827

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[];

Lib/opcode.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ def pseudo_op(name, op, real_ops):
257257
__all__.extend(["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
258258
"hasjabs", "hasfree", "haslocal", "hasexc"])
259259

260+
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
261+
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
262+
260263
hascompare = [opmap["COMPARE_OP"]]
261264

262265
_nb_ops = [
@@ -288,29 +291,6 @@ def pseudo_op(name, op, real_ops):
288291
("NB_INPLACE_XOR", "^="),
289292
]
290293

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-
314294

315295
_cache_format = {
316296
"LOAD_GLOBAL": {

Makefile.pre.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,11 +1427,9 @@ regen-opcode:
14271427
$(srcdir)/Lib/opcode.py \
14281428
$(srcdir)/Lib/_opcode_metadata.py \
14291429
$(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
14321431
$(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new
14331432
$(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
14351433

14361434
.PHONY: regen-token
14371435
regen-token:

Modules/_opcode.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "compile.h"
33
#include "opcode.h"
44
#include "internal/pycore_code.h"
5+
#include "internal/pycore_intrinsics.h"
56

67
/*[clinic input]
78
module _opcode
@@ -220,6 +221,60 @@ _opcode_get_specialization_stats_impl(PyObject *module)
220221
#endif
221222
}
222223

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+
223278
static PyMethodDef
224279
opcode_functions[] = {
225280
_OPCODE_STACK_EFFECT_METHODDEF
@@ -232,6 +287,8 @@ opcode_functions[] = {
232287
_OPCODE_HAS_LOCAL_METHODDEF
233288
_OPCODE_HAS_EXC_METHODDEF
234289
_OPCODE_GET_SPECIALIZATION_STATS_METHODDEF
290+
_OPCODE_GET_INTRINSIC1_DESCS_METHODDEF
291+
_OPCODE_GET_INTRINSIC2_DESCS_METHODDEF
235292
{NULL, NULL, 0, NULL}
236293
};
237294

Modules/clinic/_opcode.c.h

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,14 +698,14 @@ dummy_func(
698698

699699
inst(CALL_INTRINSIC_1, (value -- res)) {
700700
assert(oparg <= MAX_INTRINSIC_1);
701-
res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value);
701+
res = _PyIntrinsics_UnaryFunctions[oparg].func(tstate, value);
702702
DECREF_INPUTS();
703703
ERROR_IF(res == NULL, error);
704704
}
705705

706706
inst(CALL_INTRINSIC_2, (value2, value1 -- res)) {
707707
assert(oparg <= MAX_INTRINSIC_2);
708-
res = _PyIntrinsics_BinaryFunctions[oparg](tstate, value2, value1);
708+
res = _PyIntrinsics_BinaryFunctions[oparg].func(tstate, value2, value1);
709709
DECREF_INPUTS();
710710
ERROR_IF(res == NULL, error);
711711
}

Python/executor_cases.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/intrinsics.c

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/******** Unary functions ********/
1515

1616
static PyObject *
17-
no_intrinsic(PyThreadState* tstate, PyObject *unused)
17+
no_intrinsic1(PyThreadState* tstate, PyObject *unused)
1818
{
1919
_PyErr_SetString(tstate, PyExc_SystemError, "invalid intrinsic function");
2020
return NULL;
@@ -203,25 +203,35 @@ make_typevar(PyThreadState* Py_UNUSED(ignored), PyObject *v)
203203
return _Py_make_typevar(v, NULL, NULL);
204204
}
205205

206-
const instrinsic_func1
206+
207+
#define INTRINSIC_FUNC_ENTRY(N, F) \
208+
[N] = {F, #N},
209+
210+
const intrinsic_func1_info
207211
_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)
220224
};
221225

222226

223227
/******** Binary functions ********/
224228

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+
}
225235

226236
static PyObject *
227237
prep_reraise_star(PyThreadState* unused, PyObject *orig, PyObject *excs)
@@ -246,10 +256,29 @@ make_typevar_with_constraints(PyThreadState* Py_UNUSED(ignored), PyObject *name,
246256
return _Py_make_typevar(name, NULL, evaluate_constraints);
247257
}
248258

249-
const instrinsic_func2
259+
const intrinsic_func2_info
250260
_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)
255266
};
267+
268+
PyObject*
269+
_PyUnstable_GetUnaryIntrinsicName(int index)
270+
{
271+
if (index < 0 || index > MAX_INTRINSIC_1) {
272+
return NULL;
273+
}
274+
return PyUnicode_FromString(_PyIntrinsics_UnaryFunctions[index].name);
275+
}
276+
277+
PyObject*
278+
_PyUnstable_GetBinaryIntrinsicName(int index)
279+
{
280+
if (index < 0 || index > MAX_INTRINSIC_2) {
281+
return NULL;
282+
}
283+
return PyUnicode_FromString(_PyIntrinsics_BinaryFunctions[index].name);
284+
}

0 commit comments

Comments
 (0)