@@ -76,7 +76,6 @@ typedef struct _PyCompiler compiler;
76
76
#define SCOPE_TYPE (C ) _PyCompile_ScopeType(C)
77
77
#define QUALNAME (C ) _PyCompile_Qualname(C)
78
78
#define METADATA (C ) _PyCompile_Metadata(C)
79
- #define ARENA (C ) _PyCompile_Arena(C)
80
79
81
80
typedef _PyInstruction instruction ;
82
81
typedef _PyInstructionSequence instr_sequence ;
@@ -209,6 +208,11 @@ static int codegen_call_simple_kw_helper(compiler *c,
209
208
location loc ,
210
209
asdl_keyword_seq * keywords ,
211
210
Py_ssize_t nkwelts );
211
+ static int codegen_call_helper_impl (compiler * c , location loc ,
212
+ int n , /* Args already pushed */
213
+ asdl_expr_seq * args ,
214
+ PyObject * injected_arg ,
215
+ asdl_keyword_seq * keywords );
212
216
static int codegen_call_helper (compiler * c , location loc ,
213
217
int n , asdl_expr_seq * args ,
214
218
asdl_keyword_seq * keywords );
@@ -1549,28 +1553,10 @@ codegen_class(compiler *c, stmt_ty s)
1549
1553
ADDOP_I_IN_SCOPE (c , loc , CALL_INTRINSIC_1 , INTRINSIC_SUBSCRIPT_GENERIC );
1550
1554
RETURN_IF_ERROR_IN_SCOPE (c , codegen_nameop (c , loc , & _Py_STR (generic_base ), Store ));
1551
1555
1552
- Py_ssize_t original_len = asdl_seq_LEN (s -> v .ClassDef .bases );
1553
- asdl_expr_seq * bases = _Py_asdl_expr_seq_new (
1554
- original_len + 1 , ARENA (c ));
1555
- if (bases == NULL ) {
1556
- _PyCompile_ExitScope (c );
1557
- return ERROR ;
1558
- }
1559
- for (Py_ssize_t i = 0 ; i < original_len ; i ++ ) {
1560
- asdl_seq_SET (bases , i , asdl_seq_GET (s -> v .ClassDef .bases , i ));
1561
- }
1562
- expr_ty name_node = _PyAST_Name (
1563
- & _Py_STR (generic_base ), Load ,
1564
- loc .lineno , loc .col_offset , loc .end_lineno , loc .end_col_offset , ARENA (c )
1565
- );
1566
- if (name_node == NULL ) {
1567
- _PyCompile_ExitScope (c );
1568
- return ERROR ;
1569
- }
1570
- asdl_seq_SET (bases , original_len , name_node );
1571
- RETURN_IF_ERROR_IN_SCOPE (c , codegen_call_helper (c , loc , 2 ,
1572
- bases ,
1573
- s -> v .ClassDef .keywords ));
1556
+ RETURN_IF_ERROR_IN_SCOPE (c , codegen_call_helper_impl (c , loc , 2 ,
1557
+ s -> v .ClassDef .bases ,
1558
+ & _Py_STR (generic_base ),
1559
+ s -> v .ClassDef .keywords ));
1574
1560
1575
1561
PyCodeObject * co = _PyCompile_OptimizeAndAssemble (c , 0 );
1576
1562
@@ -3187,19 +3173,18 @@ codegen_boolop(compiler *c, expr_ty e)
3187
3173
}
3188
3174
3189
3175
static int
3190
- starunpack_helper (compiler * c , location loc ,
3191
- asdl_expr_seq * elts , int pushed ,
3192
- int build , int add , int extend , int tuple )
3176
+ starunpack_helper_impl (compiler * c , location loc ,
3177
+ asdl_expr_seq * elts , PyObject * injected_arg , int pushed ,
3178
+ int build , int add , int extend , int tuple )
3193
3179
{
3194
3180
Py_ssize_t n = asdl_seq_LEN (elts );
3195
- if (n > 2 && are_all_items_const (elts , 0 , n )) {
3181
+ if (! injected_arg && n > 2 && are_all_items_const (elts , 0 , n )) {
3196
3182
PyObject * folded = PyTuple_New (n );
3197
3183
if (folded == NULL ) {
3198
3184
return ERROR ;
3199
3185
}
3200
- PyObject * val ;
3201
3186
for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
3202
- val = ((expr_ty )asdl_seq_GET (elts , i ))-> v .Constant .value ;
3187
+ PyObject * val = ((expr_ty )asdl_seq_GET (elts , i ))-> v .Constant .value ;
3203
3188
PyTuple_SET_ITEM (folded , i , Py_NewRef (val ));
3204
3189
}
3205
3190
if (tuple && !pushed ) {
@@ -3221,7 +3206,7 @@ starunpack_helper(compiler *c, location loc,
3221
3206
return SUCCESS ;
3222
3207
}
3223
3208
3224
- int big = n + pushed > STACK_USE_GUIDELINE ;
3209
+ int big = n + pushed + ( injected_arg ? 1 : 0 ) > STACK_USE_GUIDELINE ;
3225
3210
int seen_star = 0 ;
3226
3211
for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
3227
3212
expr_ty elt = asdl_seq_GET (elts , i );
@@ -3235,6 +3220,10 @@ starunpack_helper(compiler *c, location loc,
3235
3220
expr_ty elt = asdl_seq_GET (elts , i );
3236
3221
VISIT (c , expr , elt );
3237
3222
}
3223
+ if (injected_arg ) {
3224
+ RETURN_IF_ERROR (codegen_nameop (c , loc , injected_arg , Load ));
3225
+ n ++ ;
3226
+ }
3238
3227
if (tuple ) {
3239
3228
ADDOP_I (c , loc , BUILD_TUPLE , n + pushed );
3240
3229
} else {
@@ -3265,12 +3254,25 @@ starunpack_helper(compiler *c, location loc,
3265
3254
}
3266
3255
}
3267
3256
assert (sequence_built );
3257
+ if (injected_arg ) {
3258
+ RETURN_IF_ERROR (codegen_nameop (c , loc , injected_arg , Load ));
3259
+ ADDOP_I (c , loc , add , 1 );
3260
+ }
3268
3261
if (tuple ) {
3269
3262
ADDOP_I (c , loc , CALL_INTRINSIC_1 , INTRINSIC_LIST_TO_TUPLE );
3270
3263
}
3271
3264
return SUCCESS ;
3272
3265
}
3273
3266
3267
+ static int
3268
+ starunpack_helper (compiler * c , location loc ,
3269
+ asdl_expr_seq * elts , int pushed ,
3270
+ int build , int add , int extend , int tuple )
3271
+ {
3272
+ return starunpack_helper_impl (c , loc , elts , NULL , pushed ,
3273
+ build , add , extend , tuple );
3274
+ }
3275
+
3274
3276
static int
3275
3277
unpack_helper (compiler * c , location loc , asdl_expr_seq * elts )
3276
3278
{
@@ -3973,13 +3975,13 @@ codegen_call_simple_kw_helper(compiler *c, location loc,
3973
3975
return SUCCESS ;
3974
3976
}
3975
3977
3976
-
3977
3978
/* shared code between codegen_call and codegen_class */
3978
3979
static int
3979
- codegen_call_helper (compiler * c , location loc ,
3980
- int n , /* Args already pushed */
3981
- asdl_expr_seq * args ,
3982
- asdl_keyword_seq * keywords )
3980
+ codegen_call_helper_impl (compiler * c , location loc ,
3981
+ int n , /* Args already pushed */
3982
+ asdl_expr_seq * args ,
3983
+ PyObject * injected_arg ,
3984
+ asdl_keyword_seq * keywords )
3983
3985
{
3984
3986
Py_ssize_t i , nseen , nelts , nkwelts ;
3985
3987
@@ -4010,6 +4012,10 @@ codegen_call_helper(compiler *c, location loc,
4010
4012
assert (elt -> kind != Starred_kind );
4011
4013
VISIT (c , expr , elt );
4012
4014
}
4015
+ if (injected_arg ) {
4016
+ RETURN_IF_ERROR (codegen_nameop (c , loc , injected_arg , Load ));
4017
+ nelts ++ ;
4018
+ }
4013
4019
if (nkwelts ) {
4014
4020
VISIT_SEQ (c , keyword , keywords );
4015
4021
RETURN_IF_ERROR (
@@ -4024,12 +4030,12 @@ codegen_call_helper(compiler *c, location loc,
4024
4030
ex_call :
4025
4031
4026
4032
/* Do positional arguments. */
4027
- if (n == 0 && nelts == 1 && ((expr_ty )asdl_seq_GET (args , 0 ))-> kind == Starred_kind ) {
4033
+ if (n == 0 && nelts == 1 && ((expr_ty )asdl_seq_GET (args , 0 ))-> kind == Starred_kind ) {
4028
4034
VISIT (c , expr , ((expr_ty )asdl_seq_GET (args , 0 ))-> v .Starred .value );
4029
4035
}
4030
4036
else {
4031
- RETURN_IF_ERROR (starunpack_helper (c , loc , args , n , BUILD_LIST ,
4032
- LIST_APPEND , LIST_EXTEND , 1 ));
4037
+ RETURN_IF_ERROR (starunpack_helper_impl (c , loc , args , injected_arg , n ,
4038
+ BUILD_LIST , LIST_APPEND , LIST_EXTEND , 1 ));
4033
4039
}
4034
4040
/* Then keyword arguments */
4035
4041
if (nkwelts ) {
@@ -4074,6 +4080,14 @@ codegen_call_helper(compiler *c, location loc,
4074
4080
return SUCCESS ;
4075
4081
}
4076
4082
4083
+ static int
4084
+ codegen_call_helper (compiler * c , location loc ,
4085
+ int n , /* Args already pushed */
4086
+ asdl_expr_seq * args ,
4087
+ asdl_keyword_seq * keywords )
4088
+ {
4089
+ return codegen_call_helper_impl (c , loc , n , args , NULL , keywords );
4090
+ }
4077
4091
4078
4092
/* List and set comprehensions and generator expressions work by creating a
4079
4093
nested function to perform the actual iteration. This means that the
0 commit comments