Skip to content

Commit e8f8810

Browse files
committed
emulation: IsSequenceNode
1 parent 48f382a commit e8f8810

File tree

4 files changed

+48
-32
lines changed

4 files changed

+48
-32
lines changed

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,19 @@
3838
*/
3939
package com.oracle.graal.python.nodes.datamodel;
4040

41+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
42+
4143
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4244
import com.oracle.graal.python.builtins.objects.function.PFunction;
4345
import com.oracle.graal.python.builtins.objects.function.PythonCallable;
4446
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4547
import com.oracle.graal.python.builtins.objects.method.PMethod;
46-
import com.oracle.graal.python.nodes.PBaseNode;
47-
import com.oracle.graal.python.nodes.PGuards;
48-
import com.oracle.graal.python.nodes.SpecialMethodNames;
4948
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
50-
import com.oracle.graal.python.nodes.truffle.PythonTypes;
51-
import com.oracle.truffle.api.dsl.ImportStatic;
5249
import com.oracle.truffle.api.dsl.Specialization;
53-
import com.oracle.truffle.api.dsl.TypeSystemReference;
5450

55-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
56-
57-
@TypeSystemReference(PythonTypes.class)
58-
@ImportStatic({PGuards.class, SpecialMethodNames.class})
59-
public abstract class IsCallableNode extends PBaseNode {
51+
public abstract class IsCallableNode extends PDataModelEmulationNode {
6052
@Child private LookupInheritedAttributeNode callAttrGetterNode = LookupInheritedAttributeNode.create();
6153

62-
public abstract boolean execute(Object callableObject);
63-
6454
protected static boolean isNoCallable(Object callee) {
6555
return !(callee instanceof PythonCallable);
6656
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.oracle.graal.python.nodes.datamodel;
2+
3+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
4+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__LEN__;
5+
6+
import com.oracle.graal.python.builtins.objects.PNone;
7+
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
8+
import com.oracle.truffle.api.dsl.Specialization;
9+
import com.oracle.truffle.api.profiles.ConditionProfile;
10+
11+
public abstract class IsSequenceNode extends PDataModelEmulationNode {
12+
@Child private LookupInheritedAttributeNode getGetItemNode = LookupInheritedAttributeNode.create();
13+
@Child private LookupInheritedAttributeNode getLenNode = LookupInheritedAttributeNode.create();
14+
private final ConditionProfile lenProfile = ConditionProfile.createBinaryProfile();
15+
private final ConditionProfile getItemProfile = ConditionProfile.createBinaryProfile();
16+
17+
@Specialization
18+
public boolean isSequence(Object object) {
19+
Object len = getLenNode.execute(object, __LEN__);
20+
if (lenProfile.profile(len != PNone.NO_VALUE)) {
21+
return getItemProfile.profile(getGetItemNode.execute(object, __GETITEM__) != PNone.NO_VALUE);
22+
}
23+
return false;
24+
}
25+
26+
public static IsSequenceNode create() {
27+
return IsSequenceNodeGen.create();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.oracle.graal.python.nodes.datamodel;
2+
3+
import com.oracle.graal.python.nodes.PBaseNode;
4+
import com.oracle.graal.python.nodes.PGuards;
5+
import com.oracle.graal.python.nodes.SpecialMethodNames;
6+
import com.oracle.truffle.api.dsl.ImportStatic;
7+
8+
@ImportStatic({PGuards.class, SpecialMethodNames.class})
9+
public abstract class PDataModelEmulationNode extends PBaseNode {
10+
public abstract boolean execute(Object object);
11+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonMessageResolution.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.oracle.graal.python.nodes.attributes.SetAttributeNode;
6262
import com.oracle.graal.python.nodes.call.CallDispatchNode;
6363
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
64+
import com.oracle.graal.python.nodes.datamodel.IsSequenceNode;
6465
import com.oracle.graal.python.nodes.expression.CastToListNode;
6566
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
6667
import com.oracle.graal.python.nodes.interop.PTypeToForeignNode;
@@ -88,21 +89,6 @@
8889

8990
@MessageResolution(receiverType = PythonObject.class)
9091
public class PythonMessageResolution {
91-
private static final class IsSequence extends Node {
92-
@Child private LookupInheritedAttributeNode getGetItemNode = LookupInheritedAttributeNode.create();
93-
@Child private LookupInheritedAttributeNode getLenNode = LookupInheritedAttributeNode.create();
94-
final ConditionProfile lenProfile = ConditionProfile.createBinaryProfile();
95-
final ConditionProfile getItemProfile = ConditionProfile.createBinaryProfile();
96-
97-
public boolean execute(Object object) {
98-
Object len = getLenNode.execute(object, SpecialMethodNames.__LEN__);
99-
if (lenProfile.profile(len != PNone.NO_VALUE)) {
100-
return getItemProfile.profile(getGetItemNode.execute(object, SpecialMethodNames.__GETITEM__) != PNone.NO_VALUE);
101-
}
102-
return false;
103-
}
104-
}
105-
10692
private static final class HasSetItem extends Node {
10793
@Child private LookupInheritedAttributeNode getSetItemNode = LookupInheritedAttributeNode.create();
10894
final ConditionProfile profile = ConditionProfile.createBinaryProfile();
@@ -122,7 +108,7 @@ public boolean execute(Object object) {
122108
}
123109

124110
private static final class IsImmutable extends Node {
125-
@Child private IsSequence isSequence = new IsSequence();
111+
@Child private IsSequenceNode isSequence = IsSequenceNode.create();
126112
@Child private HasSetItem hasSetItem = new HasSetItem();
127113
final ConditionProfile builtinProfile = ConditionProfile.createBinaryProfile();
128114

@@ -138,7 +124,7 @@ private static final class IsMapping extends Node {
138124
@Child private LookupInheritedAttributeNode getKeysNode = LookupInheritedAttributeNode.create();
139125
@Child private LookupInheritedAttributeNode getItemsNode = LookupInheritedAttributeNode.create();
140126
@Child private LookupInheritedAttributeNode getValuesNode = LookupInheritedAttributeNode.create();
141-
@Child private IsSequence isSequence = new IsSequence();
127+
@Child private IsSequenceNode isSequence = IsSequenceNode.create();
142128
final ConditionProfile profile = ConditionProfile.createBinaryProfile();
143129

144130
public boolean execute(Object object) {
@@ -184,7 +170,7 @@ private static final class KeyForItemAccess extends KeyForForcedAccess {
184170
private static final class ReadNode extends Node {
185171
private static final Object NONEXISTING_IDENTIFIER = new Object();
186172

187-
@Child private IsSequence isSequence = new IsSequence();
173+
@Child private IsSequenceNode isSequence = IsSequenceNode.create();
188174
@Child private GetAttributeNode readNode = GetAttributeNode.create();
189175
@Child private GetItemNode getItemNode = GetItemNode.create();
190176
@Child private KeyForAttributeAccess getAttributeKey = new KeyForAttributeAccess();
@@ -480,7 +466,7 @@ public Object access(Object object) {
480466

481467
@Resolve(message = "GET_SIZE")
482468
abstract static class PForeignGetSizeNode extends Node {
483-
@Child IsSequence isSeq = new IsSequence();
469+
@Child IsSequenceNode isSeq = IsSequenceNode.create();
484470
@Child private BuiltinFunctions.LenNode lenNode = BuiltinFunctionsFactory.LenNodeFactory.create(null);
485471

486472
public Object access(Object object) {

0 commit comments

Comments
 (0)