import java.io.*;
/** A block of JavaScript bytecode run on a very simple stack machine. */
-class ByteCodeBlock implements ByteCodes, Tokens {
+public class ByteCodeBlock implements ByteCodes, Tokens {
// FIXME: this should be line-by-line
private int line;
Object left = t.pop();
switch(op[i]) {
- case BITOR: t.push(new Long(JS.toLong(left) | JS.toLong(right))); break;
- case BITXOR: t.push(new Long(JS.toLong(left) ^ JS.toLong(right))); break;
- case BITAND: t.push(new Long(JS.toLong(left) & JS.toLong(right))); break;
-
case ADD: {
Object l = left;
Object r = right;
t.push(new Double(JS.toDouble(l) + JS.toDouble(r))); break;
}
+ case BITOR: t.push(new Long(JS.toLong(left) | JS.toLong(right))); break;
+ case BITXOR: t.push(new Long(JS.toLong(left) ^ JS.toLong(right))); break;
+ case BITAND: t.push(new Long(JS.toLong(left) & JS.toLong(right))); break;
+
case SUB: t.push(new Double(JS.toDouble(left) - JS.toDouble(right))); break;
case MUL: t.push(new Double(JS.toDouble(left) * JS.toDouble(right))); break;
case DIV: t.push(new Double(JS.toDouble(left) / JS.toDouble(right))); break;
default: throw new Error("unknown opcode " + op[i]);
} }
}
- if (t.size() != 1)
- throw new EvaluatorException(line, sourceName, "eval() terminated with " + t.size() +
- " elements on the stack; one expected");
+ System.out.println("returning");
+ if (t.size() != 1) throw new Error("eval() terminated with " + t.size() + " elements on the stack; one expected");
return t.pop();
}
public String label;
ContinueException(String label) { this.label = label; }
}
- static class ReturnException extends ControlTransferException {
+ public static class ReturnException extends ControlTransferException {
public Object retval;
ReturnException(Object retval) { this.retval = retval; }
}