Skip to content

Commit 3c4054d

Browse files
committed
fix creation of builtin function classmethods, fix copyrights
1 parent 7228ada commit 3c4054d

File tree

5 files changed

+177
-73
lines changed

5 files changed

+177
-73
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
109109
import com.oracle.graal.python.builtins.objects.type.PythonClass;
110110
import com.oracle.graal.python.nodes.PGuards;
111-
import com.oracle.graal.python.nodes.SpecialAttributeNames;
112111
import com.oracle.graal.python.nodes.argument.CreateArgumentsNode;
113112
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
114113
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
3-
* Copyright (c) 2014, Regents of the University of California
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
5-
* All rights reserved.
5+
* The Universal Permissive License (UPL), Version 1.0
66
*
7-
* Redistribution and use in source and binary forms, with or without modification, are
8-
* permitted provided that the following conditions are met:
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
914
*
10-
* 1. Redistributions of source code must retain the above copyright notice, this list of
11-
* conditions and the following disclaimer.
12-
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13-
* conditions and the following disclaimer in the documentation and/or other materials provided
14-
* with the distribution.
15+
* (a) the Software, and
1516
*
16-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17-
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19-
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21-
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22-
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24-
* OF THE POSSIBILITY OF SUCH DAMAGE.
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
2540
*/
26-
2741
package com.oracle.graal.python.builtins.objects.method;
2842

2943
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GET__;
@@ -34,11 +48,15 @@
3448
import com.oracle.graal.python.builtins.CoreFunctions;
3549
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3650
import com.oracle.graal.python.builtins.PythonBuiltins;
51+
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
3752
import com.oracle.graal.python.builtins.objects.function.PFunction;
53+
import com.oracle.graal.python.builtins.objects.method.ClassmethodBuiltinsFactory.MakeMethodNodeGen;
54+
import com.oracle.graal.python.nodes.PNodeWithContext;
3855
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
3956
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
4057
import com.oracle.graal.python.nodes.object.GetClassNode;
4158
import com.oracle.truffle.api.dsl.Cached;
59+
import com.oracle.truffle.api.dsl.Fallback;
4260
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
4361
import com.oracle.truffle.api.dsl.NodeFactory;
4462
import com.oracle.truffle.api.dsl.Specialization;
@@ -55,32 +73,51 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
5573
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4)
5674
@GenerateNodeFactory
5775
abstract static class CallNode extends PythonBuiltinNode {
76+
@Child MakeMethodNode makeMethod = MakeMethodNode.create();
77+
5878
@Specialization(guards = {"isNoValue(type)"})
5979
protected Object get(PDecoratedMethod self, Object obj, @SuppressWarnings("unused") Object type,
6080
@Cached("create()") GetClassNode getClass,
61-
@Cached("create()") BranchProfile uninitialized,
62-
@Cached("create()") BranchProfile genericCallable) {
63-
return doGet(self, getClass.execute(obj), uninitialized, genericCallable);
81+
@Cached("create()") BranchProfile uninitialized) {
82+
return doGet(self, getClass.execute(obj), uninitialized);
6483
}
6584

6685
@Specialization(guards = "!isNoValue(type)")
6786
protected Object doIt(PDecoratedMethod self, @SuppressWarnings("unused") Object obj, Object type,
68-
@Cached("create()") BranchProfile uninitialized,
69-
@Cached("create()") BranchProfile genericCallable) {
70-
return doGet(self, type, uninitialized, genericCallable);
87+
@Cached("create()") BranchProfile uninitialized) {
88+
return doGet(self, type, uninitialized);
7189
}
7290

73-
private PMethod doGet(PDecoratedMethod self, Object type, BranchProfile uninitialized, BranchProfile genericCallable) {
91+
private Object doGet(PDecoratedMethod self, Object type, BranchProfile uninitialized) {
7492
Object callable = self.getCallable();
7593
if (callable == null) {
7694
uninitialized.enter();
7795
throw raise(PythonBuiltinClassType.RuntimeError, "uninitialized classmethod object");
7896
}
79-
if (callable instanceof PFunction) {
80-
return factory().createMethod(type, (PFunction) callable);
81-
}
82-
genericCallable.enter();
83-
throw raise(PythonBuiltinClassType.NotImplementedError, "classmethods with non-function callables");
97+
return makeMethod.execute(type, callable);
98+
}
99+
}
100+
101+
abstract static class MakeMethodNode extends PNodeWithContext {
102+
abstract Object execute(Object self, Object func);
103+
104+
@Specialization
105+
Object method(Object self, PFunction func) {
106+
return factory().createMethod(self, func);
107+
}
108+
109+
@Specialization
110+
Object methodBuiltin(Object self, PBuiltinFunction func) {
111+
return factory().createBuiltinMethod(self, func);
112+
}
113+
114+
@Fallback
115+
Object generic(@SuppressWarnings("unused") Object self, Object func) {
116+
throw raise(PythonBuiltinClassType.NotImplementedError, "classmethods with non-function callables '%p'", func);
117+
}
118+
119+
static MakeMethodNode create() {
120+
return MakeMethodNodeGen.create();
84121
}
85122
}
86123
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/DecoratedMethodBuiltins.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
3-
* Copyright (c) 2014, Regents of the University of California
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
5-
* All rights reserved.
5+
* The Universal Permissive License (UPL), Version 1.0
66
*
7-
* Redistribution and use in source and binary forms, with or without modification, are
8-
* permitted provided that the following conditions are met:
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
914
*
10-
* 1. Redistributions of source code must retain the above copyright notice, this list of
11-
* conditions and the following disclaimer.
12-
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13-
* conditions and the following disclaimer in the documentation and/or other materials provided
14-
* with the distribution.
15+
* (a) the Software, and
1516
*
16-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17-
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19-
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21-
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22-
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24-
* OF THE POSSIBILITY OF SUCH DAMAGE.
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
2540
*/
26-
2741
package com.oracle.graal.python.builtins.objects.method;
2842

2943
import static com.oracle.graal.python.nodes.SpecialMethodNames.__INIT__;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PDecoratedMethod.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
141
package com.oracle.graal.python.builtins.objects.method;
242

343
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
3-
* Copyright (c) 2014, Regents of the University of California
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
5-
* All rights reserved.
5+
* The Universal Permissive License (UPL), Version 1.0
66
*
7-
* Redistribution and use in source and binary forms, with or without modification, are
8-
* permitted provided that the following conditions are met:
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
914
*
10-
* 1. Redistributions of source code must retain the above copyright notice, this list of
11-
* conditions and the following disclaimer.
12-
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13-
* conditions and the following disclaimer in the documentation and/or other materials provided
14-
* with the distribution.
15+
* (a) the Software, and
1516
*
16-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17-
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19-
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21-
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22-
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24-
* OF THE POSSIBILITY OF SUCH DAMAGE.
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
2540
*/
26-
2741
package com.oracle.graal.python.builtins.objects.method;
2842

2943
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GET__;

0 commit comments

Comments
 (0)