68
68
#define JUMPBY (offset ) ((void)0)
69
69
#define GO_TO_INSTRUCTION (instname ) ((void)0)
70
70
#define DISPATCH_SAME_OPARG () ((void)0)
71
- #define DISPATCH () ((void)0)
72
71
73
72
#define inst (name , ...) case name:
74
73
#define super (name ) static int SUPER_##name
@@ -102,10 +101,6 @@ dummy_func(
102
101
103
102
switch (opcode ) {
104
103
105
- /* BEWARE!
106
- It is essential that any operation that fails must goto error
107
- and that all operation that succeed call DISPATCH() ! */
108
-
109
104
// BEGIN BYTECODES //
110
105
inst (NOP , (-- )) {
111
106
}
@@ -150,16 +145,14 @@ dummy_func(
150
145
super (LOAD_FAST__LOAD_CONST ) = LOAD_FAST + LOAD_CONST ;
151
146
super (STORE_FAST__LOAD_FAST ) = STORE_FAST + LOAD_FAST ;
152
147
super (STORE_FAST__STORE_FAST ) = STORE_FAST + STORE_FAST ;
153
- super (LOAD_CONST__LOAD_FAST ) = LOAD_CONST + LOAD_FAST ;
148
+ super (LOAD_CONST__LOAD_FAST ) = LOAD_CONST + LOAD_FAST ;
154
149
155
150
inst (POP_TOP , (value -- )) {
156
151
Py_DECREF (value );
157
152
}
158
153
159
- // stack effect: ( -- __0)
160
- inst (PUSH_NULL ) {
161
- /* Use BASIC_PUSH as NULL is not a valid object pointer */
162
- BASIC_PUSH (NULL );
154
+ inst (PUSH_NULL , (-- res )) {
155
+ res = NULL ;
163
156
}
164
157
165
158
inst (END_FOR , (value1 , value2 -- )) {
@@ -807,11 +800,12 @@ dummy_func(
807
800
Py_DECREF (receiver );
808
801
SET_TOP (retval );
809
802
JUMPBY (oparg );
810
- DISPATCH ();
811
803
}
812
- assert (gen_status == PYGEN_NEXT );
813
- assert (retval != NULL );
814
- PUSH (retval );
804
+ else {
805
+ assert (gen_status == PYGEN_NEXT );
806
+ assert (retval != NULL );
807
+ PUSH (retval );
808
+ }
815
809
}
816
810
817
811
// stack effect: ( -- )
@@ -904,7 +898,6 @@ dummy_func(
904
898
if (PyErr_GivenExceptionMatches (val , PyExc_StopAsyncIteration )) {
905
899
Py_DECREF (val );
906
900
Py_DECREF (POP ());
907
- DISPATCH ();
908
901
}
909
902
else {
910
903
PyObject * exc = Py_NewRef (PyExceptionInstance_Class (val ));
@@ -926,12 +919,13 @@ dummy_func(
926
919
Py_DECREF (POP ()); // The last sent value.
927
920
Py_DECREF (POP ()); // The delegated sub-iterator.
928
921
PUSH (value );
929
- DISPATCH ();
930
922
}
931
- PyObject * exc_type = Py_NewRef (Py_TYPE (exc_value ));
932
- PyObject * exc_traceback = PyException_GetTraceback (exc_value );
933
- _PyErr_Restore (tstate , exc_type , Py_NewRef (exc_value ), exc_traceback );
934
- goto exception_unwind ;
923
+ else {
924
+ PyObject * exc_type = Py_NewRef (Py_TYPE (exc_value ));
925
+ PyObject * exc_traceback = PyException_GetTraceback (exc_value );
926
+ _PyErr_Restore (tstate , exc_type , Py_NewRef (exc_value ), exc_traceback );
927
+ goto exception_unwind ;
928
+ }
935
929
}
936
930
937
931
inst (STOPITERATION_ERROR ) {
@@ -973,7 +967,6 @@ dummy_func(
973
967
PyException_SetContext (error , exc );
974
968
Py_DECREF (message );
975
969
}
976
- DISPATCH ();
977
970
}
978
971
979
972
@@ -1031,8 +1024,7 @@ dummy_func(
1031
1024
goto error ;
1032
1025
}
1033
1026
1034
- // stack effect: ( -- )
1035
- inst (DELETE_NAME ) {
1027
+ inst (DELETE_NAME , (-- )) {
1036
1028
PyObject * name = GETITEM (names , oparg );
1037
1029
PyObject * ns = LOCALS ();
1038
1030
int err ;
@@ -1042,6 +1034,7 @@ dummy_func(
1042
1034
goto error ;
1043
1035
}
1044
1036
err = PyObject_DelItem (ns , name );
1037
+ // Can't use ERROR_IF here.
1045
1038
if (err != 0 ) {
1046
1039
format_exc_check_arg (tstate , PyExc_NameError ,
1047
1040
NAME_ERROR_MSG ,
@@ -1181,11 +1174,11 @@ dummy_func(
1181
1174
goto error ;
1182
1175
}
1183
1176
1184
- // stack effect: ( -- )
1185
- inst (DELETE_GLOBAL ) {
1177
+ inst (DELETE_GLOBAL , (-- )) {
1186
1178
PyObject * name = GETITEM (names , oparg );
1187
1179
int err ;
1188
1180
err = PyDict_DelItem (GLOBALS (), name );
1181
+ // Can't use ERROR_IF here.
1189
1182
if (err != 0 ) {
1190
1183
if (_PyErr_ExceptionMatches (tstate , PyExc_KeyError )) {
1191
1184
format_exc_check_arg (tstate , PyExc_NameError ,
@@ -1365,18 +1358,13 @@ dummy_func(
1365
1358
SET_TOP (Py_NewRef (res ));
1366
1359
}
1367
1360
1368
- // stack effect: ( -- )
1369
- inst (DELETE_FAST ) {
1361
+ inst (DELETE_FAST , (-- )) {
1370
1362
PyObject * v = GETLOCAL (oparg );
1371
- if (v != NULL ) {
1372
- SETLOCAL (oparg , NULL );
1373
- DISPATCH ();
1374
- }
1375
- goto unbound_local_error ;
1363
+ ERROR_IF (v == NULL , unbound_local_error );
1364
+ SETLOCAL (oparg , NULL );
1376
1365
}
1377
1366
1378
- // stack effect: ( -- )
1379
- inst (MAKE_CELL ) {
1367
+ inst (MAKE_CELL , (-- )) {
1380
1368
// "initial" is probably NULL but not if it's an arg (or set
1381
1369
// via PyFrame_LocalsToFast() before MAKE_CELL has run).
1382
1370
PyObject * initial = GETLOCAL (oparg );
@@ -1387,17 +1375,17 @@ dummy_func(
1387
1375
SETLOCAL (oparg , cell );
1388
1376
}
1389
1377
1390
- // stack effect: ( -- )
1391
- inst (DELETE_DEREF ) {
1378
+ inst (DELETE_DEREF , (-- )) {
1392
1379
PyObject * cell = GETLOCAL (oparg );
1393
1380
PyObject * oldobj = PyCell_GET (cell );
1394
- if (oldobj != NULL ) {
1395
- PyCell_SET (cell , NULL );
1396
- Py_DECREF (oldobj );
1397
- DISPATCH ();
1381
+ // Can't use ERROR_IF here.
1382
+ // Fortunately we don't need its superpower.
1383
+ if (oldobj == NULL ) {
1384
+ format_exc_unbound (tstate , frame -> f_code , oparg );
1385
+ goto error ;
1398
1386
}
1399
- format_exc_unbound ( tstate , frame -> f_code , oparg );
1400
- goto error ;
1387
+ PyCell_SET ( cell , NULL );
1388
+ Py_DECREF ( oldobj ) ;
1401
1389
}
1402
1390
1403
1391
// stack effect: ( -- __0)
@@ -1760,15 +1748,15 @@ dummy_func(
1760
1748
Py_DECREF (owner );
1761
1749
PUSH (meth );
1762
1750
}
1763
- JUMPBY (INLINE_CACHE_ENTRIES_LOAD_ATTR );
1764
- DISPATCH ();
1765
1751
}
1766
- PyObject * res = PyObject_GetAttr (owner , name );
1767
- if (res == NULL ) {
1768
- goto error ;
1752
+ else {
1753
+ PyObject * res = PyObject_GetAttr (owner , name );
1754
+ if (res == NULL ) {
1755
+ goto error ;
1756
+ }
1757
+ Py_DECREF (owner );
1758
+ SET_TOP (res );
1769
1759
}
1770
- Py_DECREF (owner );
1771
- SET_TOP (res );
1772
1760
JUMPBY (INLINE_CACHE_ENTRIES_LOAD_ATTR );
1773
1761
}
1774
1762
@@ -2426,21 +2414,23 @@ dummy_func(
2426
2414
if (Py_IsTrue (cond )) {
2427
2415
STACK_SHRINK (1 );
2428
2416
_Py_DECREF_NO_DEALLOC (cond );
2429
- DISPATCH ();
2430
2417
}
2431
- if (Py_IsFalse (cond )) {
2418
+ else if (Py_IsFalse (cond )) {
2432
2419
JUMPBY (oparg );
2433
- DISPATCH ();
2434
2420
}
2435
- err = PyObject_IsTrue (cond );
2436
- if (err > 0 ) {
2437
- STACK_SHRINK (1 );
2438
- Py_DECREF (cond );
2421
+ else {
2422
+ err = PyObject_IsTrue (cond );
2423
+ if (err > 0 ) {
2424
+ STACK_SHRINK (1 );
2425
+ Py_DECREF (cond );
2426
+ }
2427
+ else if (err == 0 ) {
2428
+ JUMPBY (oparg );
2429
+ }
2430
+ else {
2431
+ goto error ;
2432
+ }
2439
2433
}
2440
- else if (err == 0 )
2441
- JUMPBY (oparg );
2442
- else
2443
- goto error ;
2444
2434
}
2445
2435
2446
2436
// error: JUMP_IF_TRUE_OR_POP stack effect depends on jump flag
@@ -2450,22 +2440,23 @@ dummy_func(
2450
2440
if (Py_IsFalse (cond )) {
2451
2441
STACK_SHRINK (1 );
2452
2442
_Py_DECREF_NO_DEALLOC (cond );
2453
- DISPATCH ();
2454
- }
2455
- if (Py_IsTrue (cond )) {
2456
- JUMPBY (oparg );
2457
- DISPATCH ();
2458
2443
}
2459
- err = PyObject_IsTrue (cond );
2460
- if (err > 0 ) {
2444
+ else if (Py_IsTrue (cond )) {
2461
2445
JUMPBY (oparg );
2462
2446
}
2463
- else if (err == 0 ) {
2464
- STACK_SHRINK (1 );
2465
- Py_DECREF (cond );
2447
+ else {
2448
+ err = PyObject_IsTrue (cond );
2449
+ if (err > 0 ) {
2450
+ JUMPBY (oparg );
2451
+ }
2452
+ else if (err == 0 ) {
2453
+ STACK_SHRINK (1 );
2454
+ Py_DECREF (cond );
2455
+ }
2456
+ else {
2457
+ goto error ;
2458
+ }
2466
2459
}
2467
- else
2468
- goto error ;
2469
2460
}
2470
2461
2471
2462
// stack effect: ( -- )
@@ -2606,23 +2597,24 @@ dummy_func(
2606
2597
if (next != NULL ) {
2607
2598
PUSH (next );
2608
2599
JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER );
2609
- DISPATCH ();
2610
2600
}
2611
- if (_PyErr_Occurred (tstate )) {
2612
- if (!_PyErr_ExceptionMatches (tstate , PyExc_StopIteration )) {
2613
- goto error ;
2614
- }
2615
- else if (tstate -> c_tracefunc != NULL ) {
2616
- call_exc_trace (tstate -> c_tracefunc , tstate -> c_traceobj , tstate , frame );
2601
+ else {
2602
+ if (_PyErr_Occurred (tstate )) {
2603
+ if (!_PyErr_ExceptionMatches (tstate , PyExc_StopIteration )) {
2604
+ goto error ;
2605
+ }
2606
+ else if (tstate -> c_tracefunc != NULL ) {
2607
+ call_exc_trace (tstate -> c_tracefunc , tstate -> c_traceobj , tstate , frame );
2608
+ }
2609
+ _PyErr_Clear (tstate );
2617
2610
}
2618
- _PyErr_Clear (tstate );
2611
+ /* iterator ended normally */
2612
+ assert (_Py_OPCODE (next_instr [INLINE_CACHE_ENTRIES_FOR_ITER + oparg ]) == END_FOR );
2613
+ STACK_SHRINK (1 );
2614
+ Py_DECREF (iter );
2615
+ /* Skip END_FOR */
2616
+ JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1 );
2619
2617
}
2620
- /* iterator ended normally */
2621
- assert (_Py_OPCODE (next_instr [INLINE_CACHE_ENTRIES_FOR_ITER + oparg ]) == END_FOR );
2622
- STACK_SHRINK (1 );
2623
- Py_DECREF (iter );
2624
- /* Skip END_FOR */
2625
- JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1 );
2626
2618
}
2627
2619
2628
2620
// stack effect: ( -- __0)
@@ -2637,14 +2629,15 @@ dummy_func(
2637
2629
PyObject * next = PyList_GET_ITEM (seq , it -> it_index ++ );
2638
2630
PUSH (Py_NewRef (next ));
2639
2631
JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER );
2640
- DISPATCH ();
2632
+ goto end_for_iter_list ; // End of this instruction
2641
2633
}
2642
2634
it -> it_seq = NULL ;
2643
2635
Py_DECREF (seq );
2644
2636
}
2645
2637
STACK_SHRINK (1 );
2646
2638
Py_DECREF (it );
2647
2639
JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1 );
2640
+ end_for_iter_list :
2648
2641
}
2649
2642
2650
2643
// stack effect: ( -- __0)
@@ -2659,15 +2652,16 @@ dummy_func(
2659
2652
STACK_SHRINK (1 );
2660
2653
Py_DECREF (r );
2661
2654
JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1 );
2662
- DISPATCH ();
2663
2655
}
2664
- long value = (long )(r -> start +
2665
- (unsigned long )(r -> index ++ ) * r -> step );
2666
- if (_PyLong_AssignValue (& GETLOCAL (_Py_OPARG (next )), value ) < 0 ) {
2667
- goto error ;
2656
+ else {
2657
+ long value = (long )(r -> start +
2658
+ (unsigned long )(r -> index ++ ) * r -> step );
2659
+ if (_PyLong_AssignValue (& GETLOCAL (_Py_OPARG (next )), value ) < 0 ) {
2660
+ goto error ;
2661
+ }
2662
+ // The STORE_FAST is already done.
2663
+ JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER + 1 );
2668
2664
}
2669
- // The STORE_FAST is already done.
2670
- JUMPBY (INLINE_CACHE_ENTRIES_FOR_ITER + 1 );
2671
2665
}
2672
2666
2673
2667
inst (FOR_ITER_GEN ) {
0 commit comments