1
1
/*
2
- * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
40
40
*/
41
41
package com .oracle .graal .python .builtins .modules .cext ;
42
42
43
+ import static com .oracle .graal .python .builtins .objects .cext .common .CExtContext .isClassOrStaticMethod ;
43
44
45
+ import com .oracle .graal .python .annotations .ArgumentClinic ;
44
46
import java .util .List ;
45
47
import com .oracle .graal .python .builtins .Builtin ;
46
48
import com .oracle .graal .python .builtins .CoreFunctions ;
47
49
import com .oracle .graal .python .builtins .Python3Core ;
48
50
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
49
51
import com .oracle .graal .python .builtins .PythonBuiltins ;
52
+ import com .oracle .graal .python .builtins .modules .BuiltinConstructors ;
50
53
import com .oracle .graal .python .builtins .modules .BuiltinFunctions .IsInstanceNode ;
54
+ import com .oracle .graal .python .builtins .modules .cext .PythonCextDescrBuiltinsClinicProviders .PyDescrNewClassMethodClinicProviderGen ;
55
+ import com .oracle .graal .python .builtins .modules .cext .PythonCextDescrBuiltinsClinicProviders .PyDescrNewGetSetNodeClinicProviderGen ;
56
+ import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes ;
57
+ import com .oracle .graal .python .builtins .objects .getsetdescriptor .GetSetDescriptor ;
51
58
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
59
+ import com .oracle .graal .python .nodes .function .builtins .PythonClinicBuiltinNode ;
52
60
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
61
+ import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
53
62
import com .oracle .truffle .api .dsl .Cached ;
54
63
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
55
64
import com .oracle .truffle .api .dsl .NodeFactory ;
@@ -70,20 +79,74 @@ public void initialize(Python3Core core) {
70
79
super .initialize (core );
71
80
}
72
81
73
- //def PyMethodDescr_Check(func):
74
- // return 1 if isinstance(func, type(list.append)) else 0
75
-
82
+ @ Builtin (name = "PyDictProxy_New" , minNumOfPositionalArgs = 1 )
83
+ @ GenerateNodeFactory
84
+ public abstract static class PyDictProxyNewNode extends PythonUnaryBuiltinNode {
85
+ @ Specialization
86
+ public static Object values (VirtualFrame frame , Object obj ,
87
+ @ Cached BuiltinConstructors .MappingproxyNode mappingNode ) {
88
+ return mappingNode .execute (frame , PythonBuiltinClassType .PMappingproxy , obj );
89
+ }
90
+ }
91
+
92
+ // directly called without landing function
93
+ @ Builtin (name = "PyDescr_NewGetSet" , minNumOfPositionalArgs = 6 , parameterNames = {"name" , "cls" , "getter" , "setter" , "doc" , "closure" })
94
+ @ ArgumentClinic (name = "name" , conversion = ArgumentClinic .ClinicConversion .String )
95
+ @ GenerateNodeFactory
96
+ abstract static class PyDescrNewGetSetNode extends PythonClinicBuiltinNode {
97
+ @ Override
98
+ protected ArgumentClinicProvider getArgumentClinic () {
99
+ return PyDescrNewGetSetNodeClinicProviderGen .INSTANCE ;
100
+ }
101
+
102
+ @ Specialization
103
+ Object doNativeCallable (String name , Object cls , Object getter , Object setter , Object doc , Object closure ,
104
+ @ Cached PythonCextBuiltins .CreateGetSetNode createGetSetNode ,
105
+ @ Cached CExtNodes .ToSulongNode toSulongNode ) {
106
+ GetSetDescriptor descr = createGetSetNode .execute (name , cls , getter , setter , doc , closure ,
107
+ getLanguage (), factory ());
108
+ return toSulongNode .execute (descr );
109
+ }
110
+ }
111
+
112
+ // directly called without landing function
113
+ @ Builtin (name = "PyDescr_NewClassMethod" , minNumOfPositionalArgs = 6 , parameterNames = {"name" , "doc" , "flags" , "wrapper" , "cfunc" , "primary" })
114
+ @ ArgumentClinic (name = "name" , conversion = ArgumentClinic .ClinicConversion .String )
115
+ @ GenerateNodeFactory
116
+ abstract static class PyDescrNewClassMethod extends PythonClinicBuiltinNode {
117
+ @ Override
118
+ protected ArgumentClinicProvider getArgumentClinic () {
119
+ return PyDescrNewClassMethodClinicProviderGen .INSTANCE ;
120
+ }
121
+
122
+ @ Specialization
123
+ Object doNativeCallable (String name , Object doc , int flags , Object wrapper , Object methObj , Object primary ,
124
+ @ Cached CExtNodes .AsPythonObjectNode asPythonObjectNode ,
125
+ @ Cached PythonCextBuiltins .NewClassMethodNode newClassMethodNode ,
126
+ @ Cached CExtNodes .ToNewRefNode newRefNode ) {
127
+ Object type = asPythonObjectNode .execute (primary );
128
+ Object func = newClassMethodNode .execute (name , methObj , flags , wrapper , type , doc , factory ());
129
+ if (!isClassOrStaticMethod (flags )) {
130
+ /*
131
+ * NewClassMethodNode only wraps method with METH_CLASS and METH_STATIC set but we
132
+ * need to do so here.
133
+ */
134
+ func = factory ().createClassmethodFromCallableObj (func );
135
+ }
136
+ return newRefNode .execute (func );
137
+ }
138
+ }
139
+
76
140
@ Builtin (name = "PyMethodDescr_Check" , minNumOfPositionalArgs = 1 )
77
141
@ GenerateNodeFactory
78
142
public abstract static class PyMethodDescrCheckNode extends PythonUnaryBuiltinNode {
79
143
80
144
@ SuppressWarnings ("unused" )
81
145
@ Specialization
82
- int check (VirtualFrame frame , Object func ,
83
- @ Cached IsInstanceNode isInstanceNode ) {
146
+ static int check (VirtualFrame frame , Object func ,
147
+ @ Cached IsInstanceNode isInstanceNode ) {
84
148
return isInstanceNode .executeWith (frame , func , PythonBuiltinClassType .PBuiltinFunction ) ? 1 : 0 ;
85
149
}
86
150
}
87
151
88
-
89
152
}
0 commit comments