Skip to content

Commit 60b0938

Browse files
committed
Fix: delegate to 'ObjectBuiltins.StrNode/ReprNode' if not boxed.
1 parent bb22528 commit 60b0938

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import com.oracle.graal.python.builtins.objects.PNotImplemented;
6868
import com.oracle.graal.python.builtins.objects.function.PKeyword;
6969
import com.oracle.graal.python.builtins.objects.list.PList;
70+
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
71+
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
7072
import com.oracle.graal.python.nodes.PGuards;
7173
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
7274
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
@@ -931,6 +933,7 @@ protected Object doIt(TruffleObject object) {
931933
@GenerateNodeFactory
932934
abstract static class StrNode extends UnboxNode {
933935
@Child private LookupAndCallUnaryNode callStrNode;
936+
@Child private ObjectBuiltins.StrNode objectStrNode;
934937

935938
@Specialization(guards = "isForeignObject(object)")
936939
protected Object doIt(TruffleObject object) {
@@ -941,7 +944,7 @@ protected Object doIt(TruffleObject object) {
941944
throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message");
942945
}
943946
}
944-
throw raise(PythonErrorType.AttributeError);
947+
return getObjectStrNode().execute(object);
945948
}
946949

947950
private LookupAndCallUnaryNode getCallStrNode() {
@@ -951,12 +954,21 @@ private LookupAndCallUnaryNode getCallStrNode() {
951954
}
952955
return callStrNode;
953956
}
957+
958+
private ObjectBuiltins.StrNode getObjectStrNode() {
959+
if (objectStrNode == null) {
960+
CompilerDirectives.transferToInterpreterAndInvalidate();
961+
objectStrNode = insert(ObjectBuiltinsFactory.StrNodeFactory.create());
962+
}
963+
return objectStrNode;
964+
}
954965
}
955966

956967
@Builtin(name = __REPR__, fixedNumOfArguments = 1)
957968
@GenerateNodeFactory
958969
abstract static class ReprNode extends UnboxNode {
959970
@Child private LookupAndCallUnaryNode callReprNode;
971+
@Child private ObjectBuiltins.ReprNode objectReprNode;
960972

961973
@Specialization(guards = "isForeignObject(object)")
962974
protected Object doIt(TruffleObject object) {
@@ -967,7 +979,7 @@ protected Object doIt(TruffleObject object) {
967979
throw new IllegalStateException("The object '%s' claims to be boxed, but does not support the UNBOX message");
968980
}
969981
}
970-
throw raise(PythonErrorType.AttributeError);
982+
return getObjectReprNode().execute(object);
971983
}
972984

973985
private LookupAndCallUnaryNode getCallReprNode() {
@@ -977,5 +989,13 @@ private LookupAndCallUnaryNode getCallReprNode() {
977989
}
978990
return callReprNode;
979991
}
992+
993+
private ObjectBuiltins.ReprNode getObjectReprNode() {
994+
if (objectReprNode == null) {
995+
CompilerDirectives.transferToInterpreterAndInvalidate();
996+
objectReprNode = insert(ObjectBuiltinsFactory.ReprNodeFactory.create());
997+
}
998+
return objectReprNode;
999+
}
9801000
}
9811001
}

0 commit comments

Comments
 (0)