01: package gnu.ecmascript;
02:
03: import gnu.mapping.*;
04:
05: public class BinaryOp extends Procedure2 {
06: int op;
07:
08: public BinaryOp(String name, int op) {
09: setName(name);
10: this .op = op;
11: }
12:
13: public Object apply2(Object arg1, Object arg2) {
14: if (op == Reserved.LESS_OP) {
15: return Convert.toNumber(arg1) < Convert.toNumber(arg2) ? Boolean.TRUE
16: : Boolean.FALSE;
17: }
18: return new Double(apply(Convert.toNumber(arg1), Convert
19: .toNumber(arg2)));
20: }
21:
22: public double apply(double arg1, double arg2) {
23: switch (op) {
24: case Reserved.PLUS_OP:
25: return arg1 + arg2;
26: case Reserved.MINUS_OP:
27: return arg1 - arg2;
28: case Reserved.TIMES_OP:
29: return arg1 * arg2;
30: case Reserved.LSHIFT_OP:
31: return (double) ((int) arg1 << ((int) arg2 & 31));
32: }
33: return Double.NaN;
34: }
35: }
|