comparison core/src/luan/impl/LeExpr.java @ 576:4723d22062ce

remove LuanBit
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 13 Jul 2015 20:38:26 -0600
parents b48cfa14ba60
children 60c549d43988
comparison
equal deleted inserted replaced
575:7c3ad6db8ac3 576:4723d22062ce
2 2
3 import luan.Luan; 3 import luan.Luan;
4 import luan.LuanFunction; 4 import luan.LuanFunction;
5 import luan.LuanException; 5 import luan.LuanException;
6 import luan.LuanElement; 6 import luan.LuanElement;
7 import luan.LuanBit;
8 7
9 8
10 final class LeExpr extends BinaryOpExpr { 9 final class LeExpr extends BinaryOpExpr {
11 10
12 LeExpr(LuanElement el,Expr op1,Expr op2) { 11 LeExpr(LuanElement el,Expr op1,Expr op2) {
28 if( o1 instanceof String && o2 instanceof String ) { 27 if( o1 instanceof String && o2 instanceof String ) {
29 String s1 = (String)o1; 28 String s1 = (String)o1;
30 String s2 = (String)o2; 29 String s2 = (String)o2;
31 return s1.compareTo(s2) <= 0; 30 return s1.compareTo(s2) <= 0;
32 } 31 }
33 LuanBit bit = luan.bit(el); 32 luan.push(el,null);
34 LuanFunction fn = bit.getBinHandler("__le",o1,o2); 33 try {
35 if( fn != null ) 34 LuanFunction fn = luan.getBinHandler("__le",o1,o2);
36 return bit.checkBoolean( Luan.first(bit.call(fn,"__le",new Object[]{o1,o2})) ); 35 if( fn != null )
37 fn = bit.getBinHandler("__lt",o1,o2); 36 return luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) );
38 if( fn != null ) 37 fn = luan.getBinHandler("__lt",o1,o2);
39 return !bit.checkBoolean( Luan.first(bit.call(fn,"__lt",new Object[]{o2,o1})) ); 38 if( fn != null )
40 throw bit.exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); 39 return !luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o2,o1})) );
40 throw luan.exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
41 } finally {
42 luan.pop();
43 }
41 } 44 }
42 } 45 }