137
137
import com .oracle .graal .python .nodes .SpecialMethodNames ;
138
138
import com .oracle .graal .python .nodes .argument .ReadArgumentNode ;
139
139
import com .oracle .graal .python .nodes .attributes .DeleteAttributeNode ;
140
+ import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
140
141
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
141
142
import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetFixedAttributeNode ;
142
143
import com .oracle .graal .python .nodes .attributes .HasInheritedAttributeNode ;
173
174
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
174
175
import com .oracle .graal .python .nodes .object .GetClassNode ;
175
176
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
176
- import com .oracle .graal .python .nodes .statement .AbstractImportNode ;
177
177
import com .oracle .graal .python .nodes .subscript .SetItemNode ;
178
178
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
179
179
import com .oracle .graal .python .nodes .util .CannotCastException ;
193
193
import com .oracle .graal .python .util .Supplier ;
194
194
import com .oracle .truffle .api .Assumption ;
195
195
import com .oracle .truffle .api .CallTarget ;
196
+ import com .oracle .truffle .api .CompilerAsserts ;
196
197
import com .oracle .truffle .api .CompilerDirectives ;
197
198
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
198
199
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
199
200
import com .oracle .truffle .api .RootCallTarget ;
200
- import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
201
201
import com .oracle .truffle .api .TruffleLanguage .Env ;
202
202
import com .oracle .truffle .api .TruffleLanguage .LanguageReference ;
203
203
import com .oracle .truffle .api .debug .Debugger ;
204
204
import com .oracle .truffle .api .dsl .Cached ;
205
205
import com .oracle .truffle .api .dsl .Cached .Shared ;
206
- import com .oracle .truffle .api .dsl .CachedContext ;
207
206
import com .oracle .truffle .api .dsl .Fallback ;
208
207
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
209
208
import com .oracle .truffle .api .dsl .ImportStatic ;
@@ -1968,6 +1967,7 @@ PTuple update(PTuple bases, Object[] arguments, int nargs,
1968
1967
@ Cached GetClassNode getMroClass ,
1969
1968
@ Cached (parameters = "__MRO_ENTRIES__" ) LookupAttributeInMRONode getMroEntries ,
1970
1969
@ Cached CallBinaryMethodNode callMroEntries ) {
1970
+ CompilerAsserts .neverPartOfCompilation ();
1971
1971
ArrayList <Object > newBases = null ;
1972
1972
for (int i = 0 ; i < nargs ; i ++) {
1973
1973
Object base = arguments [i ];
@@ -2026,6 +2026,7 @@ Object calculate(Object metatype, PTuple bases,
2026
2026
@ Cached GetClassNode getClass ,
2027
2027
@ Cached IsSubtypeNode isSubType ,
2028
2028
@ Cached IsSubtypeNode isSubTypeReverse ) {
2029
+ CompilerAsserts .neverPartOfCompilation ();
2029
2030
/*
2030
2031
* Determine the proper metatype to deal with this, and check for metatype conflicts
2031
2032
* while we're at it. Note that if some other metatype wins to contract, it's possible
@@ -2055,25 +2056,25 @@ Object calculate(Object metatype, PTuple bases,
2055
2056
public abstract static class BuildClassNode extends PythonVarargsBuiltinNode {
2056
2057
@ TruffleBoundary
2057
2058
private static Object buildJavaClass (Object func , String name , Object base ) {
2058
- Object module = AbstractImportNode . importModule (BuiltinNames .__GRAALPYTHON__ );
2059
+ Object module = PythonLanguage . getContext (). getCore (). lookupBuiltinModule (BuiltinNames .__GRAALPYTHON__ );
2059
2060
Object buildFunction = PythonObjectLibrary .getUncached ().lookupAttribute (module , null , "build_java_class" );
2060
2061
return CallNode .getUncached ().execute (buildFunction , func , name , base );
2061
2062
}
2062
2063
2063
2064
@ Specialization
2064
2065
protected Object doItNonFunction (VirtualFrame frame , Object function , Object [] arguments , PKeyword [] keywords ,
2065
- @ CachedContext (PythonLanguage .class ) ContextReference <PythonContext > contextRef ,
2066
2066
@ Cached PythonObjectFactory factory ,
2067
2067
@ Cached CalculateMetaclassNode calculateMetaClass ,
2068
- @ Cached (parameters = "__PREPARE__" ) LookupAttributeInMRONode getPrepare ,
2069
- @ Cached GetClassNode getGetItemClass ,
2068
+ @ Cached ("create(__PREPARE__)" ) GetAttributeNode getPrepare ,
2070
2069
@ Cached (parameters = "__GETITEM__" ) LookupAttributeInMRONode getGetItem ,
2070
+ @ Cached GetClassNode getGetItemClass ,
2071
2071
@ Cached CallVarargsMethodNode callPrep ,
2072
2072
@ Cached CallVarargsMethodNode callType ,
2073
2073
@ Cached CallUnaryMethodNode callBody ,
2074
2074
@ Cached UpdateBasesNode update ,
2075
2075
@ Cached SetItemNode setOrigBases ,
2076
- @ Cached GetClassNode getClass ) {
2076
+ @ Cached GetClassNode getClass ,
2077
+ @ Cached IsBuiltinClassProfile noAttributeProfile ) {
2077
2078
2078
2079
if (arguments .length < 1 ) {
2079
2080
throw raise (PythonErrorType .TypeError , "__build_class__: not enough arguments" );
@@ -2119,14 +2120,14 @@ class InitializeBuildClass {
2119
2120
PythonUtils .arraycopy (keywords , i + 1 , mkw , i , mkw .length - i );
2120
2121
2121
2122
// metaclass is explicitly given, check if it's indeed a class
2122
- isClass = IsTypeNode .getUncached ().equals (meta );
2123
+ isClass = IsTypeNode .getUncached ().execute (meta );
2123
2124
break ;
2124
2125
}
2125
2126
}
2126
2127
if (meta == null ) {
2127
2128
// if there are no bases, use type:
2128
2129
if (bases .getSequenceStorage ().length () == 0 ) {
2129
- meta = contextRef . get ().getCore ().lookupType (PythonBuiltinClassType .PythonClass );
2130
+ meta = PythonLanguage . getContext ().getCore ().lookupType (PythonBuiltinClassType .PythonClass );
2130
2131
} else {
2131
2132
// else get the type of the first base
2132
2133
meta = getClass .execute (bases .getSequenceStorage ().getItemNormalized (0 ));
@@ -2140,23 +2141,22 @@ class InitializeBuildClass {
2140
2141
meta = calculateMetaClass .execute (meta , bases );
2141
2142
}
2142
2143
// else: meta is not a class, so we cannot do the metaclass calculation, so we
2143
- // will
2144
- // use the explicitly given object as it is
2144
+ // will use the explicitly given object as it is
2145
2145
}
2146
2146
}
2147
2147
InitializeBuildClass init = new InitializeBuildClass ();
2148
2148
2149
- Object prep = getPrepare .execute (init .meta );
2150
2149
Object ns ;
2151
- if (PGuards .isNoValue (prep )) {
2150
+ try {
2151
+ Object prep = getPrepare .executeObject (frame , init .meta );
2152
+ ns = callPrep .execute (frame , prep , new Object []{name , init .bases }, init .mkw );
2153
+ } catch (PException p ) {
2154
+ p .expectAttributeError (noAttributeProfile );
2152
2155
ns = factory .createDict ();
2153
- } else {
2154
- Object [] args = PGuards .isFunction (prep ) ? new Object []{name , init .bases } : new Object []{init .meta , name , init .bases };
2155
- ns = callPrep .execute (frame , prep , args , init .mkw );
2156
2156
}
2157
2157
if (PGuards .isNoValue (getGetItem .execute (getGetItemClass .execute (ns )))) {
2158
2158
if (init .isClass ) {
2159
- throw raise (PythonErrorType .TypeError , "%p .__prepare__() must return a mapping, not %p" , init .meta , ns );
2159
+ throw raise (PythonErrorType .TypeError , "%N .__prepare__() must return a mapping, not %p" , init .meta , ns );
2160
2160
} else {
2161
2161
throw raise (PythonErrorType .TypeError , "<metaclass>.__prepare__() must return a mapping, not %p" , ns );
2162
2162
}
0 commit comments