54
54
import com .oracle .graal .python .builtins .Builtin ;
55
55
import com .oracle .graal .python .builtins .CoreFunctions ;
56
56
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
57
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
58
57
import com .oracle .graal .python .builtins .PythonBuiltins ;
59
58
import com .oracle .graal .python .builtins .objects .PNone ;
60
59
import com .oracle .graal .python .builtins .objects .cext .PythonAbstractNativeObject ;
61
60
import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes ;
62
- import com .oracle .graal .python .builtins .objects .common .HashingCollectionNodes .GetDictStorageNode ;
63
61
import com .oracle .graal .python .builtins .objects .common .HashingStorage ;
64
62
import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary ;
65
- import com .oracle .graal .python .builtins .objects .common .HashingStorageLibrary .HashingStorageIterator ;
66
63
import com .oracle .graal .python .builtins .objects .common .PHashingCollection ;
67
64
import com .oracle .graal .python .builtins .objects .dict .PDict ;
68
65
import com .oracle .graal .python .builtins .objects .object .ObjectBuiltins ;
69
66
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
70
67
import com .oracle .graal .python .nodes .ErrorMessages ;
71
- import com .oracle .graal .python .nodes .PRaiseNode ;
72
68
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICT__ ;
73
- import static com .oracle .graal .python .nodes .SpecialMethodNames .SORT ;
74
69
import static com .oracle .graal .python .nodes .SpecialMethodNames .__DIR__ ;
75
70
import static com .oracle .graal .python .nodes .SpecialMethodNames .__GETATTRIBUTE__ ;
76
71
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
77
72
import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
78
73
import com .oracle .graal .python .nodes .builtins .ListNodes ;
79
74
import com .oracle .graal .python .nodes .call .CallNode ;
80
- import com .oracle .graal .python .nodes .call .special .LookupAndCallBinaryNode ;
81
75
import com .oracle .graal .python .nodes .expression .CoerceToBooleanNode ;
82
76
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
83
77
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
89
83
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
90
84
import com .oracle .graal .python .runtime .exception .PException ;
91
85
import com .oracle .truffle .api .CompilerDirectives ;
92
- import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
93
86
import com .oracle .truffle .api .dsl .Cached ;
94
87
import com .oracle .truffle .api .dsl .Fallback ;
95
88
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
@@ -168,7 +161,7 @@ Object dir(PythonModule self,
168
161
}
169
162
} else {
170
163
String name = getName (self , pol , hashLib , castToJavaStringNode );
171
- throw this . raise (PythonBuiltinClassType .TypeError , "%s.__dict__ is not a dictionary" , name );
164
+ throw raise (PythonBuiltinClassType .TypeError , ErrorMessages . IS_NOT_A_DICTIONARY , name );
172
165
}
173
166
}
174
167
@@ -180,7 +173,7 @@ private String getName(PythonModule self, PythonObjectLibrary pol, HashingStorag
180
173
return castToJavaStringNode .execute (name );
181
174
}
182
175
}
183
- throw raise (PythonBuiltinClassType .SystemError , "nameless module" );
176
+ throw raise (PythonBuiltinClassType .SystemError , ErrorMessages . NAMELESS_MODULE );
184
177
}
185
178
186
179
protected static boolean isDict (Object object , IsBuiltinClassProfile profile ) {
@@ -229,46 +222,6 @@ Object raise(Object self, @SuppressWarnings("unused") Object dict) {
229
222
}
230
223
}
231
224
232
- @ Builtin (name = __DIR__ , minNumOfPositionalArgs = 1 , maxNumOfPositionalArgs = 1 )
233
- @ GenerateNodeFactory
234
- @ TypeSystemReference (PythonArithmeticTypes .class )
235
- public abstract static class DirNode extends PythonBuiltinNode {
236
- @ Specialization
237
- public Object module (VirtualFrame frame , PythonModule self ,
238
- @ Cached ("create(__GETATTRIBUTE__)" ) LookupAndCallBinaryNode getDictNode ,
239
- @ Cached ("create(__GETATTRIBUTE__)" ) LookupAndCallBinaryNode getSortNode ,
240
- @ Cached CallNode callDirNode ,
241
- @ Cached CallNode callSortNode ,
242
- @ Cached GetDictStorageNode getDictStorageNode ,
243
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary lib ,
244
- @ Cached PRaiseNode raiseNode ) {
245
- Object dict = getDictNode .executeObject (frame , self , __DICT__ );
246
- Object res ;
247
- if (dict instanceof PDict ) {
248
- Object dir = HashingStorageLibrary .getUncached ().getItem (getDictStorageNode .execute ((PHashingCollection ) dict ), __DIR__ );
249
- if (dir != null && dir != PNone .NO_VALUE ) {
250
- res = callDirNode .execute (dir );
251
- } else {
252
- HashingStorage storage = getDictStorageNode .execute ((PHashingCollection ) dict );
253
- HashingStorageIterator <Object > keys = lib .keys (storage ).iterator ();
254
- int len = lib .length (storage );
255
- Object [] a = new Object [len ];
256
- for (int i = 0 ; keys .hasNext (); i ++) {
257
- a [i ] = keys .next ();
258
- }
259
- res = PythonObjectFactory .getUncached ().createList (a );
260
- }
261
- } else {
262
- throw raiseNode .raise (TypeError , ErrorMessages .IS_NOT_A_DICTIONARY , self );
263
- }
264
- Object sort = getSortNode .executeObject (frame , res , SORT );
265
- if (sort != PNone .NO_VALUE ) {
266
- callSortNode .execute (sort );
267
- }
268
- return res ;
269
- }
270
- }
271
-
272
225
@ Builtin (name = __GETATTRIBUTE__ , minNumOfPositionalArgs = 2 )
273
226
@ GenerateNodeFactory
274
227
public abstract static class ModuleGetattritbuteNode extends PythonBinaryBuiltinNode {
0 commit comments