Skip to content

Commit 35883a3

Browse files
committed
simplify code in foreign object str representations
1 parent 6f82cd9 commit 35883a3

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

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

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import com.oracle.graal.python.builtins.objects.function.PKeyword;
7373
import com.oracle.graal.python.builtins.objects.iterator.PForeignArrayIterator;
7474
import com.oracle.graal.python.builtins.objects.list.PList;
75-
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
7675
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
7776
import com.oracle.graal.python.nodes.PGuards;
7877
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
@@ -958,8 +957,9 @@ protected Object doIt(TruffleObject object) {
958957
@Builtin(name = __STR__, fixedNumOfPositionalArgs = 1)
959958
@GenerateNodeFactory
960959
abstract static class StrNode extends UnboxNode {
960+
protected final String method = __STR__;
961961
@Child private LookupAndCallUnaryNode callStrNode;
962-
@Child private ObjectBuiltins.StrNode objectStrNode;
962+
@Child protected PythonUnaryBuiltinNode objectStrNode;
963963
@Child private Node getSizeNode;
964964
@Child private Node readNode;
965965

@@ -996,12 +996,12 @@ protected Object doIt(Object object) {
996996
private LookupAndCallUnaryNode getCallStrNode() {
997997
if (callStrNode == null) {
998998
CompilerDirectives.transferToInterpreterAndInvalidate();
999-
callStrNode = insert(LookupAndCallUnaryNode.create(__STR__));
999+
callStrNode = insert(LookupAndCallUnaryNode.create(method));
10001000
}
10011001
return callStrNode;
10021002
}
10031003

1004-
private ObjectBuiltins.StrNode getObjectStrNode() {
1004+
protected PythonUnaryBuiltinNode getObjectStrNode() {
10051005
if (objectStrNode == null) {
10061006
CompilerDirectives.transferToInterpreterAndInvalidate();
10071007
objectStrNode = insert(ObjectBuiltinsFactory.StrNodeFactory.create());
@@ -1012,36 +1012,16 @@ private ObjectBuiltins.StrNode getObjectStrNode() {
10121012

10131013
@Builtin(name = __REPR__, fixedNumOfPositionalArgs = 1)
10141014
@GenerateNodeFactory
1015-
abstract static class ReprNode extends UnboxNode {
1016-
@Child private LookupAndCallUnaryNode callReprNode;
1017-
@Child private ObjectBuiltins.ReprNode objectReprNode;
1015+
abstract static class ReprNode extends StrNode {
1016+
protected final String method = __REPR__;
10181017

1019-
@Specialization(guards = "isForeignObject(object)")
1020-
protected Object doIt(TruffleObject object) {
1021-
if (isBoxed(object)) {
1022-
try {
1023-
return getCallReprNode().executeObject(unboxLeft(object));
1024-
} catch (UnsupportedMessageException e) {
1025-
throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message");
1026-
}
1027-
}
1028-
return getObjectReprNode().execute(object);
1029-
}
1030-
1031-
private LookupAndCallUnaryNode getCallReprNode() {
1032-
if (callReprNode == null) {
1033-
CompilerDirectives.transferToInterpreterAndInvalidate();
1034-
callReprNode = insert(LookupAndCallUnaryNode.create(__REPR__));
1035-
}
1036-
return callReprNode;
1037-
}
1038-
1039-
private ObjectBuiltins.ReprNode getObjectReprNode() {
1040-
if (objectReprNode == null) {
1018+
@Override
1019+
protected PythonUnaryBuiltinNode getObjectStrNode() {
1020+
if (objectStrNode == null) {
10411021
CompilerDirectives.transferToInterpreterAndInvalidate();
1042-
objectReprNode = insert(ObjectBuiltinsFactory.ReprNodeFactory.create());
1022+
objectStrNode = insert(ObjectBuiltinsFactory.ReprNodeFactory.create());
10431023
}
1044-
return objectReprNode;
1024+
return objectStrNode;
10451025
}
10461026
}
10471027
}

0 commit comments

Comments
 (0)