44
44
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .SystemError ;
45
45
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
46
46
import static com .oracle .graal .python .builtins .objects .cext .common .CExtContext .METH_CLASS ;
47
- import static com .oracle .graal .python .builtins . objects . cext . common . CExtContext . isClassOrStaticMethod ;
47
+ import static com .oracle .graal .python .nodes . ErrorMessages . LIST_CANNOT_BE_CONVERTED_TO_DICT ;
48
48
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DOC__ ;
49
49
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__MODULE__ ;
50
50
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__NAME__ ;
76
76
import com .oracle .graal .python .builtins .Python3Core ;
77
77
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
78
78
import com .oracle .graal .python .builtins .PythonBuiltins ;
79
- import com .oracle .graal .python .builtins .modules .BuiltinConstructors .MappingproxyNode ;
80
79
import com .oracle .graal .python .builtins .modules .SysModuleBuiltins ;
81
80
import com .oracle .graal .python .builtins .modules .cext .PythonCextBuiltinsFactory .CreateFunctionNodeGen ;
82
81
import com .oracle .graal .python .builtins .objects .PNone ;
179
178
import com .oracle .graal .python .builtins .objects .function .Signature ;
180
179
import com .oracle .graal .python .builtins .objects .getsetdescriptor .GetSetDescriptor ;
181
180
import com .oracle .graal .python .builtins .objects .ints .PInt ;
181
+ import com .oracle .graal .python .builtins .objects .list .ListBuiltins ;
182
182
import com .oracle .graal .python .builtins .objects .memoryview .BufferLifecycleManager ;
183
183
import com .oracle .graal .python .builtins .objects .memoryview .MemoryViewNodes ;
184
184
import com .oracle .graal .python .builtins .objects .memoryview .NativeBufferLifecycleManager ;
195
195
import com .oracle .graal .python .builtins .objects .tuple .StructSequence .Descriptor ;
196
196
import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
197
197
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
198
- import com .oracle .graal .python .builtins .objects .type .PythonClass ;
199
198
import com .oracle .graal .python .builtins .objects .type .PythonManagedClass ;
200
199
import com .oracle .graal .python .builtins .objects .type .SpecialMethodSlot ;
201
200
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
287
286
import com .oracle .truffle .api .nodes .RootNode ;
288
287
import com .oracle .truffle .api .object .DynamicObjectLibrary ;
289
288
import com .oracle .truffle .api .object .HiddenKey ;
289
+ import com .oracle .truffle .api .profiles .BranchProfile ;
290
290
import com .oracle .truffle .api .profiles .ConditionProfile ;
291
+ import com .oracle .truffle .api .profiles .LoopConditionProfile ;
291
292
import com .oracle .truffle .api .profiles .ValueProfile ;
292
293
import com .oracle .truffle .api .utilities .CyclicAssumption ;
293
294
@@ -297,7 +298,6 @@ public final class PythonCextBuiltins extends PythonBuiltins {
297
298
298
299
public static final String PYTHON_CEXT = "python_cext" ;
299
300
300
- private static final String ERROR_HANDLER = "error_handler" ;
301
301
public static final String NATIVE_NULL = "native_null" ;
302
302
303
303
private PythonObject errorHandler ;
@@ -310,11 +310,6 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
310
310
@ Override
311
311
public void initialize (Python3Core core ) {
312
312
super .initialize (core );
313
- PythonClass errorHandlerClass = core .factory ().createPythonClassAndFixupSlots (core .getLanguage (), PythonBuiltinClassType .PythonClass ,
314
- "CErrorHandler" , new PythonAbstractClass []{core .lookupType (PythonBuiltinClassType .PythonObject )});
315
- builtinConstants .put ("CErrorHandler" , errorHandlerClass );
316
- errorHandler = core .factory ().createPythonObject (errorHandlerClass );
317
- builtinConstants .put (ERROR_HANDLER , errorHandler );
318
313
// TODO can be removed when python_cext.py is gone
319
314
builtinConstants .put (NATIVE_NULL , core .getContext ().getNativeNull ());
320
315
builtinConstants .put ("PyEval_SaveThread" , new PyEvalSaveThread ());
@@ -380,15 +375,6 @@ Object run(VirtualFrame frame, Object o) {
380
375
}
381
376
}
382
377
383
- @ Builtin (name = "Py_ErrorHandler" , minNumOfPositionalArgs = 1 , declaresExplicitSelf = true )
384
- @ GenerateNodeFactory
385
- public abstract static class PyErrorHandlerNode extends PythonUnaryBuiltinNode {
386
- @ Specialization
387
- static Object run (PythonModule cextPython ) {
388
- return ((PythonCextBuiltins ) cextPython .getBuiltins ()).errorHandler ;
389
- }
390
- }
391
-
392
378
@ Builtin (name = "Py_NotImplemented" )
393
379
@ GenerateNodeFactory
394
380
public abstract static class PyNotImplementedNode extends PythonBuiltinNode {
@@ -425,15 +411,36 @@ static Object run() {
425
411
}
426
412
}
427
413
428
- ///////////// mappingproxy /////////////
429
-
430
- @ Builtin (name = "PyDictProxy_New" , minNumOfPositionalArgs = 1 )
414
+ @ Builtin (name = "PyTruffle_Dict_From_List" , minNumOfPositionalArgs = 1 )
431
415
@ GenerateNodeFactory
432
- public abstract static class PyDictProxyNewNode extends PythonUnaryBuiltinNode {
416
+ public abstract static class DictFromListNode extends PythonUnaryBuiltinNode {
433
417
@ Specialization
434
- public static Object values (VirtualFrame frame , Object obj ,
435
- @ Cached MappingproxyNode mappingNode ) {
436
- return mappingNode .execute (frame , PythonBuiltinClassType .PMappingproxy , obj );
418
+ public Object values (VirtualFrame frame , Object list ,
419
+ @ Cached com .oracle .graal .python .lib .PyObjectSizeNode sizeNode ,
420
+ @ Cached ListBuiltins .GetItemNode getItemNode ,
421
+ @ Cached BranchProfile wrongLenProfile ,
422
+ @ Cached LoopConditionProfile loopProfile ,
423
+ @ CachedLibrary (limit = "3" ) HashingStorageLibrary lib ,
424
+ @ Cached PRaiseNativeNode raiseNativeNode ,
425
+ @ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ) {
426
+ try {
427
+ int size = sizeNode .execute (frame , list );
428
+ if (size % 2 != 0 ) {
429
+ wrongLenProfile .enter ();
430
+ return raiseNativeNode .raise (frame , getContext ().getNativeNull (), PythonBuiltinClassType .SystemError , LIST_CANNOT_BE_CONVERTED_TO_DICT );
431
+ }
432
+ HashingStorage store = PDict .createNewStorage (false , size );
433
+ loopProfile .profileCounted (size );
434
+ for (int i = 0 ; loopProfile .profile (i < size ); i = i + 2 ) {
435
+ Object k = getItemNode .execute (frame , list , i );
436
+ Object v = getItemNode .execute (frame , list , i + 1 );
437
+ store = lib .setItem (store , k , v );
438
+ }
439
+ return factory ().createDict (store );
440
+ } catch (PException e ) {
441
+ transformExceptionToNativeNode .execute (e );
442
+ return getContext ().getNativeNull ();
443
+ }
437
444
}
438
445
}
439
446
@@ -2407,34 +2414,6 @@ private static void addSlot(Object clsPtr, Object tpDictPtr, Object namePtr, Obj
2407
2414
}
2408
2415
}
2409
2416
2410
- // directly called without landing function
2411
- @ Builtin (name = "PyDescr_NewClassMethod" , minNumOfPositionalArgs = 6 , parameterNames = {"name" , "doc" , "flags" , "wrapper" , "cfunc" , "primary" })
2412
- @ ArgumentClinic (name = "name" , conversion = ArgumentClinic .ClinicConversion .String )
2413
- @ GenerateNodeFactory
2414
- abstract static class PyDescrNewClassMethod extends PythonClinicBuiltinNode {
2415
- @ Override
2416
- protected ArgumentClinicProvider getArgumentClinic () {
2417
- return PythonCextBuiltinsClinicProviders .PyDescrNewClassMethodClinicProviderGen .INSTANCE ;
2418
- }
2419
-
2420
- @ Specialization
2421
- Object doNativeCallable (String name , Object doc , int flags , Object wrapper , Object methObj , Object primary ,
2422
- @ Cached AsPythonObjectNode asPythonObjectNode ,
2423
- @ Cached NewClassMethodNode newClassMethodNode ,
2424
- @ Cached ToNewRefNode newRefNode ) {
2425
- Object type = asPythonObjectNode .execute (primary );
2426
- Object func = newClassMethodNode .execute (name , methObj , flags , wrapper , type , doc , factory ());
2427
- if (!isClassOrStaticMethod (flags )) {
2428
- /*
2429
- * NewClassMethodNode only wraps method with METH_CLASS and METH_STATIC set but we
2430
- * need to do so here.
2431
- */
2432
- func = factory ().createClassmethodFromCallableObj (func );
2433
- }
2434
- return newRefNode .execute (func );
2435
- }
2436
- }
2437
-
2438
2417
abstract static class CFunctionNewExMethodNode extends Node {
2439
2418
2440
2419
abstract Object execute (String name , Object methObj , Object flags , Object wrapper , Object self , Object module , Object doc ,
@@ -2658,26 +2637,6 @@ private static RootCallTarget setterCallTarget(String name, PythonLanguage lang)
2658
2637
}
2659
2638
}
2660
2639
2661
- // directly called without landing function
2662
- @ Builtin (name = "PyDescr_NewGetSet" , minNumOfPositionalArgs = 6 , parameterNames = {"name" , "cls" , "getter" , "setter" , "doc" , "closure" })
2663
- @ ArgumentClinic (name = "name" , conversion = ClinicConversion .String )
2664
- @ GenerateNodeFactory
2665
- abstract static class PyDescrNewGetSetNode extends PythonClinicBuiltinNode {
2666
- @ Override
2667
- protected ArgumentClinicProvider getArgumentClinic () {
2668
- return PythonCextBuiltinsClinicProviders .PyDescrNewGetSetNodeClinicProviderGen .INSTANCE ;
2669
- }
2670
-
2671
- @ Specialization
2672
- Object doNativeCallable (String name , Object cls , Object getter , Object setter , Object doc , Object closure ,
2673
- @ Cached CreateGetSetNode createGetSetNode ,
2674
- @ Cached CExtNodes .ToSulongNode toSulongNode ) {
2675
- GetSetDescriptor descr = createGetSetNode .execute (name , cls , getter , setter , doc , closure ,
2676
- getLanguage (), factory ());
2677
- return toSulongNode .execute (descr );
2678
- }
2679
- }
2680
-
2681
2640
// directly called without landing function
2682
2641
@ Builtin (name = "AddGetSet" , minNumOfPositionalArgs = 7 , parameterNames = {"cls" , "tpDict" , "name" , "getter" , "setter" , "doc" , "closure" })
2683
2642
@ ArgumentClinic (name = "name" , conversion = ClinicConversion .String )
0 commit comments