зеркало из https://github.com/mozilla/pjs.git
For prefix and postfix ++/-- use mask flags instead of enumeration to denote postfix/prefix and ++/-- operation.
This commit is contained in:
Родитель
77c7c241d2
Коммит
a3039484fe
|
@ -828,13 +828,14 @@ class IRFactory
|
|||
|| childType == Token.GET_REF)
|
||||
{
|
||||
Node n = new Node(nodeType, childNode);
|
||||
int type;
|
||||
if (nodeType == Token.INC) {
|
||||
type = (post) ? Node.POST_INC : Node.PRE_INC;
|
||||
} else {
|
||||
type = (post) ? Node.POST_DEC : Node.PRE_DEC;
|
||||
int incrDecrMask = 0;
|
||||
if (nodeType == Token.DEC) {
|
||||
incrDecrMask |= Node.DECR_FLAG;
|
||||
}
|
||||
n.putIntProp(Node.INCRDECR_PROP, type);
|
||||
if (post) {
|
||||
incrDecrMask |= Node.POST_FLAG;
|
||||
}
|
||||
n.putIntProp(Node.INCRDECR_PROP, incrDecrMask);
|
||||
return n;
|
||||
}
|
||||
// TODO: This should be a ReferenceError--but that's a runtime
|
||||
|
|
|
@ -1152,7 +1152,7 @@ public class Interpreter
|
|||
|
||||
private int visitIncDec(Node node, Node child, int iCodeTop)
|
||||
{
|
||||
int incrDecrType = node.getExistingIntProp(Node.INCRDECR_PROP);
|
||||
int incrDecrMask = node.getExistingIntProp(Node.INCRDECR_PROP);
|
||||
int childType = child.getType();
|
||||
switch (childType) {
|
||||
case Token.GETVAR : {
|
||||
|
@ -1161,11 +1161,11 @@ public class Interpreter
|
|||
iCodeTop = addIcode(Icode_SCOPE, iCodeTop);
|
||||
stackChange(1);
|
||||
iCodeTop = addStringOp(Icode_PROP_INC_DEC, name, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrType, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrMask, iCodeTop);
|
||||
} else {
|
||||
int i = scriptOrFn.getParamOrVarIndex(name);
|
||||
iCodeTop = addVarOp(Icode_VAR_INC_DEC, i, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrType, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrMask, iCodeTop);
|
||||
stackChange(1);
|
||||
}
|
||||
break;
|
||||
|
@ -1173,7 +1173,7 @@ public class Interpreter
|
|||
case Token.NAME : {
|
||||
String name = child.getString();
|
||||
iCodeTop = addStringOp(Icode_NAME_INC_DEC, name, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrType, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrMask, iCodeTop);
|
||||
stackChange(1);
|
||||
break;
|
||||
}
|
||||
|
@ -1182,7 +1182,7 @@ public class Interpreter
|
|||
iCodeTop = generateICode(object, iCodeTop);
|
||||
String property = object.getNext().getString();
|
||||
iCodeTop = addStringOp(Icode_PROP_INC_DEC, property, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrType, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrMask, iCodeTop);
|
||||
break;
|
||||
}
|
||||
case Token.GETELEM : {
|
||||
|
@ -1191,7 +1191,7 @@ public class Interpreter
|
|||
Node index = object.getNext();
|
||||
iCodeTop = generateICode(index, iCodeTop);
|
||||
iCodeTop = addIcode(Icode_ELEM_INC_DEC, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrType, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrMask, iCodeTop);
|
||||
stackChange(-1);
|
||||
break;
|
||||
}
|
||||
|
@ -1199,7 +1199,7 @@ public class Interpreter
|
|||
Node ref = child.getFirstChild();
|
||||
iCodeTop = generateICode(ref, iCodeTop);
|
||||
iCodeTop = addIcode(Icode_REF_INC_DEC, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrType, iCodeTop);
|
||||
iCodeTop = addByte(incrDecrMask, iCodeTop);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
|
@ -2715,7 +2715,7 @@ switch (op) {
|
|||
case Icode_VAR_INC_DEC : {
|
||||
// indexReg : varindex
|
||||
++stackTop;
|
||||
int type = iCode[pc];
|
||||
int incrDecrMask = iCode[pc];
|
||||
if (!useActivationVars) {
|
||||
stack[stackTop] = DBL_MRK;
|
||||
Object varValue = stack[indexReg];
|
||||
|
@ -2726,14 +2726,14 @@ switch (op) {
|
|||
d = ScriptRuntime.toNumber(varValue);
|
||||
stack[indexReg] = DBL_MRK;
|
||||
}
|
||||
double d2 = (type == Node.PRE_INC || type == Node.POST_INC)
|
||||
double d2 = ((incrDecrMask & Node.DECR_FLAG) == 0)
|
||||
? d + 1.0 : d - 1.0;
|
||||
sDbl[indexReg] = d2;
|
||||
sDbl[stackTop] = (type == Node.POST_INC
|
||||
|| type == Node.POST_DEC) ? d : d2;
|
||||
sDbl[stackTop] = ((incrDecrMask & Node.POST_FLAG) == 0) ? d2 : d;
|
||||
} else {
|
||||
String varName = fnOrScript.argNames[indexReg];
|
||||
stack[stackTop] = ScriptRuntime.nameIncrDecr(scope, varName, type);
|
||||
stack[stackTop] = ScriptRuntime.nameIncrDecr(scope, varName,
|
||||
incrDecrMask);
|
||||
}
|
||||
++pc;
|
||||
continue Loop;
|
||||
|
|
|
@ -94,11 +94,9 @@ public class Node
|
|||
SPECIALCALL_EVAL = 1,
|
||||
SPECIALCALL_WITH = 2;
|
||||
|
||||
public static final int // values for INCRDECR_PROP
|
||||
PRE_INC = 0,
|
||||
PRE_DEC = 1,
|
||||
POST_INC = 2,
|
||||
POST_DEC = 3;
|
||||
public static final int // flags for INCRDECR_PROP
|
||||
DECR_FLAG = 0x1,
|
||||
POST_FLAG = 0x2;
|
||||
|
||||
private static class NumberNode extends Node
|
||||
{
|
||||
|
|
|
@ -1697,7 +1697,7 @@ public class ScriptRuntime {
|
|||
}
|
||||
|
||||
public static Object nameIncrDecr(Scriptable scopeChain, String id,
|
||||
int type)
|
||||
int incrDecrMask)
|
||||
{
|
||||
Scriptable target;
|
||||
Object value;
|
||||
|
@ -1715,11 +1715,12 @@ public class ScriptRuntime {
|
|||
} while (scopeChain != null);
|
||||
throw notFoundError(scopeChain, id);
|
||||
}
|
||||
return doScriptableIncrDecr(target, id, scopeChain, value, type);
|
||||
return doScriptableIncrDecr(target, id, scopeChain, value,
|
||||
incrDecrMask);
|
||||
}
|
||||
|
||||
public static Object propIncrDecr(Object obj, String id,
|
||||
Scriptable scope, int type)
|
||||
Scriptable scope, int incrDecrMask)
|
||||
{
|
||||
Scriptable start = toObject(scope, obj);
|
||||
Scriptable target = start;
|
||||
|
@ -1734,16 +1735,17 @@ public class ScriptRuntime {
|
|||
} while (target != null);
|
||||
return Undefined.instance;
|
||||
}
|
||||
return doScriptableIncrDecr(target, id, start, value, type);
|
||||
return doScriptableIncrDecr(target, id, start, value,
|
||||
incrDecrMask);
|
||||
}
|
||||
|
||||
private static Object doScriptableIncrDecr(Scriptable target,
|
||||
String id,
|
||||
Scriptable protoChainStart,
|
||||
Object value,
|
||||
int type)
|
||||
int incrDecrMask)
|
||||
{
|
||||
boolean post = (type == Node.POST_INC || type == Node.POST_DEC);
|
||||
boolean post = ((incrDecrMask & Node.POST_FLAG) != 0);
|
||||
double number;
|
||||
if (value instanceof Number) {
|
||||
number = ((Number)value).doubleValue();
|
||||
|
@ -1754,7 +1756,7 @@ public class ScriptRuntime {
|
|||
value = new Double(number);
|
||||
}
|
||||
}
|
||||
if (type == Node.PRE_INC || type == Node.POST_INC) {
|
||||
if ((incrDecrMask & Node.DECR_FLAG) == 0) {
|
||||
++number;
|
||||
} else {
|
||||
--number;
|
||||
|
@ -1769,12 +1771,12 @@ public class ScriptRuntime {
|
|||
}
|
||||
|
||||
public static Object elemIncrDecr(Object obj, Object index,
|
||||
Scriptable scope, int type)
|
||||
Scriptable scope, int incrDecrMask)
|
||||
{
|
||||
Object value = getElem(obj, index, scope);
|
||||
if (value == Undefined.instance)
|
||||
return value;
|
||||
boolean post = (type == Node.POST_INC || type == Node.POST_DEC);
|
||||
boolean post = ((incrDecrMask & Node.POST_FLAG) != 0);
|
||||
double number;
|
||||
if (value instanceof Number) {
|
||||
number = ((Number)value).doubleValue();
|
||||
|
@ -1785,7 +1787,7 @@ public class ScriptRuntime {
|
|||
value = new Double(number);
|
||||
}
|
||||
}
|
||||
if (type == Node.PRE_INC || type == Node.POST_INC) {
|
||||
if ((incrDecrMask & Node.DECR_FLAG) == 0) {
|
||||
++number;
|
||||
} else {
|
||||
--number;
|
||||
|
@ -1799,12 +1801,12 @@ public class ScriptRuntime {
|
|||
}
|
||||
}
|
||||
|
||||
public static Object referenceIncrDecr(Object obj, int type)
|
||||
public static Object referenceIncrDecr(Object obj, int incrDecrMask)
|
||||
{
|
||||
Object value = getReference(obj);
|
||||
if (value == Undefined.instance)
|
||||
return value;
|
||||
boolean post = (type == Node.POST_INC || type == Node.POST_DEC);
|
||||
boolean post = ((incrDecrMask & Node.POST_FLAG) != 0);
|
||||
double number;
|
||||
if (value instanceof Number) {
|
||||
number = ((Number)value).doubleValue();
|
||||
|
@ -1815,7 +1817,7 @@ public class ScriptRuntime {
|
|||
value = new Double(number);
|
||||
}
|
||||
}
|
||||
if (type == Node.PRE_INC || type == Node.POST_INC) {
|
||||
if ((incrDecrMask & Node.DECR_FLAG) == 0) {
|
||||
++number;
|
||||
} else {
|
||||
--number;
|
||||
|
|
|
@ -2701,13 +2701,12 @@ class BodyCodegen
|
|||
|
||||
private void visitIncDec(Node node, boolean isInc)
|
||||
{
|
||||
int incrDecrType = node.getExistingIntProp(Node.INCRDECR_PROP);
|
||||
int incrDecrMask = node.getExistingIntProp(Node.INCRDECR_PROP);
|
||||
Node child = node.getFirstChild();
|
||||
switch (child.getType()) {
|
||||
case Token.GETVAR:
|
||||
if (node.getIntProp(Node.ISNUMBER_PROP, -1) != -1) {
|
||||
boolean post = (incrDecrType == Node.POST_INC
|
||||
|| incrDecrType == Node.POST_DEC);
|
||||
boolean post = ((incrDecrMask & Node.POST_FLAG) != 0);
|
||||
OptLocalVariable lVar = OptLocalVariable.get(child);
|
||||
short reg = lVar.getJRegister();
|
||||
cfw.addDLoad(reg);
|
||||
|
@ -2715,9 +2714,7 @@ class BodyCodegen
|
|||
cfw.add(ByteCode.DUP2);
|
||||
}
|
||||
cfw.addPush(1.0);
|
||||
if (incrDecrType == Node.PRE_INC
|
||||
|| incrDecrType == Node.POST_INC)
|
||||
{
|
||||
if ((incrDecrMask & Node.DECR_FLAG) == 0) {
|
||||
cfw.add(ByteCode.DADD);
|
||||
} else {
|
||||
cfw.add(ByteCode.DSUB);
|
||||
|
@ -2728,8 +2725,7 @@ class BodyCodegen
|
|||
cfw.addDStore(reg);
|
||||
break;
|
||||
} else if (hasVarsInRegs) {
|
||||
boolean post = (incrDecrType == Node.POST_INC
|
||||
|| incrDecrType == Node.POST_DEC);
|
||||
boolean post = ((incrDecrMask & Node.POST_FLAG) != 0);
|
||||
OptLocalVariable lVar = OptLocalVariable.get(child);
|
||||
if (lVar == null)
|
||||
lVar = fnCurrent.getVar(child.getString());
|
||||
|
@ -2740,9 +2736,7 @@ class BodyCodegen
|
|||
}
|
||||
addObjectToDouble();
|
||||
cfw.addPush(1.0);
|
||||
if (incrDecrType == Node.PRE_INC
|
||||
|| incrDecrType == Node.POST_INC)
|
||||
{
|
||||
if ((incrDecrMask & Node.DECR_FLAG) == 0) {
|
||||
cfw.add(ByteCode.DADD);
|
||||
} else {
|
||||
cfw.add(ByteCode.DSUB);
|
||||
|
@ -2758,7 +2752,7 @@ class BodyCodegen
|
|||
case Token.NAME:
|
||||
cfw.addALoad(variableObjectLocal);
|
||||
cfw.addPush(child.getString()); // push name
|
||||
cfw.addPush(incrDecrType);
|
||||
cfw.addPush(incrDecrMask);
|
||||
addScriptRuntimeInvoke("nameIncrDecr",
|
||||
"(Lorg/mozilla/javascript/Scriptable;"
|
||||
+"Ljava/lang/String;"
|
||||
|
@ -2769,7 +2763,7 @@ class BodyCodegen
|
|||
generateCodeFromNode(getPropChild, node);
|
||||
generateCodeFromNode(getPropChild.getNext(), node);
|
||||
cfw.addALoad(variableObjectLocal);
|
||||
cfw.addPush(incrDecrType);
|
||||
cfw.addPush(incrDecrMask);
|
||||
addScriptRuntimeInvoke("propIncrDecr",
|
||||
"(Ljava/lang/Object;"
|
||||
+"Ljava/lang/String;"
|
||||
|
@ -2782,7 +2776,7 @@ class BodyCodegen
|
|||
generateCodeFromNode(getElemChild, node);
|
||||
generateCodeFromNode(getElemChild.getNext(), node);
|
||||
cfw.addALoad(variableObjectLocal);
|
||||
cfw.addPush(incrDecrType);
|
||||
cfw.addPush(incrDecrMask);
|
||||
addScriptRuntimeInvoke("elemIncrDecr",
|
||||
"(Ljava/lang/Object;"
|
||||
+"Ljava/lang/Object;"
|
||||
|
@ -2793,7 +2787,7 @@ class BodyCodegen
|
|||
case Token.GET_REF: {
|
||||
Node refChild = child.getFirstChild();
|
||||
generateCodeFromNode(refChild, node);
|
||||
cfw.addPush(incrDecrType);
|
||||
cfw.addPush(incrDecrMask);
|
||||
addScriptRuntimeInvoke(
|
||||
"referenceIncrDecr", "(Ljava/lang/Object;I)Ljava/lang/Object;");
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче