Changeset 34319 in webkit for trunk/JavaScriptCore/VM
- Timestamp:
- Jun 2, 2008, 1:45:13 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/VM
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/CodeBlock.h
r33979 r34319 123 123 { 124 124 } 125 126 Vector<Identifier> declaredVariableNames;127 Vector<Identifier> declaredFunctionNames;128 125 }; 129 126 -
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 -
trunk/JavaScriptCore/VM/CodeGenerator.h
r34250 r34319 78 78 79 79 CodeGenerator(ProgramNode*, const Debugger*, const ScopeChain&, SymbolTable*, CodeBlock*, VarStack&, FunctionStack&, bool canCreateGlobals); 80 CodeGenerator(FunctionBodyNode*, const Debugger*, const ScopeChain&, SymbolTable*, CodeBlock* , VarStack&, FunctionStack&, Vector<Identifier>& parameters);81 CodeGenerator(EvalNode*, const Debugger*, const ScopeChain&, SymbolTable*, EvalCodeBlock* , VarStack&, FunctionStack& functionStack);80 CodeGenerator(FunctionBodyNode*, const Debugger*, const ScopeChain&, SymbolTable*, CodeBlock*); 81 CodeGenerator(EvalNode*, const Debugger*, const ScopeChain&, SymbolTable*, EvalCodeBlock*); 82 82 83 83 ~CodeGenerator(); … … 107 107 108 108 // Returns the register storing "this" 109 RegisterID* thisRegister() { return m_thisRegister; }109 RegisterID* thisRegister() { return &m_thisRegister; } 110 110 111 111 bool isLocalConstant(const Identifier&); … … 352 352 353 353 HashSet<RefPtr<UString::Rep>, IdentifierRepHash> m_functions; 354 static RegisterID* programCodeThis(); 355 RegisterID* m_thisRegister; 354 RegisterID m_thisRegister; 356 355 SegmentedVector<RegisterID, 512> m_locals; 357 356 SegmentedVector<RegisterID, 512> m_temporaries; -
trunk/JavaScriptCore/VM/Machine.cpp
r34303 r34319 763 763 } 764 764 765 for (Vector<Identifier>::const_iterator iter = codeBlock->declaredVariableNames.begin(); iter != codeBlock->declaredVariableNames.end(); ++iter) { 766 Identifier ident = *iter; 767 765 const Node::VarStack& varStack = codeBlock->ownerNode->varStack(); 766 Node::VarStack::const_iterator varStackEnd = varStack.end(); 767 for (Node::VarStack::const_iterator it = varStack.begin(); it != varStackEnd; ++it) { 768 const Identifier& ident = (*it).first; 768 769 if (!variableObject->hasProperty(exec, ident)) 769 770 variableObject->put(exec, ident, jsUndefined()); 770 771 } 771 772 772 ASSERT(codeBlock->functions.size() == codeBlock->declaredFunctionNames.size()); 773 for (size_t i = 0; i < codeBlock->functions.size(); ++i) 774 variableObject->put(exec, codeBlock->declaredFunctionNames[i], codeBlock->functions[i]->makeFunction(exec, scopeChain)); 773 const Node::FunctionStack& functionStack = codeBlock->ownerNode->functionStack(); 774 Node::FunctionStack::const_iterator functionStackEnd = functionStack.end(); 775 for (Node::FunctionStack::const_iterator it = functionStack.begin(); it != functionStackEnd; ++it) 776 variableObject->put(exec, (*it)->m_ident, (*it)->makeFunction(exec, scopeChain)); 775 777 776 778 size_t oldSize = registerFile->size();
Note:
See TracChangeset
for help on using the changeset viewer.