from chart import Chart, Term, _repr
from defn import aggregator
from utils import ip, red, green, blue, magenta, yellow, \
- notimplemented, parse_attrs, ddict, dynac, \
+ notimplemented, parse_attrs, ddict, dynac, enable_crash_handler, \
DynaCompilerError, DynaInitializerException
from prioritydict import prioritydict
from config import dotdynadir, dynahome
interp = Interpreter()
+ enable_crash_handler()
+
+
if args.profile:
# When profiling, its common practice to disable the garbage collector.
import gc
-import os
-import cmd, readline
-import interpreter
-from utils import blue, yellow, green, magenta, ip, DynaCompilerError, DynaInitializerException
+import os, cmd, readline
+
+import debug, interpreter
+from utils import DynaCompilerError, DynaInitializerException, ip, crash_handler
from chart import _repr
from config import dotdynadir
-import debug
class REPL(cmd.Cmd, object):
try:
super(REPL, self).cmdloop()
except KeyboardInterrupt:
+ # Catch Control-C and resume REPL.
print '^C'
- self.cmdloop()
- except Exception as e:
+ self.cmdloop()
+ except:
+ # report uncatch exception.
+ crash_handler()
+ finally:
readline.write_history_file(self.hist)
- raise e
-import re
+import re, sys
from subprocess import Popen, PIPE
from IPython.frontend.terminal.embed import InteractiveShellEmbed
-from config import dynahome
+from IPython.core.ultratb import VerboseTB
+from config import dynahome, dotdynadir
# interactive IPython shell
raise DynaCompilerError(stderr)
+def crash_handler():
+ exception_handler(*sys.exc_info())
+
+
+def exception_handler(etype, evalue, tb):
+
+ # once for the log file.
+ with file(dotdynadir / 'crash.log', 'wb') as crashreport:
+ h = VerboseTB(color_scheme='Linux', call_pdb=False,
+ ostream=crashreport,
+ long_header=True, include_vars=True,
+ check_cache=None)
+ h(etype, evalue, tb)
+
+ # once for the user
+ h = VerboseTB(color_scheme='Linux', call_pdb=False, ostream=None,
+ tb_offset=0, long_header=False, include_vars=True,
+ check_cache=None)
+ h(etype, evalue, tb)
+
+ # TODO: we should package up all relevant state including compiler
+ # version, codegen output, interpreter state (possibly without the
+ # chart -- because it might be too big to email); input to repl.
+ # This should all go into a tarball.
+
+ print 'FATAL ERROR (%s): %s' % (etype.__name__, evalue)
+ print 'Please report this error by emailing bugs@dyna.org. ' \
+ 'Please attach the following file %s' % crashreport.name
+
+
+def enable_crash_handler():
+ """
+ Use our custom exception handler for handling uncaught exceptions.
+ """
+ sys.excepthook = exception_handler
+
+
def notimplemented(*_,**__):
raise NotImplementedError
btree = t(x)
assert check_binary(btree)
- print
+ print
print 'sentence(%s) :=\n%s.' % (i, pretty(btree, 4).rstrip())
print