}
switch(op) {
case LITERAL: stack.push((JS)arg); break;
- case OBJECT: stack.push(new JS.O()); break;
- case ARRAY: stack.push(new JSArray(JS.toInt((JS)arg))); break;
+ 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 (JS.toBoolean(stack.pop())) pc += JS.toInt((JS)arg) - 1; break;
- case JF: if (!JS.toBoolean(stack.pop())) pc += JS.toInt((JS)arg) - 1; break;
- case JMP: pc += JS.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 DUP: stack.push(stack.peek()); break;
case NEWSCOPE: {
- int n = JS.toInt((JS)arg);
+ int n = Script.toInt((JS)arg);
scope = new JSScope(scope,(n>>>16)&0xffff,(n>>>0)&0xffff);
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 (!JS.toBoolean(stack.pop())) throw je("ibex.assertion.failed"); break;
- case BITNOT: stack.push(JS.N(~JS.toLong(stack.pop()))); break;
- case BANG: stack.push(JS.B(!JS.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;
case TYPEOF: {
Object o = stack.pop();
if (o == null) stack.push(null);
- else if (o instanceof JSString) stack.push(JS.S("string"));
- else if (o instanceof JSNumber.B) stack.push(JS.S("boolean"));
- else if (o instanceof JSNumber) stack.push(JS.S("number"));
- else stack.push(JS.S("object"));
+ else if (o instanceof JSString) stack.push(Script.S("string"));
+ else if (o instanceof JSNumber.B) stack.push(Script.S("boolean"));
+ else if (o instanceof JSNumber) stack.push(Script.S("number"));
+ else stack.push(Script.S("object"));
break;
}
if (o instanceof LoopMarker) {
if (arg == null || arg.equals(((LoopMarker)o).label)) {
int loopInstructionLocation = ((LoopMarker)o).location;
- int endOfLoop = JS.toInt((JS)f.arg[loopInstructionLocation]) + loopInstructionLocation;
+ 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;
}
boolean didTrapPut = false;
if (o instanceof TrapMarker) { // handles return component of a write trap
TrapMarker tm = (TrapMarker) o;
- boolean cascade = tm.t.isWriteTrap() && !tm.cascadeHappened && !JS.toBoolean(retval);
+ boolean cascade = tm.t.isWriteTrap() && !tm.cascadeHappened && !Script.toBoolean(retval);
if(cascade) {
JS.Trap t = tm.t.nextWrite();
if(t == null && tm.t.target() instanceof JS.Clone) {
}
case CASCADE: {
- boolean write = JS.toBoolean((JS)arg);
- JS val = write ? stack.pop() : null;
+ boolean write = Script.toBoolean((JS)arg);
+ 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;
stack.push(key);
}
JS ret = null;
- if (key == null) throw je("tried to get the null key from " + JS.debugToString(target));
- if (target == null) throw je("tried to get property \"" + JS.debugToString(key) + "\" from the null object");
+ if (key == null) throw je("tried to get the null key from " + Script.str(target));
+ if (target == null) throw je("tried to get property \"" + Script.str(key) + "\" from the null object");
JS.Trap t = target.getTrap(key);
if(t != null) t = t.read();
JS left = (JS)stack.pop();
JS ret;
if(left instanceof JSString || right instanceof JSString)
- ret = JS.S(JS.toString(left).concat(JS.toString(right)));
+ ret = Script.S(Script.toString(left).concat(Script.toString(right)));
else if(left instanceof JSNumber.D || right instanceof JSNumber.D)
- ret = JS.N(JS.toDouble(left) + JS.toDouble(right));
+ ret = Script.N(Script.toDouble(left) + Script.toDouble(right));
else {
- long l = JS.toLong(left) + JS.toLong(right);
- if(l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) ret = JS.N(l);
- ret = JS.N((int)l);
+ long l = Script.toLong(left) + Script.toLong(right);
+ if(l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) ret = Script.N(l);
+ ret = Script.N((int)l);
}
stack.push(ret);
} else {
while(--count >= 0) args[count] = (JS)stack.pop();
if(args[0] instanceof JSString) {
StringBuffer sb = new StringBuffer(64);
- for(int i=0;i<args.length;i++) sb.append(JS.toString(args[i]));
- stack.push(JS.S(sb.toString()));
+ for(int i=0;i<args.length;i++) sb.append(Script.toString(args[i]));
+ stack.push(Script.S(sb.toString()));
} else {
int numStrings = 0;
for(int i=0;i<args.length;i++) if(args[i] instanceof JSString) numStrings++;
if(numStrings == 0) {
double d = 0.0;
- for(int i=0;i<args.length;i++) d += JS.toDouble(args[i]);
- stack.push(JS.N(d));
+ for(int i=0;i<args.length;i++) d += Script.toDouble(args[i]);
+ stack.push(Script.N(d));
} else {
int i=0;
StringBuffer sb = new StringBuffer(64);
if(!(args[0] instanceof JSString || args[1] instanceof JSString)) {
double d=0.0;
do {
- d += JS.toDouble(args[i++]);
+ d += Script.toDouble(args[i++]);
} while(!(args[i] instanceof JSString));
- sb.append(JS.toString(JS.N(d)));
+ sb.append(Script.toString(Script.N(d)));
}
- while(i < args.length) sb.append(JS.toString(args[i++]));
- stack.push(JS.S(sb.toString()));
+ while(i < args.length) sb.append(Script.toString(args[i++]));
+ stack.push(Script.S(sb.toString()));
}
}
}
JS left = (JS)stack.pop();
switch(op) {
- case BITOR: stack.push(JS.N(JS.toLong(left) | JS.toLong(right))); break;
- case BITXOR: stack.push(JS.N(JS.toLong(left) ^ JS.toLong(right))); break;
- case BITAND: stack.push(JS.N(JS.toLong(left) & JS.toLong(right))); break;
-
- case SUB: stack.push(JS.N(JS.toDouble(left) - JS.toDouble(right))); break;
- case MUL: stack.push(JS.N(JS.toDouble(left) * JS.toDouble(right))); break;
- case DIV: stack.push(JS.N(JS.toDouble(left) / JS.toDouble(right))); break;
- case MOD: stack.push(JS.N(JS.toDouble(left) % JS.toDouble(right))); break;
+ case BITOR: stack.push(Script.N(Script.toLong(left) | Script.toLong(right))); break;
+ case BITXOR: stack.push(Script.N(Script.toLong(left) ^ Script.toLong(right))); break;
+ case BITAND: stack.push(Script.N(Script.toLong(left) & Script.toLong(right))); break;
+
+ case SUB: stack.push(Script.N(Script.toDouble(left) - Script.toDouble(right))); break;
+ case MUL: stack.push(Script.N(Script.toDouble(left) * Script.toDouble(right))); break;
+ case DIV: stack.push(Script.N(Script.toDouble(left) / Script.toDouble(right))); break;
+ case MOD: stack.push(Script.N(Script.toDouble(left) % Script.toDouble(right))); break;
- case LSH: stack.push(JS.N(JS.toLong(left) << JS.toLong(right))); break;
- case RSH: stack.push(JS.N(JS.toLong(left) >> JS.toLong(right))); break;
- case URSH: stack.push(JS.N(JS.toLong(left) >>> JS.toLong(right))); break;
+ case LSH: stack.push(Script.N(Script.toLong(left) << Script.toLong(right))); break;
+ case RSH: stack.push(Script.N(Script.toLong(left) >> Script.toLong(right))); break;
+ case URSH: stack.push(Script.N(Script.toLong(left) >>> Script.toLong(right))); break;
//#repeat </<=/>/>= LT/LE/GT/GE
case LT: {
if(left instanceof JSString && right instanceof JSString)
- stack.push(JS.B(JS.toString(left).compareTo(JS.toString(right)) < 0));
+ stack.push(Script.B(Script.toString(left).compareTo(Script.toString(right)) < 0));
else
- stack.push(JS.B(JS.toDouble(left) < JS.toDouble(right)));
+ stack.push(Script.B(Script.toDouble(left) < Script.toDouble(right)));
}
//#end
boolean ret;
if(left == null && right == null) ret = true;
else if(left == null || right == null) ret = false;
- else ret = left.jsequals(right);
- stack.push(JS.B(op == EQ ? ret : !ret)); break;
+ else ret = left.equals(right);
+ stack.push(Script.B(op == EQ ? ret : !ret)); break;
}
default: throw new Error("unknown opcode " + op);
if(cm.f == null) break;
String s = cm.f.sourceName + ":" + cm.f.line[cm.pc-1];
if(cm instanceof Interpreter.TrapMarker)
- s += " (trap on " + JS.debugToString(((Interpreter.TrapMarker)cm).t.key) + ")";
+ s += " (trap on " + Script.str(((Interpreter.TrapMarker)cm).t.key()) + ")";
e.addBacktrace(s);
}
}