Mercurial Hosting > luan
view src/luan/interp/ReturnStmt.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 5cf15507d77e |
children | 64ecb7a3aad7 |
line wrap: on
line source
package luan.interp; import luan.Lua; import luan.LuaException; import luan.LuaFunction; import luan.LuaSource; final class ReturnStmt extends CodeImpl implements Stmt { private final Expressions expressions; private final Expr tailFnExpr; boolean throwReturnException = true; ReturnStmt(LuaSource.Element se,Expressions expressions) { super(se); if( expressions instanceof FnCall ) { // tail call FnCall fnCall = (FnCall)expressions; this.expressions = fnCall.args; this.tailFnExpr = fnCall.fnExpr; } else { this.expressions = expressions; this.tailFnExpr = null; } } @Override public void eval(LuaStateImpl lua) throws LuaException { lua.returnValues = expressions.eval(lua); if( tailFnExpr != null ) { LuaFunction tailFn = lua.checkFunction( se, tailFnExpr.eval(lua) ); if( tailFn instanceof LuaClosure ) { lua.tailFn = (LuaClosure)tailFn; } else { lua.returnValues = lua.call(tailFn,tailFnExpr.se(),tailFnExpr.se().text(),lua.returnValues); } } if( throwReturnException ) throw new ReturnException(); } }