Mercurial Hosting > luan
changeset 127:bcb3a09d0caf
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@128 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sat, 07 Jun 2014 01:47:00 +0000 |
parents | 0149bdf98fd8 |
children | f0a4abe58593 |
files | src/luan/interp/ForStmt.java src/luan/interp/GenericForStmt.java src/luan/interp/LuanParser.java |
diffstat | 3 files changed, 57 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
diff -r 0149bdf98fd8 -r bcb3a09d0caf src/luan/interp/ForStmt.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/interp/ForStmt.java Sat Jun 07 01:47:00 2014 +0000 @@ -0,0 +1,54 @@ +package luan.interp; + +import luan.Luan; +import luan.LuanException; +import luan.LuanFunction; +import luan.LuanSource; +import luan.LuanBit; + + +final class ForStmt extends CodeImpl implements Stmt { + private final int iVars; + private final int nVars; + private final Expr iterExpr; + private final Stmt block; + + ForStmt(LuanSource.Element se,int iVars,int nVars,Expr iterExpr,Stmt block) { + super(se); + this.iVars = iVars; + this.nVars = nVars; + this.iterExpr = iterExpr; + this.block = block; + } + + @Override public void eval(LuanStateImpl luan) throws LuanException { + LuanFunction iter = luan.bit(se).checkFunction( iterExpr.eval(luan) ); + LuanBit bit = luan.bit(iterExpr.se()); + String name = iterExpr.se().text(); + try { + while(true) { + Object vals = bit.call(iter,name); + if( vals==null ) + break; + if( vals instanceof Object[] ) { + Object[] a = (Object[])vals; + if( a.length==0 ) + break; + for( int i=0; i<nVars; i++ ) { + luan.stackSet( iVars+i, i < a.length ? a[i] : null ); + } + } else { + luan.stackSet( iVars, vals ); + for( int i=1; i<nVars; i++ ) { + luan.stackSet( iVars+i, null ); + } + } + block.eval(luan); + } + } catch(BreakException e) { + } finally { + luan.stackClear(iVars,iVars+nVars); + } + } + +}
diff -r 0149bdf98fd8 -r bcb3a09d0caf src/luan/interp/GenericForStmt.java --- a/src/luan/interp/GenericForStmt.java Fri Jun 06 14:16:38 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package luan.interp; - -import luan.Luan; -import luan.LuanException; -import luan.LuanFunction; -import luan.LuanSource; -import luan.LuanBit; - - -final class GenericForStmt extends CodeImpl implements Stmt { - private final int iVars; - private final int nVars; - private final Expr iterExpr; - private final Stmt block; - - GenericForStmt(LuanSource.Element se,int iVars,int nVars,Expr iterExpr,Stmt block) { - super(se); - this.iVars = iVars; - this.nVars = nVars; - this.iterExpr = iterExpr; - this.block = block; - } - - @Override public void eval(LuanStateImpl luan) throws LuanException { - LuanFunction iter = luan.bit(se).checkFunction( iterExpr.eval(luan) ); - LuanBit bit = luan.bit(iterExpr.se()); - String name = iterExpr.se().text(); - try { - while(true) { - Object vals = bit.call(iter,name); - if( vals==null ) - break; - if( vals instanceof Object[] ) { - Object[] a = (Object[])vals; - if( a.length==0 ) - break; - for( int i=0; i<nVars; i++ ) { - luan.stackSet( iVars+i, i < a.length ? a[i] : null ); - } - } else { - luan.stackSet( iVars, vals ); - for( int i=1; i<nVars; i++ ) { - luan.stackSet( iVars+i, null ); - } - } - block.eval(luan); - } - } catch(BreakException e) { - } finally { - luan.stackClear(iVars,iVars+nVars); - } - } - -}
diff -r 0149bdf98fd8 -r bcb3a09d0caf src/luan/interp/LuanParser.java --- a/src/luan/interp/LuanParser.java Fri Jun 06 14:16:38 2014 +0000 +++ b/src/luan/interp/LuanParser.java Sat Jun 07 01:47:00 2014 +0000 @@ -221,7 +221,7 @@ || (stmt=LocalFunctionStmt()) != null || (stmt=ImportStmt()) != null || (stmt=BreakStmt()) != null - || (stmt=GenericForStmt()) != null + || (stmt=ForStmt()) != null || (stmt=TryStmt()) != null || (stmt=DoStmt()) != null || (stmt=WhileStmt()) != null @@ -330,7 +330,7 @@ return parser.success( new BreakStmt() ); } - private Stmt GenericForStmt() throws ParseException { + private Stmt ForStmt() throws ParseException { int start = parser.begin(); int stackStart = symbolsSize(); if( !Keyword("for") ) @@ -343,7 +343,7 @@ addSymbols(names); Stmt loop = RequiredLoopBlock(); RequiredKeyword("end"); - Stmt stmt = new GenericForStmt( se(start), stackStart, symbolsSize() - stackStart, expr, loop ); + Stmt stmt = new ForStmt( se(start), stackStart, symbolsSize() - stackStart, expr, loop ); popSymbols( symbolsSize() - stackStart ); return parser.success(stmt); }