[svn:parrot] r47113 - trunk/compilers/pct/src/PCT
jonathan at svn.parrot.org
jonathan at svn.parrot.org
Sat May 29 17:11:43 UTC 2010
Author: jonathan
Date: Sat May 29 17:11:42 2010
New Revision: 47113
URL: https://trac.parrot.org/parrot/changeset/47113
Log:
[pct] Allow compilers to implement a .backtrace method to produce their own format of backtrace to print in the event of an uncaught exception. If not, we just fall back to Parrot's own handling.
Modified:
trunk/compilers/pct/src/PCT/HLLCompiler.pir
Modified: trunk/compilers/pct/src/PCT/HLLCompiler.pir
==============================================================================
--- trunk/compilers/pct/src/PCT/HLLCompiler.pir Sat May 29 16:42:05 2010 (r47112)
+++ trunk/compilers/pct/src/PCT/HLLCompiler.pir Sat May 29 17:11:42 2010 (r47113)
@@ -849,11 +849,15 @@
$I0 = adverbs['version']
if $I0 goto version
+ .local int can_backtrace
+ can_backtrace = can self, 'backtrace'
+ unless can_backtrace goto no_push_eh
+ push_eh uncaught_exception
+ no_push_eh:
$S0 = adverbs['e']
$I0 = exists adverbs['e']
if $I0 goto eval_line
-
.local pmc result
result = box ''
unless args goto interactive
@@ -872,6 +876,9 @@
result = self.'eval'($S0, '-e', args :flat, adverbs :flat :named)
save_output:
+ unless can_backtrace goto no_pop_eh
+ pop_eh
+ no_pop_eh:
if null result goto end
$I0 = defined result
unless $I0 goto end
@@ -903,6 +910,16 @@
version:
self.'version'()
goto end
+
+ # If we get an uncaught exception in the program and the HLL provides
+ # a backtrace method, we end up here. We pass it the exception object
+ # so it can render a backtrace.
+ uncaught_exception:
+ .get_results ($P0)
+ pop_eh
+ $S0 = self.'backtrace'($P0)
+ print $S0
+ exit 1
.end
More information about the parrot-commits
mailing list