@@ -134,7 +134,6 @@ struct location {
134
134
int end_col_offset ;
135
135
};
136
136
137
-
138
137
#define LOCATION (LNO , END_LNO , COL , END_COL ) \
139
138
((const struct location){(LNO), (END_LNO), (COL), (END_COL)})
140
139
@@ -433,8 +432,6 @@ typedef struct {
433
432
434
433
static int basicblock_next_instr (basicblock * );
435
434
436
- static int cfg_builder_addop_i (cfg_builder * g , int opcode , Py_ssize_t oparg , struct location loc );
437
-
438
435
static void compiler_free (struct compiler * );
439
436
static int compiler_error (struct compiler * , const char * , ...);
440
437
static int compiler_warn (struct compiler * , const char * , ...);
@@ -1299,7 +1296,19 @@ cfg_builder_addop(cfg_builder *g, int opcode, int oparg, basicblock *target,
1299
1296
1300
1297
/* Add an instruction with no arg. Returns 0 on failure, 1 on success. */
1301
1298
#define CFG_BUILDER_ADDOP_NOARG (G , OP , LOC ) \
1302
- cfg_builder_addop(G, OP, NO_OPARG, NO_TARGET, 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)
1303
1312
1304
1313
/* Add a jump instruction. Returns 0 on faiure, 1 on success. */
1305
1314
#define CFG_BUILDER_ADDOP_J (G , OP , T , LOC ) \
@@ -1462,7 +1471,7 @@ compiler_addop_load_const(struct compiler *c, PyObject *o)
1462
1471
Py_ssize_t arg = compiler_add_const (c , o );
1463
1472
if (arg < 0 )
1464
1473
return 0 ;
1465
- return cfg_builder_addop_i (CFG_BUILDER (c ), LOAD_CONST , arg , COMPILER_LOC (c ));
1474
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), LOAD_CONST , arg , COMPILER_LOC (c ));
1466
1475
}
1467
1476
1468
1477
static int
@@ -1472,7 +1481,7 @@ compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,
1472
1481
Py_ssize_t arg = dict_add_o (dict , o );
1473
1482
if (arg < 0 )
1474
1483
return 0 ;
1475
- return cfg_builder_addop_i (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1484
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1476
1485
}
1477
1486
1478
1487
static int
@@ -1496,25 +1505,7 @@ compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,
1496
1505
arg <<= 1 ;
1497
1506
arg |= 1 ;
1498
1507
}
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 );
1508
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), opcode , arg , COMPILER_LOC (c ));
1518
1509
}
1519
1510
1520
1511
@@ -1568,12 +1559,12 @@ cfg_builder_addop_i(cfg_builder *g, int opcode, Py_ssize_t oparg, struct locatio
1568
1559
}
1569
1560
1570
1561
#define ADDOP_I (C , OP , O ) { \
1571
- if (!cfg_builder_addop_i (CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1562
+ if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER(C), (OP), (O), COMPILER_LOC(C))) \
1572
1563
return 0; \
1573
1564
}
1574
1565
1575
1566
#define ADDOP_I_NOLINE (C , OP , O ) { \
1576
- if (!cfg_builder_addop_i (CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1567
+ if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER(C), (OP), (O), NO_LOCATION)) \
1577
1568
return 0; \
1578
1569
}
1579
1570
@@ -4236,7 +4227,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
4236
4227
if (op == LOAD_GLOBAL ) {
4237
4228
arg <<= 1 ;
4238
4229
}
4239
- return cfg_builder_addop_i (CFG_BUILDER (c ), op , arg , COMPILER_LOC (c ));
4230
+ return CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), op , arg , COMPILER_LOC (c ));
4240
4231
}
4241
4232
4242
4233
static int
@@ -6713,7 +6704,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)
6713
6704
pc -> fail_pop = NULL ;
6714
6705
pc -> fail_pop_size = 0 ;
6715
6706
pc -> on_top = 0 ;
6716
- if (!cfg_builder_addop_i (CFG_BUILDER (c ), COPY , 1 , COMPILER_LOC (c )) ||
6707
+ if (!CFG_BUILDER_ADDOP_I (CFG_BUILDER (c ), COPY , 1 , COMPILER_LOC (c )) ||
6717
6708
!compiler_pattern (c , alt , pc )) {
6718
6709
goto error ;
6719
6710
}
0 commit comments