Skip to content

Commit caad996

Browse files
committed
intrinsified base_exception
1 parent 1873128 commit caad996

File tree

5 files changed

+103
-63
lines changed

5 files changed

+103
-63
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ private static String[] initializeCoreFiles() {
304304
"_weakref",
305305
"itertools",
306306
"faulthandler",
307-
"base_exception",
308307
PythonCextBuiltins.PYTHON_CEXT,
309308
"bytes",
310309
"bytearray",

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,12 @@ public final Shape getInstanceShape(PythonLanguage lang) {
511511
SpecialMethodSlot[] reprAndNew = new SpecialMethodSlot[]{SpecialMethodSlot.Repr, SpecialMethodSlot.New};
512512

513513
Boolean.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.And};
514-
PBaseException.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str, SpecialMethodSlot.Repr};
515514
PythonModule.redefinedSlots = Super.redefinedSlots = repr;
515+
SyntaxError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
516+
UnicodeEncodeError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
517+
UnicodeDecodeError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
518+
UnicodeTranslateError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
519+
OSError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
516520

517521
// These slots actually contain context independent values, but they are initialized in
518522
// StructSequence to artificial PBuiltinFunctions with artificial builtin node factories,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@
4747
import com.oracle.graal.python.builtins.objects.list.PList;
4848
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
4949
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
50+
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins.GetItemNode;
51+
import com.oracle.graal.python.lib.PyObjectGetAttr;
52+
import com.oracle.graal.python.lib.PyObjectReprAsObjectNode;
53+
import com.oracle.graal.python.lib.PyObjectStrAsObjectNode;
5054
import com.oracle.graal.python.nodes.ErrorMessages;
5155
import com.oracle.graal.python.nodes.PGuards;
5256
import com.oracle.graal.python.nodes.PRaiseNode;
57+
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
58+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
59+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__;
5360
import com.oracle.graal.python.nodes.argument.ReadArgumentNode;
5461
import com.oracle.graal.python.nodes.expression.CastToListExpressionNode.CastToListNode;
5562
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -61,8 +68,10 @@
6168
import com.oracle.graal.python.nodes.object.SetDictNode;
6269
import com.oracle.graal.python.nodes.util.CannotCastException;
6370
import com.oracle.graal.python.nodes.util.CastToJavaBooleanNode;
71+
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
6472
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6573
import com.oracle.graal.python.runtime.formatting.ErrorMessageFormatter;
74+
import com.oracle.graal.python.util.PythonUtils;
6675
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6776
import com.oracle.truffle.api.dsl.Cached;
6877
import com.oracle.truffle.api.dsl.Fallback;
@@ -318,4 +327,92 @@ Object reduce(VirtualFrame frame, PBaseException self,
318327
return factory().createTuple(new Object[]{clazz, args, dict});
319328
}
320329
}
330+
331+
@Builtin(name = __REPR__, minNumOfPositionalArgs = 1)
332+
@GenerateNodeFactory
333+
public abstract static class ReprNode extends PythonUnaryBuiltinNode {
334+
@Specialization(guards = "argsLen(frame, self, lenNode, argsNode) == 0")
335+
Object reprNoArgs(@SuppressWarnings("unused") VirtualFrame frame, PBaseException self,
336+
@SuppressWarnings("unused") @Cached SequenceStorageNodes.LenNode lenNode,
337+
@SuppressWarnings("unused") @Cached ArgsNode argsNode,
338+
@Cached GetClassNode getClassNode,
339+
@Cached PyObjectGetAttr getAttrNode,
340+
@Cached CastToJavaStringNode castStringNode) {
341+
Object type = getClassNode.execute(self);
342+
StringBuilder sb = new StringBuilder();
343+
PythonUtils.append(sb, castStringNode.execute(getAttrNode.execute(frame, type, __NAME__)));
344+
PythonUtils.append(sb, "()");
345+
return PythonUtils.sbToString(sb);
346+
}
347+
348+
@Specialization(guards = "argsLen(frame, self, lenNode, argsNode) == 1")
349+
Object reprArgs1(VirtualFrame frame, PBaseException self,
350+
@SuppressWarnings("unused") @Cached SequenceStorageNodes.LenNode lenNode,
351+
@SuppressWarnings("unused") @Cached ArgsNode argsNode,
352+
@Cached GetClassNode getClassNode,
353+
@Cached PyObjectGetAttr getAttrNode,
354+
@Cached GetItemNode getItemNode,
355+
@Cached PyObjectReprAsObjectNode reprNode,
356+
@Cached CastToJavaStringNode castStringNode) {
357+
Object type = getClassNode.execute(self);
358+
StringBuilder sb = new StringBuilder();
359+
PythonUtils.append(sb, castStringNode.execute(getAttrNode.execute(frame, type, __NAME__)));
360+
PythonUtils.append(sb, "(");
361+
PythonUtils.append(sb, (String) reprNode.execute(frame, getItemNode.execute(frame, self.getArgs(), 0)));
362+
PythonUtils.append(sb, ")");
363+
return PythonUtils.sbToString(sb);
364+
}
365+
366+
@Specialization(guards = "argsLen(frame, self, lenNode, argsNode) > 1")
367+
Object reprArgs(VirtualFrame frame, PBaseException self,
368+
@SuppressWarnings("unused") @Cached SequenceStorageNodes.LenNode lenNode,
369+
@SuppressWarnings("unused") @Cached ArgsNode argsNode,
370+
@Cached GetClassNode getClassNode,
371+
@Cached PyObjectGetAttr getAttrNode,
372+
@Cached com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins.ReprNode reprNode,
373+
@Cached CastToJavaStringNode castStringNode) {
374+
Object type = getClassNode.execute(self);
375+
StringBuilder sb = new StringBuilder();
376+
PythonUtils.append(sb, castStringNode.execute(getAttrNode.execute(frame, type, __NAME__)));
377+
PythonUtils.append(sb, (String) reprNode.execute(frame, self.getArgs()));
378+
return PythonUtils.sbToString(sb);
379+
}
380+
381+
protected int argsLen(VirtualFrame frame, PBaseException self, SequenceStorageNodes.LenNode lenNode, ArgsNode argsNode) {
382+
return lenNode.execute(((PTuple) argsNode.executeObject(frame, self, PNone.NO_VALUE)).getSequenceStorage());
383+
}
384+
}
385+
386+
@Builtin(name = __STR__, minNumOfPositionalArgs = 1)
387+
@GenerateNodeFactory
388+
public abstract static class StrNode extends PythonUnaryBuiltinNode {
389+
@SuppressWarnings("unused")
390+
@Specialization(guards = "argsLen(frame, self, lenNode, argsNode) == 0")
391+
Object strNoArgs(VirtualFrame frame, PBaseException self,
392+
@Cached SequenceStorageNodes.LenNode lenNode,
393+
@Cached ArgsNode argsNode) {
394+
return PythonUtils.EMPTY_STRING;
395+
}
396+
397+
@Specialization(guards = "argsLen(frame, self, lenNode, argsNode) == 1")
398+
Object strArgs1(VirtualFrame frame, PBaseException self,
399+
@SuppressWarnings("unused") @Cached SequenceStorageNodes.LenNode lenNode,
400+
@SuppressWarnings("unused") @Cached ArgsNode argsNode,
401+
@Cached GetItemNode getItemNode,
402+
@Cached PyObjectStrAsObjectNode strNode) {
403+
return strNode.execute(frame, getItemNode.execute(frame, self.getArgs(), 0));
404+
}
405+
406+
@Specialization(guards = {"argsLen(frame, self, lenNode, argsNode) > 1"})
407+
Object strArgs(VirtualFrame frame, PBaseException self,
408+
@SuppressWarnings("unused") @Cached SequenceStorageNodes.LenNode lenNode,
409+
@SuppressWarnings("unused") @Cached ArgsNode argsNode,
410+
@Cached PyObjectStrAsObjectNode strNode) {
411+
return strNode.execute(frame, self.getArgs());
412+
}
413+
414+
protected int argsLen(VirtualFrame frame, PBaseException self, SequenceStorageNodes.LenNode lenNode, ArgsNode argsNode) {
415+
return lenNode.execute(((PTuple) argsNode.executeObject(frame, self, PNone.NO_VALUE)).getSequenceStorage());
416+
}
417+
}
321418
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public int doNative(PythonNativeObject self,
194194

195195
@Builtin(name = __REPR__, minNumOfPositionalArgs = 1)
196196
@GenerateNodeFactory
197-
abstract static class ReprNode extends PythonUnaryBuiltinNode {
197+
public abstract static class ReprNode extends PythonUnaryBuiltinNode {
198198

199199
public static String toString(VirtualFrame frame, Object item, PyObjectReprAsJavaStringNode reprNode) {
200200
if (item != null) {

graalpython/lib-graalpython/base_exception.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)