comparison core/src/luan/impl/UnmExpr.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 import luan.LuanTable; 7 import luan.LuanTable;
9 8
10 9
11 // unary minus 10 // unary minus
12 final class UnmExpr extends UnaryOpExpr { 11 final class UnmExpr extends UnaryOpExpr {
17 16
18 @Override public Object eval(LuanStateImpl luan) throws LuanException { 17 @Override public Object eval(LuanStateImpl luan) throws LuanException {
19 Object o = op.eval(luan); 18 Object o = op.eval(luan);
20 if( o instanceof Number ) 19 if( o instanceof Number )
21 return -((Number)o).doubleValue(); 20 return -((Number)o).doubleValue();
22 LuanBit bit = luan.bit(el); 21 luan.push(el,null);
23 if( o instanceof LuanTable ) { 22 try {
24 LuanFunction fn = bit.getHandlerFunction("__unm",(LuanTable)o); 23 if( o instanceof LuanTable ) {
25 if( fn != null ) { 24 LuanFunction fn = luan.getHandlerFunction("__unm",(LuanTable)o);
26 return Luan.first(bit.call(fn,"__unm",new Object[]{o})); 25 if( fn != null ) {
26 return Luan.first(fn.call(luan,new Object[]{o}));
27 }
27 } 28 }
29 throw luan.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value");
30 } finally {
31 luan.pop();
28 } 32 }
29 throw bit.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value");
30 } 33 }
31 } 34 }