Mercurial Hosting > luan
view core/src/luan/impl/ReturnStmt.java @ 564:c8d4d69c6dd4
add examples/upload-and-email.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 04 Jul 2015 20:57:24 -0600 |
parents | b48cfa14ba60 |
children | 4723d22062ce |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanException; import luan.LuanFunction; import luan.LuanElement; final class ReturnStmt extends CodeImpl implements Stmt { private final Expressions expressions; private final Expr tailFnExpr; boolean throwReturnException = true; ReturnStmt(LuanElement el,Expressions expressions) { super(el); if( expressions instanceof FnCall ) { // tail call FnCall fnCall = (FnCall)expressions; this.expressions = fnCall.args; this.tailFnExpr = fnCall.fnExpr; } else { this.expressions = expressions; this.tailFnExpr = null; } } @Override public void eval(LuanStateImpl luan) throws LuanException { luan.returnValues = expressions.eval(luan); if( tailFnExpr != null ) { LuanElement elTail = tailFnExpr.el(); LuanFunction tailFn = luan.bit(elTail).checkFunction( tailFnExpr.eval(luan) ); if( tailFn instanceof Closure ) { luan.tailFn = (Closure)tailFn; } else { luan.returnValues = luan.bit(elTail).call(tailFn,elTail.text(),Luan.array(luan.returnValues)); } } if( throwReturnException ) throw new ReturnException(); } }