Mercurial Hosting > luan
comparison core/src/luan/impl/ReturnStmt.java @ 171:3dcb0f9bee82
add core component
git-svn-id: https://luan-java.googlecode.com/svn/trunk@172 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 22 Jun 2014 05:41:22 +0000 |
parents | src/luan/impl/ReturnStmt.java@4eaee12f6c65 |
children | 7580379cdc79 |
comparison
equal
deleted
inserted
replaced
170:7c792a328a83 | 171:3dcb0f9bee82 |
---|---|
1 package luan.impl; | |
2 | |
3 import luan.Luan; | |
4 import luan.LuanException; | |
5 import luan.LuanFunction; | |
6 import luan.LuanSource; | |
7 | |
8 | |
9 final class ReturnStmt extends CodeImpl implements Stmt { | |
10 private final Expressions expressions; | |
11 private final Expr tailFnExpr; | |
12 boolean throwReturnException = true; | |
13 | |
14 ReturnStmt(LuanSource.Element se,Expressions expressions) { | |
15 super(se); | |
16 if( expressions instanceof FnCall ) { // tail call | |
17 FnCall fnCall = (FnCall)expressions; | |
18 this.expressions = fnCall.args; | |
19 this.tailFnExpr = fnCall.fnExpr; | |
20 } else { | |
21 this.expressions = expressions; | |
22 this.tailFnExpr = null; | |
23 } | |
24 } | |
25 | |
26 @Override public void eval(LuanStateImpl luan) throws LuanException { | |
27 luan.returnValues = expressions.eval(luan); | |
28 if( tailFnExpr != null ) { | |
29 LuanFunction tailFn = luan.bit(se).checkFunction( tailFnExpr.eval(luan) ); | |
30 if( tailFn instanceof Closure ) { | |
31 luan.tailFn = (Closure)tailFn; | |
32 } else { | |
33 luan.returnValues = luan.bit(tailFnExpr.se()).call(tailFn,tailFnExpr.se().text(),Luan.array(luan.returnValues)); | |
34 } | |
35 } | |
36 if( throwReturnException ) | |
37 throw new ReturnException(); | |
38 } | |
39 } |