@@ -630,140 +630,6 @@ compiler_unit_free(struct compiler_unit *u)
630
630
PyObject_Free (u );
631
631
}
632
632
633
- static int
634
- compiler_enter_scope (struct compiler * c , identifier name ,
635
- int scope_type , void * key , int lineno )
636
- {
637
- struct compiler_unit * u ;
638
- basicblock * block ;
639
-
640
- u = (struct compiler_unit * )PyObject_Calloc (1 , sizeof (
641
- struct compiler_unit ));
642
- if (!u ) {
643
- PyErr_NoMemory ();
644
- return 0 ;
645
- }
646
- u -> u_scope_type = scope_type ;
647
- u -> u_argcount = 0 ;
648
- u -> u_posonlyargcount = 0 ;
649
- u -> u_kwonlyargcount = 0 ;
650
- u -> u_ste = PySymtable_Lookup (c -> c_st , key );
651
- if (!u -> u_ste ) {
652
- compiler_unit_free (u );
653
- return 0 ;
654
- }
655
- Py_INCREF (name );
656
- u -> u_name = name ;
657
- u -> u_varnames = list2dict (u -> u_ste -> ste_varnames );
658
- u -> u_cellvars = dictbytype (u -> u_ste -> ste_symbols , CELL , 0 , 0 );
659
- if (!u -> u_varnames || !u -> u_cellvars ) {
660
- compiler_unit_free (u );
661
- return 0 ;
662
- }
663
- if (u -> u_ste -> ste_needs_class_closure ) {
664
- /* Cook up an implicit __class__ cell. */
665
- _Py_IDENTIFIER (__class__ );
666
- PyObject * name ;
667
- int res ;
668
- assert (u -> u_scope_type == COMPILER_SCOPE_CLASS );
669
- assert (PyDict_GET_SIZE (u -> u_cellvars ) == 0 );
670
- name = _PyUnicode_FromId (& PyId___class__ );
671
- if (!name ) {
672
- compiler_unit_free (u );
673
- return 0 ;
674
- }
675
- res = PyDict_SetItem (u -> u_cellvars , name , _PyLong_GetZero ());
676
- if (res < 0 ) {
677
- compiler_unit_free (u );
678
- return 0 ;
679
- }
680
- }
681
-
682
- u -> u_freevars = dictbytype (u -> u_ste -> ste_symbols , FREE , DEF_FREE_CLASS ,
683
- PyDict_GET_SIZE (u -> u_cellvars ));
684
- if (!u -> u_freevars ) {
685
- compiler_unit_free (u );
686
- return 0 ;
687
- }
688
-
689
- u -> u_blocks = NULL ;
690
- u -> u_nfblocks = 0 ;
691
- u -> u_firstlineno = lineno ;
692
- u -> u_lineno = lineno ;
693
- u -> u_col_offset = 0 ;
694
- u -> u_end_lineno = lineno ;
695
- u -> u_end_col_offset = 0 ;
696
- u -> u_consts = PyDict_New ();
697
- if (!u -> u_consts ) {
698
- compiler_unit_free (u );
699
- return 0 ;
700
- }
701
- u -> u_names = PyDict_New ();
702
- if (!u -> u_names ) {
703
- compiler_unit_free (u );
704
- return 0 ;
705
- }
706
-
707
- u -> u_private = NULL ;
708
-
709
- /* Push the old compiler_unit on the stack. */
710
- if (c -> u ) {
711
- PyObject * capsule = PyCapsule_New (c -> u , CAPSULE_NAME , NULL );
712
- if (!capsule || PyList_Append (c -> c_stack , capsule ) < 0 ) {
713
- Py_XDECREF (capsule );
714
- compiler_unit_free (u );
715
- return 0 ;
716
- }
717
- Py_DECREF (capsule );
718
- u -> u_private = c -> u -> u_private ;
719
- Py_XINCREF (u -> u_private );
720
- }
721
- c -> u = u ;
722
-
723
- c -> c_nestlevel ++ ;
724
-
725
- block = compiler_new_block (c );
726
- if (block == NULL )
727
- return 0 ;
728
- c -> u -> u_curblock = block ;
729
-
730
- if (u -> u_scope_type != COMPILER_SCOPE_MODULE ) {
731
- if (!compiler_set_qualname (c ))
732
- return 0 ;
733
- }
734
-
735
- return 1 ;
736
- }
737
-
738
- static void
739
- compiler_exit_scope (struct compiler * c )
740
- {
741
- // Don't call PySequence_DelItem() with an exception raised
742
- PyObject * exc_type , * exc_val , * exc_tb ;
743
- PyErr_Fetch (& exc_type , & exc_val , & exc_tb );
744
-
745
- c -> c_nestlevel -- ;
746
- compiler_unit_free (c -> u );
747
- /* Restore c->u to the parent unit. */
748
- Py_ssize_t n = PyList_GET_SIZE (c -> c_stack ) - 1 ;
749
- if (n >= 0 ) {
750
- PyObject * capsule = PyList_GET_ITEM (c -> c_stack , n );
751
- c -> u = (struct compiler_unit * )PyCapsule_GetPointer (capsule , CAPSULE_NAME );
752
- assert (c -> u );
753
- /* we are deleting from a list so this really shouldn't fail */
754
- if (PySequence_DelItem (c -> c_stack , n ) < 0 ) {
755
- _PyErr_WriteUnraisableMsg ("on removing the last compiler "
756
- "stack item" , NULL );
757
- }
758
- compiler_unit_check (c -> u );
759
- }
760
- else {
761
- c -> u = NULL ;
762
- }
763
-
764
- PyErr_Restore (exc_type , exc_val , exc_tb );
765
- }
766
-
767
633
static int
768
634
compiler_set_qualname (struct compiler * c )
769
635
{
@@ -1715,6 +1581,144 @@ compiler_addop_j_noline(struct compiler *c, int opcode, basicblock *b)
1715
1581
return 0; \
1716
1582
}
1717
1583
1584
+ static int
1585
+ compiler_enter_scope (struct compiler * c , identifier name ,
1586
+ int scope_type , void * key , int lineno )
1587
+ {
1588
+ struct compiler_unit * u ;
1589
+ basicblock * block ;
1590
+
1591
+ u = (struct compiler_unit * )PyObject_Calloc (1 , sizeof (
1592
+ struct compiler_unit ));
1593
+ if (!u ) {
1594
+ PyErr_NoMemory ();
1595
+ return 0 ;
1596
+ }
1597
+ u -> u_scope_type = scope_type ;
1598
+ u -> u_argcount = 0 ;
1599
+ u -> u_posonlyargcount = 0 ;
1600
+ u -> u_kwonlyargcount = 0 ;
1601
+ u -> u_ste = PySymtable_Lookup (c -> c_st , key );
1602
+ if (!u -> u_ste ) {
1603
+ compiler_unit_free (u );
1604
+ return 0 ;
1605
+ }
1606
+ Py_INCREF (name );
1607
+ u -> u_name = name ;
1608
+ u -> u_varnames = list2dict (u -> u_ste -> ste_varnames );
1609
+ u -> u_cellvars = dictbytype (u -> u_ste -> ste_symbols , CELL , 0 , 0 );
1610
+ if (!u -> u_varnames || !u -> u_cellvars ) {
1611
+ compiler_unit_free (u );
1612
+ return 0 ;
1613
+ }
1614
+ if (u -> u_ste -> ste_needs_class_closure ) {
1615
+ /* Cook up an implicit __class__ cell. */
1616
+ _Py_IDENTIFIER (__class__ );
1617
+ PyObject * name ;
1618
+ int res ;
1619
+ assert (u -> u_scope_type == COMPILER_SCOPE_CLASS );
1620
+ assert (PyDict_GET_SIZE (u -> u_cellvars ) == 0 );
1621
+ name = _PyUnicode_FromId (& PyId___class__ );
1622
+ if (!name ) {
1623
+ compiler_unit_free (u );
1624
+ return 0 ;
1625
+ }
1626
+ res = PyDict_SetItem (u -> u_cellvars , name , _PyLong_GetZero ());
1627
+ if (res < 0 ) {
1628
+ compiler_unit_free (u );
1629
+ return 0 ;
1630
+ }
1631
+ }
1632
+
1633
+ u -> u_freevars = dictbytype (u -> u_ste -> ste_symbols , FREE , DEF_FREE_CLASS ,
1634
+ PyDict_GET_SIZE (u -> u_cellvars ));
1635
+ if (!u -> u_freevars ) {
1636
+ compiler_unit_free (u );
1637
+ return 0 ;
1638
+ }
1639
+
1640
+ u -> u_blocks = NULL ;
1641
+ u -> u_nfblocks = 0 ;
1642
+ u -> u_firstlineno = lineno ;
1643
+ u -> u_lineno = lineno ;
1644
+ u -> u_col_offset = 0 ;
1645
+ u -> u_end_lineno = lineno ;
1646
+ u -> u_end_col_offset = 0 ;
1647
+ u -> u_consts = PyDict_New ();
1648
+ if (!u -> u_consts ) {
1649
+ compiler_unit_free (u );
1650
+ return 0 ;
1651
+ }
1652
+ u -> u_names = PyDict_New ();
1653
+ if (!u -> u_names ) {
1654
+ compiler_unit_free (u );
1655
+ return 0 ;
1656
+ }
1657
+
1658
+ u -> u_private = NULL ;
1659
+
1660
+ /* Push the old compiler_unit on the stack. */
1661
+ if (c -> u ) {
1662
+ PyObject * capsule = PyCapsule_New (c -> u , CAPSULE_NAME , NULL );
1663
+ if (!capsule || PyList_Append (c -> c_stack , capsule ) < 0 ) {
1664
+ Py_XDECREF (capsule );
1665
+ compiler_unit_free (u );
1666
+ return 0 ;
1667
+ }
1668
+ Py_DECREF (capsule );
1669
+ u -> u_private = c -> u -> u_private ;
1670
+ Py_XINCREF (u -> u_private );
1671
+ }
1672
+ c -> u = u ;
1673
+
1674
+ c -> c_nestlevel ++ ;
1675
+
1676
+ block = compiler_new_block (c );
1677
+ if (block == NULL )
1678
+ return 0 ;
1679
+ c -> u -> u_curblock = block ;
1680
+
1681
+ if (u -> u_scope_type == COMPILER_SCOPE_MODULE ) {
1682
+ c -> u -> u_lineno = -1 ;
1683
+ }
1684
+ else {
1685
+ if (!compiler_set_qualname (c ))
1686
+ return 0 ;
1687
+ }
1688
+ ADDOP_I (c , RESUME , 0 );
1689
+
1690
+ return 1 ;
1691
+ }
1692
+
1693
+ static void
1694
+ compiler_exit_scope (struct compiler * c )
1695
+ {
1696
+ // Don't call PySequence_DelItem() with an exception raised
1697
+ PyObject * exc_type , * exc_val , * exc_tb ;
1698
+ PyErr_Fetch (& exc_type , & exc_val , & exc_tb );
1699
+
1700
+ c -> c_nestlevel -- ;
1701
+ compiler_unit_free (c -> u );
1702
+ /* Restore c->u to the parent unit. */
1703
+ Py_ssize_t n = PyList_GET_SIZE (c -> c_stack ) - 1 ;
1704
+ if (n >= 0 ) {
1705
+ PyObject * capsule = PyList_GET_ITEM (c -> c_stack , n );
1706
+ c -> u = (struct compiler_unit * )PyCapsule_GetPointer (capsule , CAPSULE_NAME );
1707
+ assert (c -> u );
1708
+ /* we are deleting from a list so this really shouldn't fail */
1709
+ if (PySequence_DelItem (c -> c_stack , n ) < 0 ) {
1710
+ _PyErr_WriteUnraisableMsg ("on removing the last compiler "
1711
+ "stack item" , NULL );
1712
+ }
1713
+ compiler_unit_check (c -> u );
1714
+ }
1715
+ else {
1716
+ c -> u = NULL ;
1717
+ }
1718
+
1719
+ PyErr_Restore (exc_type , exc_val , exc_tb );
1720
+ }
1721
+
1718
1722
/* Search if variable annotations are present statically in a block. */
1719
1723
1720
1724
static int
@@ -2049,10 +2053,9 @@ compiler_mod(struct compiler *c, mod_ty mod)
2049
2053
if (module == NULL ) {
2050
2054
return 0 ;
2051
2055
}
2052
- if (!compiler_enter_scope (c , module , COMPILER_SCOPE_MODULE , mod , 1 ))
2056
+ if (!compiler_enter_scope (c , module , COMPILER_SCOPE_MODULE , mod , 1 )) {
2053
2057
return NULL ;
2054
- c -> u -> u_lineno = -1 ;
2055
- ADDOP_I (c , RESUME , 0 );
2058
+ }
2056
2059
c -> u -> u_lineno = 1 ;
2057
2060
switch (mod -> kind ) {
2058
2061
case Module_kind :
@@ -2508,7 +2511,6 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
2508
2511
if (!compiler_enter_scope (c , name , scope_type , (void * )s , firstlineno )) {
2509
2512
return 0 ;
2510
2513
}
2511
- ADDOP_I (c , RESUME , 0 );
2512
2514
2513
2515
/* if not -OO mode, add docstring */
2514
2516
if (c -> c_optimize < 2 ) {
@@ -2581,7 +2583,6 @@ compiler_class(struct compiler *c, stmt_ty s)
2581
2583
COMPILER_SCOPE_CLASS , (void * )s , firstlineno )) {
2582
2584
return 0 ;
2583
2585
}
2584
- ADDOP_I (c , RESUME , 0 );
2585
2586
/* this block represents what we do in the new scope */
2586
2587
{
2587
2588
/* use the class name for name mangling */
@@ -2914,13 +2915,11 @@ compiler_lambda(struct compiler *c, expr_ty e)
2914
2915
if (funcflags == -1 ) {
2915
2916
return 0 ;
2916
2917
}
2917
- ADDOP_I (c , RESUME , 0 );
2918
2918
2919
2919
if (!compiler_enter_scope (c , name , COMPILER_SCOPE_LAMBDA ,
2920
- (void * )e , e -> lineno ))
2920
+ (void * )e , e -> lineno )) {
2921
2921
return 0 ;
2922
-
2923
- ADDOP_I (c , RESUME , 0 );
2922
+ }
2924
2923
/* Make None the first constant, so the lambda can't have a
2925
2924
docstring. */
2926
6AF1
2925
if (compiler_add_const (c , Py_None ) < 0 )
@@ -5292,7 +5291,6 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
5292
5291
{
5293
5292
goto error ;
5294
5293
}
5295
- ADDOP_I (c , RESUME , 0 );
5296
5294
SET_LOC (c , e );
5297
5295
5298
5296
is_async_generator = c -> u -> u_ste -> ste_coroutine ;
0 commit comments