Mercurial Hosting > luan
comparison core/src/luan/impl/ReturnStmt.java @ 659:f1150518c467
remove tail recursion
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Apr 2016 20:30:42 -0600 |
parents | 8e8c30b72e9b |
children | b438a47196bc |
comparison
equal
deleted
inserted
replaced
658:e038905512d3 | 659:f1150518c467 |
---|---|
12 ReturnStmt(Expressions expressions) { | 12 ReturnStmt(Expressions expressions) { |
13 this.expressions = expressions; | 13 this.expressions = expressions; |
14 } | 14 } |
15 | 15 |
16 @Override public void eval(LuanStateImpl luan) throws LuanException { | 16 @Override public void eval(LuanStateImpl luan) throws LuanException { |
17 if( !(expressions instanceof FnCall) ) { | 17 luan.returnValues = expressions.eval(luan); |
18 luan.returnValues = expressions.eval(luan); | |
19 } else { // tail call | |
20 FnCall tailFnCall = (FnCall)expressions; | |
21 LuanFunction tailFn = Luan.checkFunction( tailFnCall.fnExpr.eval(luan) ); | |
22 luan.returnValues = tailFnCall.args.eval(luan); | |
23 if( tailFn instanceof Closure ) { | |
24 luan.tailFn = (Closure)tailFn; | |
25 } else { | |
26 luan.returnValues = tailFn.call(luan,Luan.array(luan.returnValues)); | |
27 } | |
28 } | |
29 if( throwReturnException ) | 18 if( throwReturnException ) |
30 throw new ReturnException(); | 19 throw new ReturnException(); |
31 } | 20 } |
32 } | 21 } |