comparison 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
comparison
equal deleted inserted replaced
39:e5bcb1eeafc1 40:e3624b7cd603
1 package luan.interp; 1 package luan.interp;
2 2
3 import luan.Lua; 3 import luan.Lua;
4 import luan.LuaException; 4 import luan.LuaException;
5 import luan.LuaFunction; 5 import luan.LuaFunction;
6 import luan.LuaSource;
6 7
7 8
8 final class ReturnStmt implements Stmt { 9 final class ReturnStmt extends CodeImpl implements Stmt {
9 private final Expressions expressions; 10 private final Expressions expressions;
10 private final Expr tailFnExpr; 11 private final Expr tailFnExpr;
11 boolean throwReturnException = true; 12 boolean throwReturnException = true;
12 13
13 ReturnStmt(Expressions expressions) { 14 ReturnStmt(LuaSource.Element se,Expressions expressions) {
15 super(se);
14 if( expressions instanceof FnCall ) { // tail call 16 if( expressions instanceof FnCall ) { // tail call
15 FnCall fnCall = (FnCall)expressions; 17 FnCall fnCall = (FnCall)expressions;
16 this.expressions = fnCall.args; 18 this.expressions = fnCall.args;
17 this.tailFnExpr = fnCall.fnExpr; 19 this.tailFnExpr = fnCall.fnExpr;
18 } else { 20 } else {
22 } 24 }
23 25
24 @Override public void eval(LuaStateImpl lua) throws LuaException { 26 @Override public void eval(LuaStateImpl lua) throws LuaException {
25 lua.returnValues = expressions.eval(lua); 27 lua.returnValues = expressions.eval(lua);
26 if( tailFnExpr != null ) { 28 if( tailFnExpr != null ) {
27 LuaFunction tailFn = Lua.checkFunction( tailFnExpr.eval(lua) ); 29 LuaFunction tailFn = lua.checkFunction( se, tailFnExpr.eval(lua) );
28 if( tailFn instanceof LuaClosure ) { 30 if( tailFn instanceof LuaClosure ) {
29 lua.tailFn = (LuaClosure)tailFn; 31 lua.tailFn = (LuaClosure)tailFn;
30 } else { 32 } else {
31 lua.returnValues = tailFn.call(lua,lua.returnValues); 33 lua.returnValues = lua.call(tailFn,tailFnExpr.se(),tailFnExpr.se().text(),lua.returnValues);
32 } 34 }
33 } 35 }
34 if( throwReturnException ) 36 if( throwReturnException )
35 throw new ReturnException(); 37 throw new ReturnException();
36 } 38 }