comparison src/luan/interp/NumericForStmt.java @ 88:6ca02b188dba

add LuanBit to clean up code; add repr(); git-svn-id: https://luan-java.googlecode.com/svn/trunk@89 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 27 Feb 2013 23:50:32 +0000
parents 8ede219cd111
children
comparison
equal deleted inserted replaced
87:eaf37cfa30c2 88:6ca02b188dba
1 package luan.interp; 1 package luan.interp;
2 2
3 import luan.Luan; 3 import luan.Luan;
4 import luan.LuanException; 4 import luan.LuanException;
5 import luan.LuanSource; 5 import luan.LuanSource;
6 import luan.LuanBit;
6 7
7 8
8 final class NumericForStmt extends CodeImpl implements Stmt { 9 final class NumericForStmt extends CodeImpl implements Stmt {
9 private final int iVar; 10 private final int iVar;
10 private final Expr fromExpr; 11 private final Expr fromExpr;
20 this.stepExpr = stepExpr; 21 this.stepExpr = stepExpr;
21 this.block = block; 22 this.block = block;
22 } 23 }
23 24
24 @Override public void eval(LuanStateImpl luan) throws LuanException { 25 @Override public void eval(LuanStateImpl luan) throws LuanException {
25 double v = luan.checkNumber( se, fromExpr.eval(luan) ).doubleValue(); 26 LuanBit bit = luan.bit(se);
26 double limit = luan.checkNumber( se, toExpr.eval(luan) ).doubleValue(); 27 double v = bit.checkNumber( fromExpr.eval(luan) ).doubleValue();
27 double step = luan.checkNumber( se, stepExpr.eval(luan) ).doubleValue(); 28 double limit = bit.checkNumber( toExpr.eval(luan) ).doubleValue();
29 double step = bit.checkNumber( stepExpr.eval(luan) ).doubleValue();
28 try { 30 try {
29 while( step > 0.0 && v <= limit || step < 0.0 && v >= limit ) { 31 while( step > 0.0 && v <= limit || step < 0.0 && v >= limit ) {
30 luan.stackSet( iVar, v ); 32 luan.stackSet( iVar, v );
31 block.eval(luan); 33 block.eval(luan);
32 v += step; 34 v += step;