Skip to content

Commit 2f88cc1

Browse files
committed
add isIterable node
- fixed style issues
1 parent 8fb8b72 commit 2f88cc1

File tree

5 files changed

+129
-7
lines changed

5 files changed

+129
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/NodeFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.graal.python.nodes.control.WhileNode;
5454
import com.oracle.graal.python.nodes.datamodel.IsCallableNode;
5555
import com.oracle.graal.python.nodes.datamodel.IsContextManagerNode;
56+
import com.oracle.graal.python.nodes.datamodel.IsIterableNode;
5657
import com.oracle.graal.python.nodes.datamodel.IsMappingNode;
5758
import com.oracle.graal.python.nodes.datamodel.IsSequenceNode;
5859
import com.oracle.graal.python.nodes.datamodel.PDataModelEmulationNode;
@@ -529,4 +530,8 @@ public PDataModelEmulationNode createIsContextManager() {
529530
public PDataModelEmulationNode createIsCallable() {
530531
return IsCallableNode.create();
531532
}
533+
534+
public PDataModelEmulationNode createIsIterable() {
535+
return IsIterableNode.create();
536+
}
532537
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/HasInheritedAttributeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, Oracle and/or its affiliates.
33
*
44
* The Universal Permissive License (UPL), Version 1.0
55
*

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/datamodel/IsCallableNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ protected boolean isSpecialCallable(Object callable) {
6262
}
6363

6464
@Specialization
65-
protected boolean isMethod(PMethod callable) {
65+
protected boolean isMethod(@SuppressWarnings("unused") PMethod callable) {
6666
return true;
6767
}
6868

6969
@Specialization
70-
protected boolean isBuiltinMethod(PBuiltinMethod callable) {
70+
protected boolean isBuiltinMethod(@SuppressWarnings("unused") PBuiltinMethod callable) {
7171
return true;
7272
}
7373

7474
@Specialization
75-
protected boolean isFunctionCall(PFunction callable) {
75+
protected boolean isFunctionCall(@SuppressWarnings("unused") PFunction callable) {
7676
return true;
7777
}
7878

7979
@Specialization
80-
protected boolean isBuiltinFunctionCall(PBuiltinFunction callable) {
80+
protected boolean isBuiltinFunctionCall(@SuppressWarnings("unused") PBuiltinFunction callable) {
8181
return true;
8282
}
8383

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates.
3+
*
4+
* The Universal Permissive License (UPL), Version 1.0
5+
*
6+
* Subject to the condition set forth below, permission is hereby granted to any
7+
* person obtaining a copy of this software, associated documentation and/or data
8+
* (collectively the "Software"), free of charge and under any and all copyright
9+
* rights in the Software, and any and all patent rights owned or freely
10+
* licensable by each licensor hereunder covering either (i) the unmodified
11+
* Software as contributed to or provided by such licensor, or (ii) the Larger
12+
* Works (as defined below), to deal in both
13+
*
14+
* (a) the Software, and
15+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
* one is included with the Software (each a "Larger Work" to which the
17+
* Software is contributed by such licensors),
18+
*
19+
* without restriction, including without limitation the rights to copy, create
20+
* derivative works of, display, perform, and distribute the Software and make,
21+
* use, sell, offer for sale, import, export, have made, and have sold the
22+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
* either these or other terms.
24+
*
25+
* This license is subject to the following condition:
26+
*
27+
* The above copyright notice and either this complete permission notice or at a
28+
* minimum a reference to the UPL must be included in all copies or substantial
29+
* portions of the Software.
30+
*
31+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37+
* SOFTWARE.
38+
*/
39+
package com.oracle.graal.python.nodes.datamodel;
40+
41+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
42+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEXT__;
43+
44+
import com.oracle.graal.python.builtins.objects.PNone;
45+
import com.oracle.graal.python.builtins.objects.array.PCharArray;
46+
import com.oracle.graal.python.builtins.objects.array.PDoubleArray;
47+
import com.oracle.graal.python.builtins.objects.array.PIntArray;
48+
import com.oracle.graal.python.builtins.objects.array.PLongArray;
49+
import com.oracle.graal.python.builtins.objects.iterator.PZip;
50+
import com.oracle.graal.python.builtins.objects.range.PRange;
51+
import com.oracle.graal.python.nodes.attributes.HasInheritedAttributeNode;
52+
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
53+
import com.oracle.graal.python.runtime.sequence.PSequence;
54+
import com.oracle.truffle.api.dsl.Specialization;
55+
import com.oracle.truffle.api.profiles.ConditionProfile;
56+
57+
public abstract class IsIterableNode extends PDataModelEmulationNode {
58+
@Child private HasInheritedAttributeNode hasNextNode = HasInheritedAttributeNode.create(__NEXT__);
59+
@Child private LookupInheritedAttributeNode getIterNode = LookupInheritedAttributeNode.create();
60+
61+
private final ConditionProfile profileIter = ConditionProfile.createBinaryProfile();
62+
private final ConditionProfile profileNext = ConditionProfile.createBinaryProfile();
63+
64+
@Specialization
65+
public boolean isIterable(@SuppressWarnings("unused") PRange range) {
66+
return true;
67+
}
68+
69+
@Specialization
70+
public boolean isIterable(@SuppressWarnings("unused") PIntArray array) {
71+
return true;
72+
}
73+
74+
@Specialization
75+
public boolean isIterable(@SuppressWarnings("unused") PLongArray array) {
76+
return true;
77+
}
78+
79+
@Specialization
80+
public boolean isIterable(@SuppressWarnings("unused") PDoubleArray array) {
81+
return true;
82+
}
83+
84+
@Specialization
85+
public boolean isIterable(@SuppressWarnings("unused") PCharArray array) {
86+
return true;
87+
}
88+
89+
@Specialization
90+
public boolean isIterable(@SuppressWarnings("unused") PSequence sequence) {
91+
return true;
92+
}
93+
94+
@Specialization
95+
public boolean isIterable(@SuppressWarnings("unused") String str) {
96+
return true;
97+
}
98+
99+
@Specialization
100+
public boolean isIterable(@SuppressWarnings("unused") PZip zip) {
101+
return true;
102+
}
103+
104+
@Specialization
105+
public boolean isIterable(Object object) {
106+
Object iterMethod = getIterNode.execute(object, __ITER__);
107+
if (profileIter.profile(iterMethod != PNone.NO_VALUE)) {
108+
return iterMethod != PNone.NONE;
109+
} else {
110+
return profileNext.profile(hasNextNode.execute(object));
111+
}
112+
}
113+
114+
public static IsIterableNode create() {
115+
return IsIterableNodeGen.create();
116+
}
117+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/datamodel/IsMappingNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public abstract class IsMappingNode extends PDataModelEmulationNode {
5858
public boolean isMapping(Object object) {
5959
if (isSequence.execute(object)) {
6060
return profile.profile((hasKeysNode.execute(object)) &&
61-
(hasItemsNode.execute(object)) &&
62-
(hasValuesNode.execute(object)));
61+
(hasItemsNode.execute(object)) &&
62+
(hasValuesNode.execute(object)));
6363
}
6464
return false;
6565
}

0 commit comments

Comments
 (0)