Changeset 34319 in webkit for trunk/JavaScriptCore/VM/CodeGenerator.cpp
- Timestamp:
- Jun 2, 2008, 1:45:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/CodeGenerator.cpp
r34303 r34319 130 130 { 131 131 m_codeBlock->numLocals = m_codeBlock->numVars + m_codeBlock->numParameters; 132 m_codeBlock->thisRegister = m_ codeType == FunctionCode ? -m_codeBlock->numLocals : Machine::ProgramCodeThisRegister;132 m_codeBlock->thisRegister = m_thisRegister.index(); 133 133 if (m_shouldEmitDebugHooks) 134 134 m_codeBlock->needsFullScopeChain = true; … … 143 143 #endif 144 144 145 // Remove "this" from symbol table so it does not appear as a global object property at runtime. 146 symbolTable().remove(m_propertyNames->thisIdentifier.ustring().rep()); 145 m_scopeNode->children().shrinkCapacity(0); 146 if (m_codeType != EvalCode) { // eval code needs to hang on to its declaration stacks to keep declaration info alive until Machine::execute time. 147 m_scopeNode->varStack().shrinkCapacity(0); 148 m_scopeNode->functionStack().shrinkCapacity(0); 149 } 147 150 } 148 151 … … 164 167 r0 = &m_locals[localsIndex(index)]; 165 168 return result.second; 166 }167 168 RegisterID* CodeGenerator::programCodeThis()169 {170 static RegisterID programThis(Machine::ProgramCodeThisRegister);171 return &programThis;172 169 } 173 170 … … 178 175 , m_scopeNode(programNode) 179 176 , m_codeBlock(codeBlock) 177 , m_thisRegister(Machine::ProgramCodeThisRegister) 180 178 , m_finallyDepth(0) 181 179 , m_dynamicScopeDepth(0) … … 184 182 , m_nextVar(-1) 185 183 , m_propertyNames(CommonIdentifiers::shared()) 186 187 184 { 188 185 // Global code can inherit previously defined symbols. 189 186 int size = symbolTable->size() + 1; // + 1 slot for "this" 190 m_thisRegister = programCodeThis();191 187 192 188 // Add previously defined symbols to bookkeeping. … … 202 198 203 199 ExecState* exec = globalObject->globalExec(); 200 201 // FIXME: Move the execution-related parts of this code to Machine::execute. 204 202 205 203 if (canCreateVariables) { 206 204 for (size_t i = 0; i < functionStack.size(); ++i) { 207 FuncDeclNode* funcDecl = functionStack[i] ;205 FuncDeclNode* funcDecl = functionStack[i].get(); 208 206 globalObject->removeDirect(funcDecl->m_ident); // Make sure our new function is not shadowed by an old property. 209 207 emitNewFunction(addVar(funcDecl->m_ident, false), funcDecl); … … 216 214 } else { 217 215 for (size_t i = 0; i < functionStack.size(); ++i) { 218 FuncDeclNode* funcDecl = functionStack[i] ;216 FuncDeclNode* funcDecl = functionStack[i].get(); 219 217 globalObject->putWithAttributes(exec, funcDecl->m_ident, funcDecl->makeFunction(exec, scopeChain.node()), DontDelete); 220 218 } … … 230 228 } 231 229 232 CodeGenerator::CodeGenerator(FunctionBodyNode* functionBody, const Debugger* debugger, const ScopeChain& scopeChain, SymbolTable* symbolTable, CodeBlock* codeBlock , VarStack& varStack, FunctionStack& functionStack, Vector<Identifier>& parameters)230 CodeGenerator::CodeGenerator(FunctionBodyNode* functionBody, const Debugger* debugger, const ScopeChain& scopeChain, SymbolTable* symbolTable, CodeBlock* codeBlock) 233 231 : m_shouldEmitDebugHooks(!!debugger) 234 232 , m_scopeChain(&scopeChain) … … 236 234 , m_scopeNode(functionBody) 237 235 , m_codeBlock(codeBlock) 238 , m_thisRegister(0)239 236 , m_finallyDepth(0) 240 237 , m_dynamicScopeDepth(0) … … 244 241 , m_propertyNames(CommonIdentifiers::shared()) 245 242 { 243 const Node::FunctionStack& functionStack = functionBody->functionStack(); 246 244 for (size_t i = 0; i < functionStack.size(); ++i) { 247 FuncDeclNode* funcDecl = functionStack[i] ;245 FuncDeclNode* funcDecl = functionStack[i].get(); 248 246 const Identifier& ident = funcDecl->m_ident; 249 247 … … 252 250 } 253 251 252 const Node::VarStack& varStack = functionBody->varStack(); 254 253 for (size_t i = 0; i < varStack.size(); ++i) { 255 254 const Identifier& ident = varStack[i].first; … … 262 261 } 263 262 264 m_nextParameter = m_nextVar - parameters.size(); 265 m_locals.resize(localsIndex(m_nextParameter) + 1); 266 267 m_thisRegister = addParameter(m_propertyNames->thisIdentifier); 268 for (size_t i = 0; i < parameters.size(); ++i) { 263 Vector<Identifier>& parameters = functionBody->parameters(); 264 m_nextParameter = m_nextVar - parameters.size(); // parameters are allocated prior to vars 265 m_locals.resize(localsIndex(m_nextParameter) + 1); // localsIndex of 0 => m_locals size of 1 266 267 // Add "this" as a parameter 268 m_thisRegister.setIndex(m_nextParameter); 269 ++m_nextParameter; 270 ++m_codeBlock->numParameters; 271 272 for (size_t i = 0; i < parameters.size(); ++i) 269 273 addParameter(parameters[i]); 270 } 271 } 272 273 CodeGenerator::CodeGenerator(EvalNode* evalNode, const Debugger* debugger, const ScopeChain& scopeChain, SymbolTable* symbolTable, EvalCodeBlock* codeBlock, VarStack& varStack, FunctionStack& functionStack) 274 } 275 276 CodeGenerator::CodeGenerator(EvalNode* evalNode, const Debugger* debugger, const ScopeChain& scopeChain, SymbolTable* symbolTable, EvalCodeBlock* codeBlock) 274 277 : m_shouldEmitDebugHooks(!!debugger) 275 278 , m_scopeChain(&scopeChain) … … 277 280 , m_scopeNode(evalNode) 278 281 , m_codeBlock(codeBlock) 279 , m_thisRegister( 0)282 , m_thisRegister(Machine::ProgramCodeThisRegister) 280 283 , m_finallyDepth(0) 281 284 , m_dynamicScopeDepth(0) … … 285 288 , m_propertyNames(CommonIdentifiers::shared()) 286 289 { 287 addVar(m_propertyNames->thisIdentifier, m_thisRegister, false); 288 289 for (size_t i = 0; i < varStack.size(); ++i) 290 codeBlock->declaredVariableNames.append(varStack[i].first); 291 292 for (size_t i = 0; i < functionStack.size(); ++i) { 293 FuncDeclNode* funcDecl = functionStack[i]; 294 codeBlock->declaredFunctionNames.append(funcDecl->m_ident); 295 addConstant(funcDecl); 296 } 290 m_codeBlock->numVars = 1; // Allocate space for "this" 297 291 } 298 292 … … 325 319 m_codeBlock->needsFullScopeChain = true; 326 320 327 if (!shouldOptimizeLocals() && ident != m_propertyNames->thisIdentifier) 321 if (ident == m_propertyNames->thisIdentifier) 322 return &m_thisRegister; 323 324 if (!shouldOptimizeLocals()) 328 325 return 0; 329 326
Note:
See TracChangeset
for help on using the changeset viewer.