@@ -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 );
@@ -2704,48 +2704,28 @@ static int
2704
2704
compiler_if (struct compiler * c , stmt_ty s )
2705
2705
{
2706
2706
basicblock * end , * next ;
2707
- int constant ;
2708
2707
assert (s -> kind == If_kind );
2709
2708
end = compiler_new_block (c );
2710
- if (end == NULL )
2709
+ if (end == NULL ) {
2711
2710
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 )) {
2711
+ }
2712
+ if (asdl_seq_LEN (s -> v .If .orelse )) {
2713
+ next = compiler_new_block (c );
2714
+ if (next == NULL ) {
2741
2715
return 0 ;
2742
2716
}
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
- }
2717
+ }
2718
+ else {
2719
+ next = end ;
2720
+ }
2721
+ if (!compiler_jump_if (c , s -> v .If .test , next , 0 )) {
2722
+ return 0 ;
2723
+ }
2724
+ VISIT_SEQ (c , stmt , s -> v .If .body );
2725
+ if (asdl_seq_LEN (s -> v .If .orelse )) {
2726
+ ADDOP_JUMP (c , JUMP_FORWARD , end );
2727
+ compiler_use_next_block (c , next );
2728
+ VISIT_SEQ (c , stmt , s -> v .If .orelse );
2749
2729
}
2750
2730
compiler_use_next_block (c , end );
2751
2731
return 1 ;
@@ -2842,25 +2822,6 @@ static int
2842
2822
compiler_while (struct compiler * c , stmt_ty s )
2843
2823
{
2844
2824
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
2825
loop = compiler_new_block (c );
2865
2826
body = compiler_new_block (c );
2866
2827
anchor = compiler_new_block (c );
@@ -2872,15 +2833,16 @@ compiler_while(struct compiler *c, stmt_ty s)
2872
2833
if (!compiler_push_fblock (c , WHILE_LOOP , loop , end , NULL )) {
2873
2834
return 0 ;
2874
2835
}
2875
- if (constant == -1 ) {
2876
- if (!compiler_jump_if (c , s -> v .While .test , anchor , 0 )) {
2877
- return 0 ;
2878
- }
2836
+ if (!compiler_jump_if (c , s -> v .While .test , anchor , 0 )) {
2837
+ return 0 ;
2879
2838
}
2880
2839
2881
2840
compiler_use_next_block (c , body );
2882
2841
VISIT_SEQ (c , stmt , s -> v .While .body );
2883
- ADDOP_JUMP (c , JUMP_ABSOLUTE , loop );
2842
+ SET_LOC (c , s );
2843
+ if (!compiler_jump_if (c , s -> v .While .test , body , 1 )) {
2844
+ return 0 ;
2845
+ }
2884
2846
2885
2847
compiler_pop_fblock (c , WHILE_LOOP , loop );
2886
2848
@@ -4791,15 +4753,6 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
4791
4753
Return values: 1 for true, 0 for false, -1 for non-constant.
4792
4754
*/
4793
4755
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
4756
static int
4804
4757
compiler_with_except_finish (struct compiler * c ) {
4805
4758
basicblock * exit ;
@@ -6317,8 +6270,8 @@ optimize_basic_block(basicblock *bb, PyObject *consts)
6317
6270
}
6318
6271
if (inst -> i_target -> b_exit && inst -> i_target -> b_iused <= MAX_COPY_SIZE ) {
6319
6272
basicblock * to_copy = inst -> i_target ;
6320
- * inst = to_copy -> b_instr [ 0 ] ;
6321
- for (i = 1 ; i < to_copy -> b_iused ; i ++ ) {
6273
+ inst -> i_opcode = NOP ;
6274
+ for (i = 0 ; i < to_copy -> b_iused ; i ++ ) {
6322
6275
int index = compiler_next_instr (bb );
6323
6276
if (index < 0 ) {
6324
6277
return -1 ;
0 commit comments