@@ -134,6 +134,7 @@ struct location {
134
134
int end_col_offset ;
135
135
};
136
136
137
+
137
138
#define LOCATION (LNO , END_LNO , COL , END_COL ) \
138
139
((const struct location){(LNO), (END_LNO), (COL), (END_COL)})
139
140
@@ -432,6 +433,8 @@ typedef struct {
432
433
433
434
static int basicblock_next_instr (basicblock * );
434
435
436
+ static int cfg_builder_addop_i (cfg_builder * g , int opcode , Py_ssize_t oparg , struct location loc );
437
+
435
438
static void compiler_free (struct compiler * );
436
439
static int compiler_error (struct compiler * , const char * , ...);
437
440
static int compiler_warn (struct compiler * , const char * , ...);
@@ -1296,19 +1299,7 @@ cfg_builder_addop(cfg_builder *g, int opcode, int oparg, basicblock *target,
1296
1299
1297
1300
/* Add an instruction with no arg. Returns 0 on failure, 1 on success. */
1298
1301
#define CFG_BUILDER_ADDOP_NOARG (G , OP , LOC ) \
1299
- cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, LOC)
1300
-
1301
- /* Add an instructon with integer arg. Returns 0 on failure and 1 on success.
1302
- * oparg value is unsigned, but a signed C int is usually used to store
1303
- * it in the C code (like Python/ceval.c).
1304
- *
1305
- * Limit to 32-bit signed C int (rather than INT_MAX) for portability.
1306
- *
1307
- * The argument of a concrete bytecode instruction is limited to 8-bit.
1308
- * EXTENDED_ARG is used for 16, 24, and 32-bit arguments.
1309
- */
1310
- #define CFG_BUILDER_ADDOP_I (G , OP , ARG , LOC ) \
1311
- cfg_builder_addop(G, OP, Py_SAFE_DOWNCAST(ARG, Py_ssize_t, int), NULL, LOC)
1302
+ cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, LOC)
1312
1303
1313
1304
/* Add a jump instruction. Returns 0 on faiure, 1 on success. */
1314
1305
#define CFG_BUILDER_ADDOP_J (G , OP , T , LOC ) \
@@ -1471,7 +1462,7 @@ compiler_addop_load_const(struct compiler *c, PyObject *o)
1471
1462
Py_ssize_t arg = compiler_add_const (c , o );
1472
1463
if (arg < 0 )
1473
1464
return 0 ;
1474
- return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), LOAD_CONST , arg , COMPILER_LOC (c ));
1465
+ return cfg_builder_addop_i (CFG_BUILDER (c ), LOAD_CONST , arg , COMPILER_LOC (c ));
1475
1466
}
1476
1467
1477
1468
static int
@@ -1481,7 +1472,7 @@ compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,
1481
1472
Py_ssize_t arg = dict_add_o (dict , o );
1482
1473
if (arg < 0 )
1483
1474
return 0 ;
1484
- return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1475
+ return cfg_builder_addop_i (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1485
1476
}
1486
1477
1487
1478
static int
@@ -1505,7 +1496,25 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
1505
1496
arg <<= 1 ;
1506
1497
arg |= 1 ;
1507
1498
}
1508
- return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1499
+ return cfg_builder_addop_i (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1500
+ }
1501
+
1502
+ /* Add an opcode with an integer argument.
1503
+ Returns 0 on failure, 1 on success.
1504
+ */
1505
+ static int
1506
+ cfg_builder_addop_i (cfg_builder * g , int opcode , Py_ssize_t oparg , struct location loc )
1507
+ {
1508
+ /* oparg value is unsigned, but a signed C int is usually used to store
1509
+ it in the C code (like Python/ceval.c).
1510
+
1511
+ Limit to 32-bit signed C int (rather than INT_MAX) for portability.
1512
+
1513
+ The argument of a concrete bytecode instruction is limited to 8-bit.
1514
+ EXTENDED_ARG is used for 16, 24, and 32-bit arguments. */
1515
+
1516
+ int oparg_ = Py_SAFE_DOWNCAST (oparg , Py_ssize_t , int );
1517
+ return cfg_builder_addop (g , opcode , oparg_ , NULL , loc );
1509
1518
}
1510
1519
1511
1520
@@ -1559,12 +1568,12 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
1559
1568
}
1560
1569
1561
1570
#define ADDOP_I (C , OP , O ) { \
1562
- if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1571
+ if (!cfg_builder_addop_i (CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1563
1572
return 0; \
1564
1573
}
1565
1574
1566
1575
#define ADDOP_I_NOLINE (C , OP , O ) { \
1567
- if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1576
+ if (!cfg_builder_addop_i (CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1568
1577
return 0; \
1569
1578
}
1570
1579
@@ -4227,7 +4236,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
4227
4236
if (op == LOAD_GLOBAL ) {
4228
4237
arg <<= 1 ;
4229
4238
}
4230
- return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), op , arg , COMPILER_LOC (c ));
4239
+ return cfg_builder_addop_i (CFG_BUILDER (c ), op , arg , COMPILER_LOC (c ));
4231
4240
}
4232
4241
4233
4242
static int
@@ -6704,7 +6713,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)
6704
6713
pc -> fail_pop = NULL ;
6705
6714
pc -> fail_pop_size = 0 ;
6706
6715
pc -> on_top = 0 ;
6707
- if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), COPY , 1 , COMPILER_LOC (c )) ||
6716
+ if (!cfg_builder_addop_i (CFG_BUILDER (c ), COPY , 1 , COMPILER_LOC (c )) ||
6708
6717
!compiler_pattern (c , alt , pc )) {
6709
6718
goto error ;
6710
6719
}
0 commit comments