Mercurial Hosting > luan
comparison src/luan/interp/GenericForStmt.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | c3eab5a3ce3c |
children | 64ecb7a3aad7 |
comparison
equal
deleted
inserted
replaced
39:e5bcb1eeafc1 | 40:e3624b7cd603 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.Lua; | 3 import luan.Lua; |
4 import luan.LuaException; | 4 import luan.LuaException; |
5 import luan.LuaFunction; | 5 import luan.LuaFunction; |
6 import luan.LuaSource; | |
6 | 7 |
7 | 8 |
8 final class GenericForStmt implements Stmt { | 9 final class GenericForStmt extends CodeImpl implements Stmt { |
9 private final int iVars; | 10 private final int iVars; |
10 private final int nVars; | 11 private final int nVars; |
11 private final Expr iterExpr; | 12 private final Expr iterExpr; |
12 private final Stmt block; | 13 private final Stmt block; |
13 | 14 |
14 GenericForStmt(int iVars,int nVars,Expr iterExpr,Stmt block) { | 15 GenericForStmt(LuaSource.Element se,int iVars,int nVars,Expr iterExpr,Stmt block) { |
16 super(se); | |
15 this.iVars = iVars; | 17 this.iVars = iVars; |
16 this.nVars = nVars; | 18 this.nVars = nVars; |
17 this.iterExpr = iterExpr; | 19 this.iterExpr = iterExpr; |
18 this.block = block; | 20 this.block = block; |
19 } | 21 } |
20 | 22 |
21 @Override public void eval(LuaStateImpl lua) throws LuaException { | 23 @Override public void eval(LuaStateImpl lua) throws LuaException { |
22 LuaFunction iter = Lua.checkFunction( iterExpr.eval(lua) ); | 24 LuaFunction iter = lua.checkFunction( se, iterExpr.eval(lua) ); |
23 try { | 25 try { |
24 while(true) { | 26 while(true) { |
25 Object[] vals = iter.call(lua); | 27 Object[] vals = lua.call(iter,iterExpr.se(),iterExpr.se().text()); |
26 if( vals.length==0 || vals[0]==null ) | 28 if( vals.length==0 || vals[0]==null ) |
27 break; | 29 break; |
28 for( int i=0; i<nVars; i++ ) { | 30 for( int i=0; i<nVars; i++ ) { |
29 lua.stackSet( iVars+i, i < vals.length ? vals[i] : null ); | 31 lua.stackSet( iVars+i, i < vals.length ? vals[i] : null ); |
30 } | 32 } |