Mercurial Hosting > luan
comparison src/luan/interp/ReturnStmt.java @ 48:64ecb7a3aad7
rename Lua to Luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@49 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 03:29:12 +0000 |
parents | e3624b7cd603 |
children | 8ede219cd111 |
comparison
equal
deleted
inserted
replaced
47:659c7139e903 | 48:64ecb7a3aad7 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.Lua; | 3 import luan.Luan; |
4 import luan.LuaException; | 4 import luan.LuanException; |
5 import luan.LuaFunction; | 5 import luan.LuanFunction; |
6 import luan.LuaSource; | 6 import luan.LuanSource; |
7 | 7 |
8 | 8 |
9 final class ReturnStmt extends CodeImpl implements Stmt { | 9 final class ReturnStmt extends CodeImpl implements Stmt { |
10 private final Expressions expressions; | 10 private final Expressions expressions; |
11 private final Expr tailFnExpr; | 11 private final Expr tailFnExpr; |
12 boolean throwReturnException = true; | 12 boolean throwReturnException = true; |
13 | 13 |
14 ReturnStmt(LuaSource.Element se,Expressions expressions) { | 14 ReturnStmt(LuanSource.Element se,Expressions expressions) { |
15 super(se); | 15 super(se); |
16 if( expressions instanceof FnCall ) { // tail call | 16 if( expressions instanceof FnCall ) { // tail call |
17 FnCall fnCall = (FnCall)expressions; | 17 FnCall fnCall = (FnCall)expressions; |
18 this.expressions = fnCall.args; | 18 this.expressions = fnCall.args; |
19 this.tailFnExpr = fnCall.fnExpr; | 19 this.tailFnExpr = fnCall.fnExpr; |
21 this.expressions = expressions; | 21 this.expressions = expressions; |
22 this.tailFnExpr = null; | 22 this.tailFnExpr = null; |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 @Override public void eval(LuaStateImpl lua) throws LuaException { | 26 @Override public void eval(LuanStateImpl lua) throws LuanException { |
27 lua.returnValues = expressions.eval(lua); | 27 lua.returnValues = expressions.eval(lua); |
28 if( tailFnExpr != null ) { | 28 if( tailFnExpr != null ) { |
29 LuaFunction tailFn = lua.checkFunction( se, tailFnExpr.eval(lua) ); | 29 LuanFunction tailFn = lua.checkFunction( se, tailFnExpr.eval(lua) ); |
30 if( tailFn instanceof LuaClosure ) { | 30 if( tailFn instanceof Closure ) { |
31 lua.tailFn = (LuaClosure)tailFn; | 31 lua.tailFn = (Closure)tailFn; |
32 } else { | 32 } else { |
33 lua.returnValues = lua.call(tailFn,tailFnExpr.se(),tailFnExpr.se().text(),lua.returnValues); | 33 lua.returnValues = lua.call(tailFn,tailFnExpr.se(),tailFnExpr.se().text(),lua.returnValues); |
34 } | 34 } |
35 } | 35 } |
36 if( throwReturnException ) | 36 if( throwReturnException ) |