SOURCEFILE bytecode used to restore interpreter source information is replaced by setting cx.interpreterSourceFile at the beginning of Interpreter.interpreter and restoring the old value at the end.

This commit is contained in:
igor%mir2.org 2003-08-05 11:16:14 +00:00
Родитель 0e5cd07030
Коммит fa6d86fba0
1 изменённых файлов: 30 добавлений и 46 удалений

Просмотреть файл

@ -46,9 +46,11 @@ public class Interpreter {
// Additional interpreter-specific codes // Additional interpreter-specific codes
private static final int private static final int
// See comments in Interpreter.interpret in CATCH_ICODE case
CATCH_ICODE = Token.LAST_TOKEN + 1,
// To indicating a line number change in icodes. // To indicating a line number change in icodes.
LINE_ICODE = Token.LAST_TOKEN + 1, LINE_ICODE = Token.LAST_TOKEN + 2,
SOURCEFILE_ICODE = Token.LAST_TOKEN + 2,
// To store shorts and ints inline // To store shorts and ints inline
SHORTNUMBER_ICODE = Token.LAST_TOKEN + 3, SHORTNUMBER_ICODE = Token.LAST_TOKEN + 3,
@ -89,6 +91,7 @@ public class Interpreter {
scriptOrFn = tree; scriptOrFn = tree;
version = cx.getLanguageVersion(); version = cx.getLanguageVersion();
itsData = new InterpreterData(securityDomain); itsData = new InterpreterData(securityDomain);
itsData.itsSourceFile = scriptOrFn.getSourceName();
if (tree instanceof FunctionNode) { if (tree instanceof FunctionNode) {
generateFunctionICode(cx, scope); generateFunctionICode(cx, scope);
return createFunction(cx, scope, itsData, false); return createFunction(cx, scope, itsData, false);
@ -100,8 +103,6 @@ public class Interpreter {
private void generateScriptICode(Context cx, Scriptable scope) private void generateScriptICode(Context cx, Scriptable scope)
{ {
itsSourceFile = scriptOrFn.getSourceName();
itsData.itsSourceFile = itsSourceFile;
debugSource = scriptOrFn.getOriginalSource(); debugSource = scriptOrFn.getOriginalSource();
generateNestedFunctions(cx, scope); generateNestedFunctions(cx, scope);
@ -136,7 +137,6 @@ public class Interpreter {
generateICodeFromTree(theFunction.getLastChild()); generateICodeFromTree(theFunction.getLastChild());
itsData.itsName = theFunction.getFunctionName(); itsData.itsName = theFunction.getFunctionName();
itsData.itsSourceFile = theFunction.getSourceName();
itsData.itsSource = theFunction.getEncodedSource(); itsData.itsSource = theFunction.getEncodedSource();
if (Token.printICode) dumpICode(itsData); if (Token.printICode) dumpICode(itsData);
@ -156,8 +156,8 @@ public class Interpreter {
FunctionNode def = scriptOrFn.getFunctionNode(i); FunctionNode def = scriptOrFn.getFunctionNode(i);
Interpreter jsi = new Interpreter(); Interpreter jsi = new Interpreter();
jsi.scriptOrFn = def; jsi.scriptOrFn = def;
jsi.itsSourceFile = itsSourceFile;
jsi.itsData = new InterpreterData(itsData.securityDomain); jsi.itsData = new InterpreterData(itsData.securityDomain);
jsi.itsData.itsSourceFile = itsData.itsSourceFile;
jsi.itsData.itsCheckThis = def.getCheckThis(); jsi.itsData.itsCheckThis = def.getCheckThis();
jsi.itsInFunctionFlag = true; jsi.itsInFunctionFlag = true;
jsi.debugSource = debugSource; jsi.debugSource = debugSource;
@ -195,7 +195,7 @@ public class Interpreter {
} }
// Add special CATCH to simplify Interpreter.interpret logic // Add special CATCH to simplify Interpreter.interpret logic
// and workaround lack of goto in Java // and workaround lack of goto in Java
theICodeTop = addByte(Token.CATCH, theICodeTop); theICodeTop = addByte(CATCH_ICODE, theICodeTop);
itsData.itsICodeTop = theICodeTop; itsData.itsICodeTop = theICodeTop;
@ -410,14 +410,6 @@ public class Interpreter {
case Token.NEW : case Token.NEW :
case Token.CALL : { case Token.CALL : {
if (itsSourceFile != null
&& (itsData.itsSourceFile == null
|| !itsSourceFile.equals(itsData.itsSourceFile)))
{
itsData.itsSourceFile = itsSourceFile;
}
iCodeTop = addByte(SOURCEFILE_ICODE, iCodeTop);
int childCount = 0; int childCount = 0;
String functionName = null; String functionName = null;
while (child != null) { while (child != null) {
@ -442,7 +434,6 @@ public class Interpreter {
iCodeTop = addByte(type == Token.NEW ? 1 : 0, iCodeTop = addByte(type == Token.NEW ? 1 : 0,
iCodeTop); iCodeTop);
iCodeTop = addShort(itsLineNumber, iCodeTop); iCodeTop = addShort(itsLineNumber, iCodeTop);
iCodeTop = addString(itsSourceFile, iCodeTop);
} else { } else {
iCodeTop = addByte(type, iCodeTop); iCodeTop = addByte(type, iCodeTop);
iCodeTop = addString(functionName, iCodeTop); iCodeTop = addString(functionName, iCodeTop);
@ -458,8 +449,6 @@ public class Interpreter {
iCodeTop = addIndex(childCount, iCodeTop); iCodeTop = addIndex(childCount, iCodeTop);
if (childCount > itsData.itsMaxCalleeArgs) if (childCount > itsData.itsMaxCalleeArgs)
itsData.itsMaxCalleeArgs = childCount; itsData.itsMaxCalleeArgs = childCount;
iCodeTop = addByte(SOURCEFILE_ICODE, iCodeTop);
break; break;
} }
@ -1234,14 +1223,14 @@ public class Interpreter {
return Token.name(icode); return Token.name(icode);
} else { } else {
switch (icode) { switch (icode) {
case LINE_ICODE: return "line"; case CATCH_ICODE: return "catch";
case SOURCEFILE_ICODE: return "sourcefile";
case SHORTNUMBER_ICODE: return "shortnumber";
case INTNUMBER_ICODE: return "intnumber";
case RETURN_UNDEF_ICODE: return "return_undef";
case GOSUB: return "gosub";
case RETSUB: return "retsub";
case END_ICODE: return "end"; case END_ICODE: return "end";
case GOSUB: return "gosub";
case INTNUMBER_ICODE: return "intnumber";
case LINE_ICODE: return "line";
case RETSUB: return "retsub";
case RETURN_UNDEF_ICODE: return "return_undef";
case SHORTNUMBER_ICODE: return "shortnumber";
} }
} }
return "<UNKNOWN ICODE: "+icode+">"; return "<UNKNOWN ICODE: "+icode+">";
@ -1302,11 +1291,9 @@ public class Interpreter {
int callType = iCode[pc] & 0xFF; int callType = iCode[pc] & 0xFF;
boolean isNew = (iCode[pc + 1] != 0); boolean isNew = (iCode[pc + 1] != 0);
int line = getShort(iCode, pc+2); int line = getShort(iCode, pc+2);
String source = strings[getIndex(iCode, pc + 4)]; int count = getIndex(iCode, pc + 4);
int count = getIndex(iCode, pc + 6);
out.println(tname + " " + callType + " " + isNew out.println(tname + " " + callType + " " + isNew
+ " " + count + " " + count + " " + line);
+ " " + line + " " + source);
pc += 8; pc += 8;
break; break;
} }
@ -1414,7 +1401,6 @@ public class Interpreter {
case Token.ENTERWITH : case Token.ENTERWITH :
case Token.LEAVEWITH : case Token.LEAVEWITH :
case Token.RETURN : case Token.RETURN :
case Token.CATCH:
case Token.THROW : case Token.THROW :
case Token.GETTHIS : case Token.GETTHIS :
case Token.SETELEM : case Token.SETELEM :
@ -1460,7 +1446,7 @@ public class Interpreter {
case Token.FALSE : case Token.FALSE :
case Token.TRUE : case Token.TRUE :
case Token.UNDEFINED : case Token.UNDEFINED :
case SOURCEFILE_ICODE : case CATCH_ICODE:
case RETURN_UNDEF_ICODE: case RETURN_UNDEF_ICODE:
case END_ICODE: case END_ICODE:
return 1; return 1;
@ -1488,9 +1474,8 @@ public class Interpreter {
// call type // call type
// is new // is new
// line number // line number
// name string index
// arg count // arg count
return 1 + 1 + 1 + 2 + 2 + 2; return 1 + 1 + 1 + 2 + 2;
case Token.REGEXP : case Token.REGEXP :
// regexp index // regexp index
@ -1703,6 +1688,7 @@ public class Interpreter {
debuggerFrame.onEnter(cx, scope, thisObj, args); debuggerFrame.onEnter(cx, scope, thisObj, args);
} }
String savedSourceFile = cx.interpreterSourceFile;
cx.interpreterSourceFile = idata.itsSourceFile; cx.interpreterSourceFile = idata.itsSourceFile;
Object result = undefined; Object result = undefined;
@ -1729,10 +1715,11 @@ public class Interpreter {
switch (iCode[pc] & 0xff) { switch (iCode[pc] & 0xff) {
// Back indent to ease imlementation reading // Back indent to ease imlementation reading
case Token.CATCH: { case CATCH_ICODE: {
// See comments in generateICodeFromTree: the following code should // The following code should be executed inside try/catch inside main
// be executed inside try/catch inside main loop, not in the loop catch // loop, not in the loop catch block itself to deal withnexceptions
// block itself // from observeInstructionCount. A special bytecode is used only to
// simplify logic.
if (javaException == null) Context.codeBug(); if (javaException == null) Context.codeBug();
int pcNew = -1; int pcNew = -1;
@ -2287,8 +2274,7 @@ public class Interpreter {
int callType = iCode[pc + 1] & 0xFF; int callType = iCode[pc + 1] & 0xFF;
boolean isNew = (iCode[pc + 2] != 0); boolean isNew = (iCode[pc + 2] != 0);
int sourceLine = getShort(iCode, pc + 3); int sourceLine = getShort(iCode, pc + 3);
String sourceName = strings[getIndex(iCode, pc + 5)]; int count = getIndex(iCode, pc + 5);
int count = getIndex(iCode, pc + 7);
stackTop -= count; stackTop -= count;
Object[] outArgs = getArgsArray(stack, sDbl, stackTop + 1, count); Object[] outArgs = getArgsArray(stack, sDbl, stackTop + 1, count);
Object functionThis; Object functionThis;
@ -2306,8 +2292,8 @@ public class Interpreter {
stack[stackTop] = ScriptRuntime.callSpecial( stack[stackTop] = ScriptRuntime.callSpecial(
cx, function, isNew, functionThis, outArgs, cx, function, isNew, functionThis, outArgs,
scope, thisObj, callType, scope, thisObj, callType,
sourceName, sourceLine); idata.itsSourceFile, sourceLine);
pc += 8; pc += 6;
instructionCount = cx.instructionCount; instructionCount = cx.instructionCount;
break; break;
} }
@ -2626,9 +2612,6 @@ public class Interpreter {
pc += 2; pc += 2;
break; break;
} }
case SOURCEFILE_ICODE :
cx.interpreterSourceFile = idata.itsSourceFile;
break;
case LINE_ICODE : { case LINE_ICODE : {
int line = getShort(iCode, pc + 1); int line = getShort(iCode, pc + 1);
cx.interpreterLine = line; cx.interpreterLine = line;
@ -2666,6 +2649,8 @@ public class Interpreter {
} }
} }
cx.interpreterSourceFile = savedSourceFile;
if (debuggerFrame != null) { if (debuggerFrame != null) {
if (javaException != null) { if (javaException != null) {
debuggerFrame.onExit(cx, true, javaException); debuggerFrame.onExit(cx, true, javaException);
@ -2990,7 +2975,7 @@ public class Interpreter {
private static int getJavaCatchPC(byte[] iCode) private static int getJavaCatchPC(byte[] iCode)
{ {
int pc = iCode.length - 1; int pc = iCode.length - 1;
if ((iCode[pc] & 0xFF) != Token.CATCH) Context.codeBug(); if ((iCode[pc] & 0xFF) != CATCH_ICODE) Context.codeBug();
return pc; return pc;
} }
@ -3000,7 +2985,6 @@ public class Interpreter {
private ScriptOrFnNode scriptOrFn; private ScriptOrFnNode scriptOrFn;
private int itsStackDepth = 0; private int itsStackDepth = 0;
private int itsWithDepth = 0; private int itsWithDepth = 0;
private String itsSourceFile;
private int itsLineNumber = 0; private int itsLineNumber = 0;
private LabelTable itsLabels = new LabelTable(); private LabelTable itsLabels = new LabelTable();
private int itsDoubleTableTop; private int itsDoubleTableTop;