Skip to content

Commit eb299a3

Browse files
committed
remove CastToBooleanNode from ForeignObjectBuiltins
1 parent c16ef25 commit eb299a3

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
import com.oracle.graal.python.builtins.objects.ints.PInt;
7676
import com.oracle.graal.python.builtins.objects.iterator.PForeignArrayIterator;
7777
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
78+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
7879
import com.oracle.graal.python.nodes.PRaiseNode;
7980
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
8081
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
8182
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
8283
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
83-
import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
8484
import com.oracle.graal.python.nodes.expression.CastToListExpressionNode.CastToListNode;
8585
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8686
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -120,25 +120,10 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
120120
@Builtin(name = __BOOL__, minNumOfPositionalArgs = 1)
121121
@GenerateNodeFactory
122122
abstract static class BoolNode extends PythonUnaryBuiltinNode {
123-
@Specialization
124-
boolean doForeignObject(VirtualFrame frame, Object self,
125-
@CachedLibrary(limit = "3") InteropLibrary lib,
126-
@Cached("createIfTrueNode()") CastToBooleanNode cast) {
127-
try {
128-
if (lib.isBoolean(self)) {
129-
return lib.asBoolean(self);
130-
} else if (lib.fitsInLong(self)) {
131-
return cast.executeBoolean(frame, lib.asLong(self));
132-
} else if (lib.fitsInDouble(self)) {
133-
return cast.executeBoolean(frame, lib.asDouble(self));
134-
} else if (lib.hasArrayElements(self)) {
135-
return cast.executeBoolean(frame, lib.getArraySize(self));
136-
} else {
137-
return !lib.isNull(self);
138-
}
139-
} catch (UnsupportedMessageException e) {
140-
throw raise(AttributeError, "'foreign' object has no attribute '__bool__'");
141-
}
123+
@Specialization(limit = "1")
124+
boolean doForeignObject(Object self,
125+
@CachedLibrary("self") PythonObjectLibrary lib) {
126+
return lib.isTrue(self);
142127
}
143128
}
144129

0 commit comments

Comments
 (0)