|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.objects.exception;
|
42 | 42 |
|
| 43 | +import com.oracle.graal.python.builtins.objects.PNone; |
43 | 44 | import com.oracle.graal.python.builtins.objects.frame.PFrame;
|
44 | 45 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
45 | 46 | import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
|
46 | 47 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
47 | 48 | import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
|
48 | 49 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
|
| 50 | +import com.oracle.graal.python.nodes.PRaiseNode; |
49 | 51 | import com.oracle.graal.python.nodes.object.GetLazyClassNode;
|
50 | 52 | import com.oracle.graal.python.nodes.statement.ExceptNode;
|
51 | 53 | import com.oracle.graal.python.runtime.exception.PException;
|
|
54 | 56 | import com.oracle.graal.python.runtime.sequence.storage.BasicSequenceStorage;
|
55 | 57 | import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
|
56 | 58 | import com.oracle.truffle.api.CompilerAsserts;
|
| 59 | +import com.oracle.truffle.api.dsl.Cached; |
| 60 | +import com.oracle.truffle.api.library.ExportMessage; |
| 61 | +import com.oracle.truffle.api.profiles.ConditionProfile; |
57 | 62 |
|
58 | 63 | public final class PBaseException extends PythonObject {
|
59 |
| - |
| 64 | + private static final Object[] EMPTY_ARGS = new Object[0]; |
60 | 65 | private static final ErrorMessageFormatter FORMATTER = new ErrorMessageFormatter();
|
61 | 66 |
|
62 | 67 | private PTuple args; // can be null for lazily generated message
|
@@ -225,4 +230,30 @@ public void reifyException(PFrame.Reference curFrameInfo) {
|
225 | 230 | // TODO: frames: provide legacy stack walk method via Python option
|
226 | 231 | // TruffleStackTrace.fillIn(exception);
|
227 | 232 | }
|
| 233 | + |
| 234 | + @ExportMessage |
| 235 | + @SuppressWarnings("static-method") |
| 236 | + boolean isException() { |
| 237 | + return true; |
| 238 | + } |
| 239 | + |
| 240 | + @ExportMessage |
| 241 | + RuntimeException throwException(@Cached("createBinaryProfile()") ConditionProfile hasExc, |
| 242 | + @Cached GetLazyClassNode getClass, |
| 243 | + @Cached PRaiseNode raiseNode) { |
| 244 | + PException exc = getException(); |
| 245 | + if (hasExc.profile(exc != null)) { |
| 246 | + throw exc; |
| 247 | + } else { |
| 248 | + Object[] newArgs = messageArgs; |
| 249 | + if (newArgs == null) { |
| 250 | + newArgs = EMPTY_ARGS; |
| 251 | + } |
| 252 | + Object format = messageFormat; |
| 253 | + if (format == null) { |
| 254 | + format = PNone.NO_VALUE; |
| 255 | + } |
| 256 | + throw raiseNode.execute(getClass.execute(this), this, format, newArgs); |
| 257 | + } |
| 258 | + } |
228 | 259 | }
|
0 commit comments