Mercurial Hosting > luan
changeset 615:abc3198c86dd
fix tail recursion bug;
add Hosting.exists();
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 17 Dec 2015 01:53:48 -0700 |
parents | 9ecf5673fb6d |
children | 56b0b9018319 |
files | core/src/luan/impl/ReturnStmt.java core/src/luan/modules/host/Hosting.luan |
diffstat | 2 files changed, 20 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
diff -r 9ecf5673fb6d -r abc3198c86dd core/src/luan/impl/ReturnStmt.java --- a/core/src/luan/impl/ReturnStmt.java Mon Dec 14 23:55:36 2015 -0700 +++ b/core/src/luan/impl/ReturnStmt.java Thu Dec 17 01:53:48 2015 -0700 @@ -8,35 +8,29 @@ 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; - } + this.expressions = expressions; } @Override public void eval(LuanStateImpl luan) throws LuanException { - luan.returnValues = expressions.eval(luan); - if( tailFnExpr != null ) { - LuanElement elTail = tailFnExpr.el(); - luan.push(elTail,elTail.text()); - try { - LuanFunction tailFn = luan.checkFunction( tailFnExpr.eval(luan) ); - if( tailFn instanceof Closure ) { - luan.tailFn = (Closure)tailFn; - } else { + 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.push(el,tailFnCall.fnName); + try { luan.returnValues = tailFn.call(luan,Luan.array(luan.returnValues)); + } finally { + luan.pop(); } - } finally { - luan.pop(); } } if( throwReturnException )
diff -r 9ecf5673fb6d -r abc3198c86dd core/src/luan/modules/host/Hosting.luan --- a/core/src/luan/modules/host/Hosting.luan Mon Dec 14 23:55:36 2015 -0700 +++ b/core/src/luan/modules/host/Hosting.luan Thu Dec 17 01:53:48 2015 -0700 @@ -63,4 +63,10 @@ host.delete(domain,password) end +function M.exists(domain) + local socket = "socket:" .. domain .. ":" .. M.port + local host = Rpc.remote(socket) + return host.exists(domain) +end + return M