Bug 752758 - Separate TreeContext and BytecodeEmitter. r=bhackett.

This commit is contained in:
Nicholas Nethercote
2012-05-14 16:08:32 -07:00
parent df0979f7d6
commit 3777d53c9a
17 changed files with 709 additions and 692 deletions

View File

@@ -127,8 +127,14 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
TokenStream &tokenStream = parser.tokenStream;
BytecodeEmitter bce(&parser, tokenStream.getLineno());
if (!bce.init(cx, TreeContext::USED_AS_TREE_CONTEXT))
SharedContext sc(cx);
TreeContext tc(&parser, &sc);
if (!tc.init(cx))
return NULL;
BytecodeEmitter bce(&parser, &sc, tokenStream.getLineno());
if (!bce.init())
return NULL;
Probes::compileScriptBegin(cx, filename, lineno);
@@ -145,17 +151,17 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
RootedVar<JSScript*> script(cx);
GlobalScope globalScope(cx, globalObj);
bce.flags |= tcflags;
bce.setScopeChain(scopeChain);
bce.sc->flags |= tcflags;
bce.sc->setScopeChain(scopeChain);
bce.globalScope = &globalScope;
if (!SetStaticLevel(&bce, staticLevel))
if (!SetStaticLevel(bce.sc, staticLevel))
goto out;
/* If this is a direct call to eval, inherit the caller's strictness. */
if (callerFrame &&
callerFrame->isScriptFrame() &&
callerFrame->script()->strictModeCode) {
bce.flags |= TCF_STRICT_MODE_CODE;
bce.sc->flags |= TCF_STRICT_MODE_CODE;
tokenStream.setStrictMode();
}
@@ -198,9 +204,9 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
* generate our script-body blockid since we aren't calling Statements.
*/
uint32_t bodyid;
if (!GenerateBlockId(&bce, bodyid))
if (!GenerateBlockId(bce.sc, bodyid))
goto out;
bce.bodyid = bodyid;
bce.sc->bodyid = bodyid;
#if JS_HAS_XML_SUPPORT
pn = NULL;
@@ -222,7 +228,6 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
pn = parser.statement();
if (!pn)
goto out;
JS_ASSERT(!bce.blockNode);
if (inDirectivePrologue && !parser.recognizeDirectivePrologue(pn, &inDirectivePrologue))
goto out;
@@ -232,7 +237,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
if (!AnalyzeFunctions(bce.parser))
goto out;
bce.functionList = NULL;
bce.sc->functionList = NULL;
if (!EmitTree(cx, &bce, pn))
goto out;
@@ -296,19 +301,25 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
TokenStream &tokenStream = parser.tokenStream;
BytecodeEmitter funbce(&parser, tokenStream.getLineno());
if (!funbce.init(cx, TreeContext::USED_AS_TREE_CONTEXT))
SharedContext funsc(cx);
TreeContext funtc(&parser, &funsc);
if (!funtc.init(cx))
return NULL;
BytecodeEmitter funbce(&parser, &funsc, tokenStream.getLineno());
if (!funbce.init())
return false;
funbce.flags |= TCF_IN_FUNCTION;
funbce.setFunction(fun);
funbce.bindings.transfer(cx, bindings);
fun->setArgCount(funbce.bindings.numArgs());
if (!GenerateBlockId(&funbce, funbce.bodyid))
funsc.flags |= TCF_IN_FUNCTION;
funsc.setFunction(fun);
funsc.bindings.transfer(cx, bindings);
fun->setArgCount(funsc.bindings.numArgs());
if (!GenerateBlockId(&funsc, funsc.bodyid))
return false;
/* FIXME: make Function format the source for a function definition. */
ParseNode *fn = FunctionNode::create(PNK_NAME, funbce.parser);
ParseNode *fn = FunctionNode::create(PNK_NAME, &parser);
if (fn) {
fn->pn_body = NULL;
fn->pn_cookie.makeFree();
@@ -320,11 +331,11 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
* allocated from cx->tempLifoAlloc by DefineArg.
*/
BindingNames names(cx);
if (!funbce.bindings.getLocalNameArray(cx, &names)) {
if (!funsc.bindings.getLocalNameArray(cx, &names)) {
fn = NULL;
} else {
for (unsigned i = 0; i < nargs; i++) {
if (!DefineArg(fn, names[i].maybeAtom, i, funbce.parser)) {
if (!DefineArg(fn, names[i].maybeAtom, i, &parser)) {
fn = NULL;
break;
}
@@ -343,10 +354,10 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
if (!tokenStream.matchToken(TOK_EOF)) {
parser.reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
pn = NULL;
} else if (!FoldConstants(cx, pn, funbce.parser)) {
} else if (!FoldConstants(cx, pn, &parser)) {
/* FoldConstants reported the error already. */
pn = NULL;
} else if (!AnalyzeFunctions(funbce.parser)) {
} else if (!AnalyzeFunctions(&parser)) {
pn = NULL;
} else {
if (fn->pn_body) {