@@ -228,7 +228,7 @@ static int compiler_slice(struct compiler *, expr_ty);
228
228
229
229
static int inplace_binop (operator_ty );
230
230
static int are_all_items_const (asdl_expr_seq * , Py_ssize_t , Py_ssize_t );
231
- static int expr_constant ( expr_ty );
231
+
232
232
233
233
static int compiler_with (struct compiler * , stmt_ty , int );
234
234
static int compiler_async_with (struct compiler * , stmt_ty , int );
@@ -1572,17 +1572,6 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b)
1572
1572
} \
1573
1573
}
1574
1574
1575
- /* These macros allows to check only for errors and not emmit bytecode
1576
- * while visiting nodes.
1577
- */
1578
-
1579
- #define BEGIN_DO_NOT_EMIT_BYTECODE { \
1580
- c->c_do_not_emit_bytecode++;
1581
-
1582
- #define END_DO_NOT_EMIT_BYTECODE \
1583
- c->c_do_not_emit_bytecode--; \
1584
- }
1585
-
1586
1575
/* Search if variable annotations are present statically in a block. */
1587
1576
1588
1577
static int
@@ -2704,48 +2693,28 @@ static int
2704
2693
compiler_if (struct compiler * c , stmt_ty s )
2705
2694
{
2706
2695
basicblock * end , * next ;
2707
- int constant ;
2708
2696
assert (s -> kind == If_kind );
2709
2697
end = compiler_new_block (c );
2710
- if (end == NULL )
2698
+ if (end == NULL ) {
2711
2699
return 0 ;
2712
-
2713
- constant = expr_constant (s -> v .If .test );
2714
- /* constant = 0: "if 0"
2715
- * constant = 1: "if 1", "if 2", ...
2716
- * constant = -1: rest */
2717
- if (constant == 0 ) {
2718
- BEGIN_DO_NOT_EMIT_BYTECODE
2719
- VISIT_SEQ (c , stmt , s -> v .If .body );
2720
- END_DO_NOT_EMIT_BYTECODE
2721
- if (s -> v .If .orelse ) {
2722
- VISIT_SEQ (c , stmt , s -> v .If .orelse );
2723
- }
2724
- } else if (constant == 1 ) {
2725
- VISIT_SEQ (c , stmt , s -> v .If .body );
2726
- if (s -> v .If .orelse ) {
2727
- BEGIN_DO_NOT_EMIT_BYTECODE
2728
- VISIT_SEQ (c , stmt , s -> v .If .orelse );
2729
- END_DO_NOT_EMIT_BYTECODE
2730
- }
2731
- } else {
2732
- if (asdl_seq_LEN (s -> v .If .orelse )) {
2733
- next = compiler_new_block (c );
2734
- if (next == NULL )
2735
- return 0 ;
2736
- }
2737
- else {
2738
- next = end ;
2739
- }
2740
- if (!compiler_jump_if (c , s -> v .If .test , next , 0 )) {
2700
+ }
2701
+ if (asdl_seq_LEN (s -> v .If .orelse )) {
2702
+ next = compiler_new_block (c );
2703
+ if (next == NULL ) {
2741
2704
return 0 ;
2742
2705
}
2743
- VISIT_SEQ (c , stmt , s -> v .If .body );
2744
- if (asdl_seq_LEN (s -> v .If .orelse )) {
2745
- ADDOP_JUMP (c , JUMP_FORWARD , end );
2746
- compiler_use_next_block (c , next );
2747
- VISIT_SEQ (c , stmt , s -> v .If .orelse );
2748
- }
2706
+ }
2707
+ else {
2708
+ next = end ;
2709
+ }
2710
+ if (!compiler_jump_if (c , s -> v .If .test , next , 0 )) {
2711
+ return 0 ;
2712
+ }
2713
+ VISIT_SEQ (c , stmt , s -> v .If .body );
2714
+ if (asdl_seq_LEN (s -> v .If .orelse )) {
2715
+ ADDOP_JUMP (c , JUMP_FORWARD , end );
2716
+ compiler_use_next_block (c , next );
2717
+ VISIT_SEQ (c , stmt , s -> v .If .orelse );
2749
2718
}
2750
2719
compiler_use_next_block (c , end );
2751
2720
return 1 ;
@@ -2842,25 +2811,6 @@ static int
2842
2811
compiler_while (struct compiler * c , stmt_ty s )
2843
2812
{
2844
2813
basicblock * loop , * body , * end , * anchor = NULL ;
2845
- int constant = expr_constant (s -> v .While .test );
2846
-
2847
- if (constant == 0 ) {
2848
- BEGIN_DO_NOT_EMIT_BYTECODE
2849
- // Push a dummy block so the VISIT_SEQ knows that we are
2850
- // inside a while loop so it can correctly evaluate syntax
2851
- // errors.
2852
- if (!compiler_push_fblock (c , WHILE_LOOP , NULL , NULL , NULL )) {
2853
- return 0 ;
2854
- }
2855
- VISIT_SEQ (c , stmt , s -> v .While .body );
2856
- // Remove the dummy block now that is not needed.
2857
- compiler_pop_fblock (c , WHILE_LOOP , NULL );
2858
- END_DO_NOT_EMIT_BYTECODE
2859
- if (s -> v .While .orelse ) {
2860
- VISIT_SEQ (c , stmt , s -> v .While .orelse );
2861
- }
2862
- return 1 ;
2863
- }
2864
2814
loop = compiler_new_block (c );
2865
2815
body = compiler_new_block (c );
2866
2816
anchor = compiler_new_block (c );
@@ -2872,15 +2822,16 @@ compiler_while(struct compiler *c, stmt_ty s)
2872
2822
if (!compiler_push_fblock (c , WHILE_LOOP , loop , end , NULL )) {
2873
2823
return 0 ;
2874
2824
}
2875
- if (constant == -1 ) {
2876
- if (!compiler_jump_if (c , s -> v .While .test , anchor , 0 )) {
2877
- return 0 ;
2878
- }
2825
+ if (!compiler_jump_if (c , s -> v .While .test , anchor , 0 )) {
2826
+ return 0 ;
2879
2827
}
2880
2828
2881
2829
compiler_use_next_block (c , body );
2882
2830
VISIT_SEQ (c , stmt , s -> v .While .body );
2883
- ADDOP_JUMP (c , JUMP_ABSOLUTE , loop );
2831
+ SET_LOC (c , s );
2832
+ if (!compiler_jump_if (c , s -> v .While .test , body , 1 )) {
2833
+ return 0 ;
2834
+ }
2884
2835
2885
2836
compiler_pop_fblock (c , WHILE_LOOP , loop );
2886
2837
@@ -4791,15 +4742,6 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
4791
4742
Return values: 1 for true, 0 for false, -1 for non-constant.
4792
4743
*/
4793
4744
4794
- static int
4795
- expr_constant (expr_ty e )
4796
- {
4797
- if (e -> kind == Constant_kind ) {
4798
- return PyObject_IsTrue (e -> v .Constant .value );
4799
- }
4800
- return -1 ;
4801
- }
4802
-
4803
4745
static int
4804
4746
compiler_with_except_finish (struct compiler * c ) {
4805
4747
basicblock * exit ;
@@ -6304,7 +6246,7 @@ optimize_basic_block(basicblock *bb, PyObject *consts)
6304
6246
case JUMP_FORWARD :
6305
6247
if (inst -> i_target != target -> i_target ) {
6306
6248
inst -> i_target = target -> i_target ;
6307
- -- i ;
6249
+ // --i;
6308
6250
}
6309
6251
break ;
6310
6252
case JUMP_ABSOLUTE :
@@ -6317,8 +6259,8 @@ optimize_basic_block(basicblock *bb, PyObject *consts)
6317
6259
}
6318
6260
if (inst -> i_target -> b_exit && inst -> i_target -> b_iused <= MAX_COPY_SIZE ) {
6319
6261
basicblock * to_copy = inst -> i_target ;
6320
- * inst = to_copy -> b_instr [ 0 ] ;
6321
- for (i = 1 ; i < to_copy -> b_iused ; i ++ ) {
6262
+ inst -> i_opcode = NOP ;
6263
+ for (i = 0 ; i < to_copy -> b_iused ; i ++ ) {
6322
6264
int index = compiler_next_instr (bb );
6323
6265
if (index < 0 ) {
6324
6266
return -1 ;
0 commit comments