Mercurial Hosting > luan
view core/src/luan/impl/ReturnStmt.java @ 652:067d9470184d
compile SetStmt and ForStmt
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 04 Apr 2016 23:26:06 -0600 |
parents | 8e8c30b72e9b |
children | f1150518c467 |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanException; import luan.LuanFunction; final class ReturnStmt extends CodeImpl implements Stmt { private final Expressions expressions; boolean throwReturnException = true; ReturnStmt(Expressions expressions) { this.expressions = expressions; } @Override public void eval(LuanStateImpl luan) throws LuanException { if( !(expressions instanceof FnCall) ) { luan.returnValues = expressions.eval(luan); } else { // tail call FnCall tailFnCall = (FnCall)expressions; LuanFunction tailFn = Luan.checkFunction( tailFnCall.fnExpr.eval(luan) ); luan.returnValues = tailFnCall.args.eval(luan); if( tailFn instanceof Closure ) { luan.tailFn = (Closure)tailFn; } else { luan.returnValues = tailFn.call(luan,Luan.array(luan.returnValues)); } } if( throwReturnException ) throw new ReturnException(); } }