42
42
import com .oracle .graal .python .builtins .objects .itertools .PChain ;
43
43
import com .oracle .graal .python .builtins .objects .itertools .PRepeat ;
44
44
import com .oracle .graal .python .builtins .objects .itertools .PTeeDataObject ;
45
- import com .oracle .graal .python .builtins .objects .itertools .TeeBuiltins .NewNode ;
46
- import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
45
+ import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
47
46
import com .oracle .graal .python .lib .PyCallableCheckNode ;
48
47
import com .oracle .graal .python .lib .PyObjectLookupAttr ;
49
48
import com .oracle .graal .python .nodes .ErrorMessages ;
60
59
import com .oracle .truffle .api .dsl .NodeFactory ;
61
60
import com .oracle .truffle .api .dsl .Specialization ;
62
61
import com .oracle .truffle .api .frame .VirtualFrame ;
63
- import com .oracle .truffle .api .library .CachedLibrary ;
64
62
import com .oracle .truffle .api .profiles .BranchProfile ;
65
63
66
64
@ CoreFunctions (defineModule = "itertools" )
@@ -97,14 +95,15 @@ protected Object tee(VirtualFrame frame, Object iterable, int n,
97
95
@ Cached IterNode iterNode ,
98
96
@ Cached PyObjectLookupAttr getAttrNode ,
99
97
@ Cached PyCallableCheckNode callableCheckNode ,
100
- @ Cached NewNode newNode ,
101
98
@ Cached CallVarargsMethodNode callNode ,
102
99
@ Cached BranchProfile notCallableProfile ) {
103
100
Object it = iterNode .execute (frame , iterable , PNone .NO_VALUE );
104
101
Object copyCallable = getAttrNode .execute (frame , it , __COPY__ );
105
102
if (!callableCheckNode .execute (copyCallable )) {
106
103
notCallableProfile .enter ();
107
- it = newNode .execute (frame , PythonBuiltinClassType .PTee , it );
104
+ // as in Tee.__NEW__()
105
+ PTeeDataObject dataObj = factory ().createTeeDataObject (it );
106
+ it = factory ().createTee (dataObj , 0 );
108
107
}
109
108
110
109
// return tuple([it] + [it.__copy__() for i in range(1, n)])
@@ -124,14 +123,16 @@ protected Object tee(VirtualFrame frame, Object iterable, int n,
124
123
@ GenerateNodeFactory
125
124
public abstract static class TeeDataObjectNode extends PythonVarargsBuiltinNode {
126
125
@ SuppressWarnings ("unused" )
127
- @ Specialization (guards = "lib.isLazyPythonClass(cls)" )
128
- protected PTeeDataObject construct (Object cls , Object [] arguments , PKeyword [] keywords , @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
126
+ @ Specialization (guards = "isTypeNode.execute(cls)" , limit = "1" )
127
+ protected PTeeDataObject construct (Object cls , Object [] arguments , PKeyword [] keywords ,
128
+ @ SuppressWarnings ("unused" ) @ Cached TypeNodes .IsTypeNode isTypeNode ) {
129
129
return factory ().createTeeDataObject ();
130
130
}
131
131
132
132
@ Fallback
133
133
@ SuppressWarnings ("unused" )
134
- protected Object construct (Object cls , Object [] arguments , PKeyword [] keywords ) {
134
+ protected Object notype (Object cls , Object [] arguments , PKeyword [] keywords ,
135
+ @ SuppressWarnings ("unused" ) @ Cached TypeNodes .IsTypeNode isTypeNode ) {
135
136
throw raise (TypeError , ErrorMessages .IS_NOT_TYPE_OBJ , "'cls'" , cls );
136
137
}
137
138
}
@@ -141,14 +142,15 @@ protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords)
141
142
@ GenerateNodeFactory
142
143
public abstract static class RepeatNode extends PythonVarargsBuiltinNode {
143
144
@ SuppressWarnings ("unused" )
144
- @ Specialization (guards = "lib.isLazyPythonClass(cls)" )
145
- protected PRepeat construct (Object cls , Object [] arguments , PKeyword [] keywords , @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
145
+ @ Specialization (guards = "isTypeNode.execute(cls)" , limit = "1" )
146
+ protected PRepeat construct (Object cls , Object [] arguments , PKeyword [] keywords ,
147
+ @ SuppressWarnings ("unused" ) @ Cached TypeNodes .IsTypeNode isTypeNode ) {
146
148
return factory ().createRepeat ();
147
149
}
148
150
149
151
@ Fallback
150
152
@ SuppressWarnings ("unused" )
151
- protected Object construct (Object cls , Object [] arguments , PKeyword [] keywords ) {
153
+ protected Object notype (Object cls , Object [] arguments , PKeyword [] keywords ) {
152
154
throw raise (TypeError , ErrorMessages .IS_NOT_TYPE_OBJ , "'cls'" , cls );
153
155
}
154
156
}
@@ -158,14 +160,15 @@ protected Object construct(Object cls, Object[] arguments, PKeyword[] keywords)
158
160
@ GenerateNodeFactory
159
161
public abstract static class ChainNode extends PythonVarargsBuiltinNode {
160
162
@ SuppressWarnings ("unused" )
161
- @ Specialization (guards = "lib.isLazyPythonClass(cls)" )
162
- protected PChain construct (Object cls , Object [] arguments , PKeyword [] keywords , @ CachedLibrary (limit = "3" ) PythonObjectLibrary lib ) {
163
+ @ Specialization (guards = "isTypeNode.execute(cls)" , limit = "1" )
164
+ protected PChain construct (Object cls , Object [] arguments , PKeyword [] keywords ,
165
+ @ SuppressWarnings ("unused" ) @ Cached TypeNodes .IsTypeNode isTypeNode ) {
163
166
return factory ().createChain ();
164
167
}
165
168
166
169
@ Fallback
167
170
@ SuppressWarnings ("unused" )
168
- protected Object construct (Object cls , Object [] arguments , PKeyword [] keywords ) {
171
+ protected Object notype (Object cls , Object [] arguments , PKeyword [] keywords ) {
169
172
throw raise (TypeError , ErrorMessages .IS_NOT_TYPE_OBJ , "'cls'" , cls );
170
173
}
171
174
}
0 commit comments