4444import static com .oracle .graal .python .builtins .PythonBuiltinClassType .SystemError ;
4545import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
4646import 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 ;
4848import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DOC__ ;
4949import static com .oracle .graal .python .nodes .SpecialAttributeNames .__MODULE__ ;
5050import static com .oracle .graal .python .nodes .SpecialAttributeNames .__NAME__ ;
7676import com .oracle .graal .python .builtins .Python3Core ;
7777import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
7878import com .oracle .graal .python .builtins .PythonBuiltins ;
79- import com .oracle .graal .python .builtins .modules .BuiltinConstructors .MappingproxyNode ;
8079import com .oracle .graal .python .builtins .modules .SysModuleBuiltins ;
8180import com .oracle .graal .python .builtins .modules .cext .PythonCextBuiltinsFactory .CreateFunctionNodeGen ;
8281import com .oracle .graal .python .builtins .objects .PNone ;
179178import com .oracle .graal .python .builtins .objects .function .Signature ;
180179import com .oracle .graal .python .builtins .objects .getsetdescriptor .GetSetDescriptor ;
181180import com .oracle .graal .python .builtins .objects .ints .PInt ;
181+ import com .oracle .graal .python .builtins .objects .list .ListBuiltins ;
182182import com .oracle .graal .python .builtins .objects .memoryview .BufferLifecycleManager ;
183183import com .oracle .graal .python .builtins .objects .memoryview .MemoryViewNodes ;
184184import com .oracle .graal .python .builtins .objects .memoryview .NativeBufferLifecycleManager ;
195195import com .oracle .graal .python .builtins .objects .tuple .StructSequence .Descriptor ;
196196import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
197197import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
198- import com .oracle .graal .python .builtins .objects .type .PythonClass ;
199198import com .oracle .graal .python .builtins .objects .type .PythonManagedClass ;
200199import com .oracle .graal .python .builtins .objects .type .SpecialMethodSlot ;
201200import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
287286import com .oracle .truffle .api .nodes .RootNode ;
288287import com .oracle .truffle .api .object .DynamicObjectLibrary ;
289288import com .oracle .truffle .api .object .HiddenKey ;
289+ import com .oracle .truffle .api .profiles .BranchProfile ;
290290import com .oracle .truffle .api .profiles .ConditionProfile ;
291+ import com .oracle .truffle .api .profiles .LoopConditionProfile ;
291292import com .oracle .truffle .api .profiles .ValueProfile ;
292293import com .oracle .truffle .api .utilities .CyclicAssumption ;
293294
@@ -297,7 +298,6 @@ public final class PythonCextBuiltins extends PythonBuiltins {
297298
298299 public static final String PYTHON_CEXT = "python_cext" ;
299300
300- private static final String ERROR_HANDLER = "error_handler" ;
301301 public static final String NATIVE_NULL = "native_null" ;
302302
303303 private PythonObject errorHandler ;
@@ -310,11 +310,6 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
310310 @ Override
311311 public void initialize (Python3Core core ) {
312312 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 );
318313 // TODO can be removed when python_cext.py is gone
319314 builtinConstants .put (NATIVE_NULL , core .getContext ().getNativeNull ());
320315 builtinConstants .put ("PyEval_SaveThread" , new PyEvalSaveThread ());
@@ -380,15 +375,6 @@ Object run(VirtualFrame frame, Object o) {
380375 }
381376 }
382377
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-
392378 @ Builtin (name = "Py_NotImplemented" )
393379 @ GenerateNodeFactory
394380 public abstract static class PyNotImplementedNode extends PythonBuiltinNode {
@@ -425,15 +411,36 @@ static Object run() {
425411 }
426412 }
427413
428- ///////////// mappingproxy /////////////
429-
430- @ Builtin (name = "PyDictProxy_New" , minNumOfPositionalArgs = 1 )
414+ @ Builtin (name = "PyTruffle_Dict_From_List" , minNumOfPositionalArgs = 1 )
431415 @ GenerateNodeFactory
432- public abstract static class PyDictProxyNewNode extends PythonUnaryBuiltinNode {
416+ public abstract static class DictFromListNode extends PythonUnaryBuiltinNode {
433417 @ 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+ }
437444 }
438445 }
439446
@@ -2407,34 +2414,6 @@ private static void addSlot(Object clsPtr, Object tpDictPtr, Object namePtr, Obj
24072414 }
24082415 }
24092416
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-
24382417 abstract static class CFunctionNewExMethodNode extends Node {
24392418
24402419 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)
26582637 }
26592638 }
26602639
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-
26812640 // directly called without landing function
26822641 @ Builtin (name = "AddGetSet" , minNumOfPositionalArgs = 7 , parameterNames = {"cls" , "tpDict" , "name" , "getter" , "setter" , "doc" , "closure" })
26832642 @ ArgumentClinic (name = "name" , conversion = ClinicConversion .String )
0 commit comments