case OBJECT: stack.push(new JS.Obj()); break;
case ARRAY: stack.push(new JSArray(Script.toInt((JS)arg))); break;
//case DECLARE: scope.declare((JS)(arg==null ? stack.peek() : arg)); if(arg != null) stack.push((JS)arg); break;
- case JT: if (Script.toBoolean(stack.pop())) pc += Script.toInt((JS)arg) - 1; break;
- case JF: if (!Script.toBoolean(stack.pop())) pc += Script.toInt((JS)arg) - 1; break;
+ case JT: if (Script.toBoolean((JS)stack.pop())) pc += Script.toInt((JS)arg) - 1; break;
+ case JF: if (!Script.toBoolean((JS)stack.pop())) pc += Script.toInt((JS)arg) - 1; break;
case JMP: pc += Script.toInt((JS)arg) - 1; break;
case POP: stack.pop(); break;
case SWAP: stack.swap(); break;
case OLDSCOPE: scope = scope.parent; break;
case GLOBALSCOPE: stack.push(scope.getGlobal()); break;
case SCOPEGET: stack.push(scope.get((JS)arg)); break;
- case SCOPEPUT: scope.put((JS)arg,stack.peek()); break;
- case ASSERT: if (!Script.toBoolean(stack.pop())) throw je("ibex.assertion.failed"); break;
- case BITNOT: stack.push(Script.N(~Script.toLong(stack.pop()))); break;
- case BANG: stack.push(Script.B(!Script.toBoolean(stack.pop()))); break;
+ case SCOPEPUT: scope.put((JS)arg, (JS)stack.peek()); break;
+ case ASSERT: if (!Script.toBoolean((JS)stack.pop())) throw je("ibex.assertion.failed"); break;
+ case BITNOT: stack.push(Script.N(~Script.toLong((JS)stack.pop()))); break;
+ case BANG: stack.push(Script.B(!Script.toBoolean((JS)stack.pop()))); break;
case NEWFUNCTION: stack.push(((JSFunction)arg)._cloneWithNewParentScope(scope)); break;
case LABEL: break;
int loopInstructionLocation = ((LoopMarker)o).location;
int endOfLoop = Script.toInt((JS)f.arg[loopInstructionLocation]) + loopInstructionLocation;
scope = ((LoopMarker)o).scope;
- if (op == CONTINUE) { stack.push(o); stack.push(JS.F); }
+ if (op == CONTINUE) { stack.push(o); stack.push(Script.F); }
pc = op == BREAK ? endOfLoop - 1 : loopInstructionLocation;
continue OUTER;
}
case CASCADE: {
boolean write = Script.toBoolean((JS)arg);
- JS val = write ? stack.pop() : null;
+ JS val = write ? (JS)stack.pop() : null;
CallMarker o = stack.findCall();
if(!(o instanceof TrapMarker)) throw new JSExn("tried to CASCADE while not in a trap");
TrapMarker tm = (TrapMarker) o;
}
case CALL: case CALLMETHOD: {
- JS[] jsargs = (JS[])arg;
+ // FIXME: can a lot of simple cases in Parser be
+ // reduced so creating a new JS[] is not necessary?
+ JS[] jsargs;
+ if (arg instanceof JSNumber.I) {
+ jsargs = new JS[((JSNumber.I)arg).toInt()];
+ for (int i=0; i < jsargs.length; i++) jsargs[i] = (JS)stack.pop();
+ } else jsargs = (JS[])arg;
JS method = null;
JS ret = null;
JS key = (JS)stack.pop();
JS js = (JS)stack.peek();
// A trap addition/removal
- if(!(val instanceof JSFunction)) throw new JSExn("tried to add/remove a non-function trap");
+ if(!(val instanceof JSFunction)) throw new JSExn("tried to add/remove a non-function trap"); // FIXME
if(op == ADD_TRAP) js.addTrap(key, val);
else js.delTrap(key, val);
break;
boolean ret;
if(left == null && right == null) ret = true;
else if(left == null || right == null) ret = false;
- else ret = left.jsequals(right);
+ else ret = left.equals(right);
stack.push(Script.B(op == EQ ? ret : !ret)); break;
}
*/
void catchException(JSExn e) throws JSExn {
while(!stack.empty()) {
- JS o = (JS)stack.pop();
+ Object o = stack.pop();
if (o instanceof CatchMarker || o instanceof TryMarker) {
boolean inCatch = o instanceof CatchMarker;
if(inCatch) {
if(cm.f == null) break;
String s = cm.f.sourceName + ":" + cm.f.line[cm.pc-1];
if(cm instanceof Interpreter.TrapMarker)
- s += " (trap on " + Script.str(((Interpreter.TrapMarker)cm).t.key) + ")";
+ s += " (trap on " + Script.str(((Interpreter.TrapMarker)cm).t.key()) + ")";
e.addBacktrace(s);
}
}