Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: src/ast.cc

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: internalizing better Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ast.h" 5 #include "ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "builtins.h" 8 #include "builtins.h"
9 #include "code-stubs.h" 9 #include "code-stubs.h"
10 #include "contexts.h" 10 #include "contexts.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 50
51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const { 51 bool Expression::IsUndefinedLiteral(Isolate* isolate) const {
52 const VariableProxy* var_proxy = AsVariableProxy(); 52 const VariableProxy* var_proxy = AsVariableProxy();
53 if (var_proxy == NULL) return false; 53 if (var_proxy == NULL) return false;
54 Variable* var = var_proxy->var(); 54 Variable* var = var_proxy->var();
55 // The global identifier "undefined" is immutable. Everything 55 // The global identifier "undefined" is immutable. Everything
56 // else could be reassigned. 56 // else could be reassigned.
57 return var != NULL && var->location() == Variable::UNALLOCATED && 57 return var != NULL && var->location() == Variable::UNALLOCATED &&
58 String::Equals(var_proxy->name(), 58 ParserSymbolTable::SymbolMatches(var_proxy->raw_name(), "undefined", 9);
59 isolate->factory()->undefined_string());
60 } 59 }
61 60
62 61
63 VariableProxy::VariableProxy(Zone* zone, Variable* var, int position) 62 VariableProxy::VariableProxy(Zone* zone, Variable* var, int position)
64 : Expression(zone, position), 63 : Expression(zone, position),
65 name_(var->name()), 64 raw_name_(var->raw_name()),
66 var_(NULL), // Will be set by the call to BindTo. 65 var_(NULL), // Will be set by the call to BindTo.
67 is_this_(var->is_this()), 66 is_this_(var->is_this()),
68 is_trivial_(false), 67 is_trivial_(false),
69 is_lvalue_(false), 68 is_lvalue_(false),
70 interface_(var->interface()) { 69 interface_(var->interface()) {
71 BindTo(var); 70 BindTo(var);
72 } 71 }
73 72
74 73
75 VariableProxy::VariableProxy(Zone* zone, 74 VariableProxy::VariableProxy(Zone* zone,
76 Handle<String> name, 75 ParserSymbolTable::Symbol* raw_name,
77 bool is_this, 76 bool is_this,
78 Interface* interface, 77 Interface* interface,
79 int position) 78 int position)
80 : Expression(zone, position), 79 : Expression(zone, position),
81 name_(name), 80 raw_name_(raw_name),
82 var_(NULL), 81 var_(NULL),
83 is_this_(is_this), 82 is_this_(is_this),
84 is_trivial_(false), 83 is_trivial_(false),
85 is_lvalue_(false), 84 is_lvalue_(false),
86 interface_(interface) { 85 interface_(interface) {
87 // Names must be canonicalized for fast equality checks.
88 ASSERT(name->IsInternalizedString());
89 } 86 }
90 87
91 88
92 void VariableProxy::BindTo(Variable* var) { 89 void VariableProxy::BindTo(Variable* var) {
93 ASSERT(var_ == NULL); // must be bound only once 90 ASSERT(var_ == NULL); // must be bound only once
94 ASSERT(var != NULL); // must bind 91 ASSERT(var != NULL); // must bind
95 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface())); 92 ASSERT(!FLAG_harmony_modules || interface_->IsUnified(var->interface()));
96 ASSERT((is_this() && var->is_this()) || name_.is_identical_to(var->name())); 93 ASSERT((is_this() && var->is_this()) || raw_name_ == var->raw_name());
97 // Ideally CONST-ness should match. However, this is very hard to achieve 94 // Ideally CONST-ness should match. However, this is very hard to achieve
98 // because we don't know the exact semantics of conflicting (const and 95 // because we don't know the exact semantics of conflicting (const and
99 // non-const) multiple variable declarations, const vars introduced via 96 // non-const) multiple variable declarations, const vars introduced via
100 // eval() etc. Const-ness and variable declarations are a complete mess 97 // eval() etc. Const-ness and variable declarations are a complete mess
101 // in JS. Sigh... 98 // in JS. Sigh...
102 var_ = var; 99 var_ = var;
103 var->set_is_used(true); 100 var->set_is_used(true);
104 } 101 }
105 102
106 103
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 175 }
179 } 176 }
180 } 177 }
181 178
182 179
183 ObjectLiteralProperty::ObjectLiteralProperty( 180 ObjectLiteralProperty::ObjectLiteralProperty(
184 Zone* zone, Literal* key, Expression* value) { 181 Zone* zone, Literal* key, Expression* value) {
185 emit_store_ = true; 182 emit_store_ = true;
186 key_ = key; 183 key_ = key;
187 value_ = value; 184 value_ = value;
188 Handle<Object> k = key->value(); 185 if (ParserSymbolTable::SymbolMatches(key->string(), "__proto__", 9)) {
189 if (k->IsInternalizedString() &&
190 String::Equals(Handle<String>::cast(k),
191 zone->isolate()->factory()->proto_string())) {
192 kind_ = PROTOTYPE; 186 kind_ = PROTOTYPE;
193 } else if (value_->AsMaterializedLiteral() != NULL) { 187 } else if (value_->AsMaterializedLiteral() != NULL) {
194 kind_ = MATERIALIZED_LITERAL; 188 kind_ = MATERIALIZED_LITERAL;
195 } else if (value_->AsLiteral() != NULL) { 189 } else if (value_->AsLiteral() != NULL) {
196 kind_ = CONSTANT; 190 kind_ = CONSTANT;
197 } else { 191 } else {
198 kind_ = COMPUTED; 192 kind_ = COMPUTED;
199 } 193 }
200 } 194 }
201 195
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 DONT_CACHE_NODE(ModuleLiteral) 1109 DONT_CACHE_NODE(ModuleLiteral)
1116 1110
1117 1111
1118 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) { 1112 void AstConstructionVisitor::VisitCallRuntime(CallRuntime* node) {
1119 increase_node_count(); 1113 increase_node_count();
1120 if (node->is_jsruntime()) { 1114 if (node->is_jsruntime()) {
1121 // Don't try to inline JS runtime calls because we don't (currently) even 1115 // Don't try to inline JS runtime calls because we don't (currently) even
1122 // optimize them. 1116 // optimize them.
1123 add_flag(kDontInline); 1117 add_flag(kDontInline);
1124 } else if (node->function()->intrinsic_type == Runtime::INLINE && 1118 } else if (node->function()->intrinsic_type == Runtime::INLINE &&
1125 (node->name()->IsOneByteEqualTo( 1119 (ParserSymbolTable::SymbolMatches(node->raw_name(),
1126 STATIC_ASCII_VECTOR("_ArgumentsLength")) || 1120 "_ArgumentsLength", 16) ||
1127 node->name()->IsOneByteEqualTo(STATIC_ASCII_VECTOR("_Arguments")))) { 1121 ParserSymbolTable::SymbolMatches(node->raw_name(), "_Arguments",
1122 9))) {
1128 // Don't inline the %_ArgumentsLength or %_Arguments because their 1123 // Don't inline the %_ArgumentsLength or %_Arguments because their
1129 // implementation will not work. There is no stack frame to get them 1124 // implementation will not work. There is no stack frame to get them
1130 // from. 1125 // from.
1131 add_flag(kDontInline); 1126 add_flag(kDontInline);
1132 } 1127 }
1133 } 1128 }
1134 1129
1135 #undef REGULAR_NODE 1130 #undef REGULAR_NODE
1136 #undef DONT_OPTIMIZE_NODE 1131 #undef DONT_OPTIMIZE_NODE
1137 #undef DONT_SELFOPTIMIZE_NODE 1132 #undef DONT_SELFOPTIMIZE_NODE
(...skipping 11 matching lines...) Expand all
1149 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value()); 1144 OS::SNPrintF(buffer, "%d", Smi::cast(*value_)->value());
1150 str = arr; 1145 str = arr;
1151 } else { 1146 } else {
1152 str = DoubleToCString(value_->Number(), buffer); 1147 str = DoubleToCString(value_->Number(), buffer);
1153 } 1148 }
1154 return isolate_->factory()->NewStringFromAsciiChecked(str); 1149 return isolate_->factory()->NewStringFromAsciiChecked(str);
1155 } 1150 }
1156 1151
1157 1152
1158 } } // namespace v8::internal 1153 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698