Commits

Shashank Bharadwaj committed 7bf2068

fixing the nullpointer exception\! That was a stupid bug

Comments (0)

Files changed (1)

fix-asm-via-cfg.patch

 # HG changeset patch
-# Parent ae51dbe75e279fd3480e9e01d8132f120db304a5
+# Parent 4b94fb54b57380cbd2aa5a04c31e8705a327fef4
 
 diff --git a/.classpath b/.classpath
 --- a/.classpath
 +
 +/**
 + * A compiler to generate JDK7 complaint bytecode.
-+ * 
++ *
 + * The DefaultCompiler first builds an intermediate representation (IR) (See
 + * {@link IRBuilder}). The IR is a very basic control flow graph (CFG) with
 + * edges between the start and end of a try-catch block. The IR is then passed
 + * to {@link StampTryCatch}, which will convert the edges to nodes and
 + * {@link TryCatchBlock} nodes into the IR. Then the {@link
 + * LegacyCompiler#compile(...)} is called to do the actual byte-code generation.
-+ * 
++ *
 + */
 +public class JDK7Compiler extends LegacyCompiler {
 +
 +/**
 + * Builds an internal representation (IR) of the AST with simple try-catch
 + * blocks.
-+ * 
++ *
 + * This visitor runs through the AST to build a IR. The IR is very similar to
 + * the AST for most nodes, except for {@link TryExcept} and {@link TryFinally}.
 + */
 +
 +    private void startNewExceptionRange() {
 +        if (data.handler == null)
-+            assert false;
++            assert false: data;
 +        ExceptionRangeStart start = new ExceptionRangeStart();
 +        new Edge(start, data.handler);
 +        data.stmts.add(start);
 +
 +    private void endCurrExceptionRange() {
 +        if (data.handler == null)
-+            assert false;
++            assert false: data;
 +        ExceptionRangeStop end = new ExceptionRangeStop();
 +        new Edge(end, data.handler);
 +        data.stmts.add(end);
 +    @Override
 +    public Object visitTryFinally(TryFinally node) throws Exception {
 +        List<stmt> finally_body = node.getInternalFinalbody();
++        FinallyStart finally_handler = new FinallyStart(finally_body);
++
++        List<stmt> body = suite(node.getInternalBody(), finally_handler);
 +        List<stmt> suited_finally = suite(finally_body);
-+        FinallyStart finally_handler = new FinallyStart(finally_body);
-+
-+        List<stmt> body = suite(node.getInternalBody(), finally_handler);
 +        body.addAll(suited_finally);
 +
 +        suited_finally.add(
 new file mode 100644
 --- /dev/null
 +++ b/tmp/test.py
-@@ -0,0 +1,5 @@
-+def foo():
-+    s = compile('print "hi"', 'foo', 'single')
-+    exec s
-+    
-+foo()
-\ No newline at end of file
+@@ -0,0 +1,13 @@
++def genTryExceptAroundFinally():
++    for i in range(3):
++        try:
++            try:
++                1//0
++            finally:
++                yield i
++        except:
++            pass
++
++
++print 'expected:', [0, 1, 2]
++print 'got:     ', list(genTryExceptAroundFinally())