|
25 | 25 | */
|
26 | 26 | package com.oracle.graal.python.builtins.objects.traceback;
|
27 | 27 |
|
| 28 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; |
28 | 29 | import static com.oracle.graal.python.builtins.objects.traceback.PTraceback.TB_FRAME;
|
29 | 30 | import static com.oracle.graal.python.builtins.objects.traceback.PTraceback.TB_LASTI;
|
30 | 31 | import static com.oracle.graal.python.builtins.objects.traceback.PTraceback.TB_LINENO;
|
|
45 | 46 | import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode;
|
46 | 47 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
47 | 48 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
| 49 | +import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode; |
48 | 50 | import com.oracle.graal.python.runtime.exception.PException;
|
49 | 51 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
50 | 52 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
@@ -257,14 +259,39 @@ protected static boolean isMaterialized(PFrame.Reference frameInfo) {
|
257 | 259 | }
|
258 | 260 | }
|
259 | 261 |
|
260 |
| - @Builtin(name = TB_NEXT, minNumOfPositionalArgs = 1, isGetter = true) |
| 262 | + @Builtin(name = TB_NEXT, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true) |
261 | 263 | @GenerateNodeFactory
|
262 |
| - public abstract static class GetTracebackNextNode extends PythonBuiltinNode { |
263 |
| - @Specialization |
264 |
| - Object get(PTraceback tb, |
| 264 | + public abstract static class GetTracebackNextNode extends PythonBinaryBuiltinNode { |
| 265 | + @Specialization(guards = "isNoValue(none)") |
| 266 | + Object get(PTraceback self, @SuppressWarnings("unused") PNone none, |
265 | 267 | @Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode) {
|
266 |
| - materializeTruffleStacktraceNode.execute(tb); |
267 |
| - return (tb.getNext() != null) ? tb.getNext() : PNone.NONE; |
| 268 | + materializeTruffleStacktraceNode.execute(self); |
| 269 | + return (self.getNext() != null) ? self.getNext() : PNone.NONE; |
| 270 | + } |
| 271 | + |
| 272 | + @Specialization(guards = "!isNoValue(next)") |
| 273 | + Object set(PTraceback self, PTraceback next, |
| 274 | + @Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode) { |
| 275 | + // Realize whatever was in the truffle stacktrace, so that we don't overwrite the |
| 276 | + // user-set next later |
| 277 | + materializeTruffleStacktraceNode.execute(self); |
| 278 | + self.setNext(next); |
| 279 | + return PNone.NONE; |
| 280 | + } |
| 281 | + |
| 282 | + @Specialization(guards = "isNone(next)") |
| 283 | + Object clear(PTraceback self, @SuppressWarnings("unused") PNone next, |
| 284 | + @Cached MaterializeTruffleStacktraceNode materializeTruffleStacktraceNode) { |
| 285 | + // Realize whatever was in the truffle stacktrace, so that we don't overwrite the |
| 286 | + // user-set next later |
| 287 | + materializeTruffleStacktraceNode.execute(self); |
| 288 | + self.setNext(null); |
| 289 | + return PNone.NONE; |
| 290 | + } |
| 291 | + |
| 292 | + @Specialization(guards = {"!isPNone(next)", "!isPTraceback(next)"}) |
| 293 | + Object setError(@SuppressWarnings("unused") PTraceback self, Object next) { |
| 294 | + throw raise(TypeError, "expected traceback object, got '%p'", next); |
268 | 295 | }
|
269 | 296 | }
|
270 | 297 |
|
|
0 commit comments