19
19
import com .oracle .graal .python .builtins .objects .ellipsis .PEllipsis ;
20
20
import com .oracle .graal .python .builtins .objects .function .PArguments ;
21
21
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
22
+ import com .oracle .graal .python .builtins .objects .type .TypeFlags ;
22
23
import com .oracle .graal .python .compiler .CompilationScope ;
23
24
import com .oracle .graal .python .compiler .Compiler ;
24
25
import com .oracle .graal .python .compiler .Compiler .ConstantCollection ;
@@ -845,7 +846,11 @@ private BytecodeDSLCompilerResult buildComprehensionCodeUnit(SSTNode node, Compr
845
846
@ Override
846
847
public BytecodeDSLCompilerResult visit (ExprTy .ListComp node ) {
847
848
return buildComprehensionCodeUnit (node , node .generators , "<listcomp>" ,
848
- (statementCompiler ) -> statementCompiler .b .emitMakeEmptyList (),
849
+ (statementCompiler ) -> {
850
+ statementCompiler .b .beginMakeList ();
851
+ statementCompiler .b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
852
+ statementCompiler .b .endMakeList ();
853
+ },
849
854
(statementCompiler , collection ) -> {
850
855
statementCompiler .b .beginListAppend ();
851
856
statementCompiler .b .emitLoadLocal (collection );
@@ -857,7 +862,10 @@ public BytecodeDSLCompilerResult visit(ExprTy.ListComp node) {
857
862
@ Override
858
863
public BytecodeDSLCompilerResult visit (ExprTy .DictComp node ) {
859
864
return buildComprehensionCodeUnit (node , node .generators , "<dictcomp>" ,
860
- (statementCompiler ) -> statementCompiler .b .emitMakeEmptyDict (),
865
+ (statementCompiler ) -> {
866
+ statementCompiler .b .beginMakeDict (0 );
867
+ statementCompiler .b .endMakeDict ();
868
+ },
861
869
(statementCompiler , collection ) -> {
862
870
statementCompiler .b .beginSetDictItem ();
863
871
statementCompiler .b .emitLoadLocal (collection );
@@ -870,7 +878,11 @@ public BytecodeDSLCompilerResult visit(ExprTy.DictComp node) {
870
878
@ Override
871
879
public BytecodeDSLCompilerResult visit (ExprTy .SetComp node ) {
872
880
return buildComprehensionCodeUnit (node , node .generators , "<setcomp>" ,
873
- (statementCompiler ) -> statementCompiler .b .emitMakeEmptySet (),
881
+ (statementCompiler ) -> {
882
+ statementCompiler .b .beginMakeSet ();
883
+ statementCompiler .b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
884
+ statementCompiler .b .endMakeSet ();
885
+ },
874
886
(statementCompiler , collection ) -> {
875
887
statementCompiler .b .beginSetAdd ();
876
888
statementCompiler .b .emitLoadLocal (collection );
@@ -968,21 +980,14 @@ private void emitNameFastOperation(String mangled, NameOperation op, Builder b)
968
980
BytecodeLocal local = locals .get (mangled );
969
981
switch (op ) {
970
982
case Read :
971
- b .beginCheckUnboundLocal (varnames .get (mangled ));
972
- b .emitLoadLocal (local );
973
- b .endCheckUnboundLocal ();
974
- break ;
975
- case Delete :
976
983
b .beginBlock ();
977
- b .beginCheckUnboundLocal ( varnames .get (mangled ));
984
+ b .emitCheckUnboundLocal ( local , varnames .get (mangled ));
978
985
b .emitLoadLocal (local );
979
- b .endCheckUnboundLocal ();
980
-
981
- b .beginStoreLocal (local );
982
- b .emitLoadNull ();
983
- b .endStoreLocal ();
984
986
b .endBlock ();
985
987
break ;
988
+ case Delete :
989
+ b .emitDeleteLocal (local , varnames .get (mangled ));
990
+ break ;
986
991
case BeginWrite :
987
992
if (local == null ) {
988
993
throw new NullPointerException ("local " + mangled + " not defined" );
@@ -1142,7 +1147,7 @@ public void setUpFrame(ArgumentsTy args, Builder b) {
1142
1147
List <BytecodeLocal > toClear = new ArrayList <>();
1143
1148
1144
1149
b .beginStoreRange (cellVariableLocals );
1145
- b .beginMakeVariadic ();
1150
+ b .beginCollectToObjectArray ();
1146
1151
for (int i = 0 ; i < cellVariableLocals .length ; i ++) {
1147
1152
b .beginCreateCell ();
1148
1153
if (scope .getUseOfName (cellVariables [i ]).contains (DefUse .DefParam )) {
@@ -1159,7 +1164,7 @@ public void setUpFrame(ArgumentsTy args, Builder b) {
1159
1164
}
1160
1165
b .endCreateCell ();
1161
1166
}
1162
- b .endMakeVariadic ();
1167
+ b .endCollectToObjectArray ();
1163
1168
b .endStoreRange ();
1164
1169
1165
1170
for (BytecodeLocal local : toClear ) {
@@ -1722,11 +1727,11 @@ private void createConstant(ConstantValue value) {
1722
1727
break ;
1723
1728
case TUPLE :
1724
1729
b .beginMakeTuple ();
1725
- b .beginMakeVariadic ();
1730
+ b .beginCollectToObjectArray ();
1726
1731
for (ConstantValue cv : value .getTupleElements ()) {
1727
1732
createConstant (cv );
1728
1733
}
1729
- b .endMakeVariadic ();
1734
+ b .endCollectToObjectArray ();
1730
1735
b .endMakeTuple ();
1731
1736
break ;
1732
1737
case FROZENSET :
@@ -1767,7 +1772,8 @@ public Void visit(ExprTy.Dict node) {
1767
1772
boolean newStatement = beginSourceSection (node , b );
1768
1773
1769
1774
if (len (node .keys ) == 0 ) {
1770
- b .emitMakeEmptyDict ();
1775
+ b .beginMakeDict (0 );
1776
+ b .endMakeDict ();
1771
1777
} else {
1772
1778
b .beginMakeDict (node .keys .length );
1773
1779
for (int i = 0 ; i < node .keys .length ; i ++) {
@@ -2027,11 +2033,11 @@ private void emitUnstar(Runnable initialElementsProducer, ExprTy[] args) {
2027
2033
*
2028
2034
* @formatter:off
2029
2035
* Unstar(
2030
- * MakeVariadic (a, b),
2036
+ * CollectToObjectArray (a, b),
2031
2037
* UnpackStarred(c),
2032
- * MakeVariadic (d, e),
2038
+ * CollectToObjectArray (d, e),
2033
2039
* UnpackStarred(f),
2034
- * MakeVariadic (g)
2040
+ * CollectToObjectArray (g)
2035
2041
* )
2036
2042
* @formatter:on
2037
2043
*/
@@ -2040,15 +2046,15 @@ private void emitUnstar(Runnable initialElementsProducer, ExprTy[] args) {
2040
2046
int numOperands = 0 ;
2041
2047
2042
2048
if (initialElementsProducer != null ) {
2043
- b .beginMakeVariadic ();
2049
+ b .beginCollectToObjectArray ();
2044
2050
initialElementsProducer .run ();
2045
2051
inVariadic = true ;
2046
2052
}
2047
2053
2048
2054
for (int i = 0 ; i < args .length ; i ++) {
2049
2055
if (args [i ] instanceof ExprTy .Starred ) {
2050
2056
if (inVariadic ) {
2051
- b .endMakeVariadic ();
2057
+ b .endCollectToObjectArray ();
2052
2058
inVariadic = false ;
2053
2059
numOperands ++;
2054
2060
}
@@ -2059,7 +2065,7 @@ private void emitUnstar(Runnable initialElementsProducer, ExprTy[] args) {
2059
2065
numOperands ++;
2060
2066
} else {
2061
2067
if (!inVariadic ) {
2062
- b .beginMakeVariadic ();
2068
+ b .beginCollectToObjectArray ();
2063
2069
inVariadic = true ;
2064
2070
}
2065
2071
@@ -2068,33 +2074,31 @@ private void emitUnstar(Runnable initialElementsProducer, ExprTy[] args) {
2068
2074
}
2069
2075
2070
2076
if (inVariadic ) {
2071
- b .endMakeVariadic ();
2077
+ b .endCollectToObjectArray ();
2072
2078
numOperands ++;
2073
2079
}
2074
2080
2075
2081
b .endUnstar (numOperands );
2076
2082
} else {
2077
- b .beginMakeVariadic ();
2083
+ b .beginCollectToObjectArray ();
2078
2084
if (initialElementsProducer != null ) {
2079
2085
initialElementsProducer .run ();
2080
2086
}
2081
2087
visitSequence (args );
2082
- b .endMakeVariadic ();
2088
+ b .endCollectToObjectArray ();
2083
2089
}
2084
2090
}
2085
2091
2086
2092
@ Override
2087
2093
public Void visit (ExprTy .Set node ) {
2088
2094
boolean newStatement = beginSourceSection (node , b );
2089
-
2095
+ b . beginMakeSet ();
2090
2096
if (len (node .elements ) == 0 ) {
2091
- b .emitMakeEmptySet ( );
2097
+ b .emitLoadConstant ( PythonUtils . EMPTY_OBJECT_ARRAY );
2092
2098
} else {
2093
- b .beginMakeSet ();
2094
2099
emitUnstar (node .elements );
2095
- b .endMakeSet ();
2096
2100
}
2097
-
2101
+ b . endMakeSet ();
2098
2102
endSourceSection (b , newStatement );
2099
2103
return null ;
2100
2104
}
@@ -2943,7 +2947,8 @@ private void emitKeywordGroup(KeywordGroup group, boolean copy, BytecodeLocal fu
2943
2947
2944
2948
if (copy ) {
2945
2949
b .beginKwargsMerge (function );
2946
- b .emitMakeEmptyDict ();
2950
+ b .beginMakeDict (0 );
2951
+ b .endMakeDict ();
2947
2952
splatKeywords .expr .accept (this );
2948
2953
b .endKwargsMerge ();
2949
2954
} else {
@@ -3229,11 +3234,11 @@ private void emitMakeFunction(SSTNode node, String name, ArgumentsTy args, List<
3229
3234
if (args == null || len (args .defaults ) == 0 ) {
3230
3235
b .emitLoadConstant (PythonUtils .EMPTY_OBJECT_ARRAY );
3231
3236
} else {
3232
- b .beginMakeVariadic ();
3237
+ b .beginCollectToObjectArray ();
3233
3238
for (int i = 0 ; i < args .defaults .length ; i ++) {
3234
3239
args .defaults [i ].accept (this );
3235
3240
}
3236
- b .endMakeVariadic ();
3241
+ b .endCollectToObjectArray ();
3237
3242
}
3238
3243
3239
3244
boolean hasKeywords = false ;
@@ -3822,9 +3827,9 @@ private void doVisitPattern(PatternTy.MatchSequence node, PatternContext pc) {
3822
3827
3823
3828
b .beginPrimitiveBoolAnd ();
3824
3829
3825
- b .beginIsSequence ( );
3830
+ b .beginCheckTypeFlags ( TypeFlags . SEQUENCE );
3826
3831
b .emitLoadLocal (pc .subject );
3827
- b .endIsSequence ();
3832
+ b .endCheckTypeFlags ();
3828
3833
3829
3834
if (star < 0 ) {
3830
3835
// No star: len(subject) == size
0 commit comments