comparison src/luan/impl/ReturnStmt.java @ 166:4eaee12f6c65

move luan/interp to impl git-svn-id: https://luan-java.googlecode.com/svn/trunk@167 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 22 Jun 2014 04:17:38 +0000
parents src/luan/interp/ReturnStmt.java@f5af13062b10
children
comparison
equal deleted inserted replaced
165:94bbc4cbc106 166:4eaee12f6c65
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 }