Mercurial Hosting > luan
changeset 23:2446c1755d9b
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@24 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 06 Dec 2012 00:35:13 +0000 |
parents | 1e37f22a34c8 |
children | 7ee247560db5 |
files | src/luan/interp/Block.java src/luan/interp/Chunk.java src/luan/interp/IfStmt.java |
diffstat | 3 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/interp/Block.java Wed Dec 05 09:03:50 2012 +0000 +++ b/src/luan/interp/Block.java Thu Dec 06 00:35:13 2012 +0000 @@ -10,6 +10,8 @@ private final int stackEnd; Block(Stmt[] stmts,int stackStart,int stackEnd) { + if( stmts.length==0 ) + throw new RuntimeException("empty block"); this.stmts = stmts; this.stackStart = stackStart; this.stackEnd = stackEnd;
--- a/src/luan/interp/Chunk.java Wed Dec 05 09:03:50 2012 +0000 +++ b/src/luan/interp/Chunk.java Thu Dec 06 00:35:13 2012 +0000 @@ -14,16 +14,20 @@ this.block = block; this.stackSize = stackSize; this.numArgs = numArgs; - Stmt stmt = block; - while( stmt instanceof Block ) { - Block b = (Block)stmt; - if( b.stmts.length==0 ) - break; - stmt = b.stmts[b.stmts.length-1]; - } + fixReturns(block); + } + + private static void fixReturns(Stmt stmt) { if( stmt instanceof ReturnStmt ) { ReturnStmt rs = (ReturnStmt)stmt; rs.throwReturnException = false; + } else if( stmt instanceof Block ) { + Block b = (Block)stmt; + fixReturns( b.stmts[b.stmts.length-1] ); + } else if( stmt instanceof IfStmt ) { + IfStmt is = (IfStmt)stmt; + fixReturns( is.thenStmt ); + fixReturns( is.elseStmt ); } }
--- a/src/luan/interp/IfStmt.java Wed Dec 05 09:03:50 2012 +0000 +++ b/src/luan/interp/IfStmt.java Thu Dec 06 00:35:13 2012 +0000 @@ -7,8 +7,8 @@ final class IfStmt implements Stmt { private final Expr cnd; - private final Stmt thenStmt; - private final Stmt elseStmt; + final Stmt thenStmt; + final Stmt elseStmt; IfStmt(Expr cnd,Stmt thenStmt,Stmt elseStmt) { this.cnd = cnd;