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

Side by Side Diff: runtime/vm/flow_graph_builder.cc

Issue 9615025: Implement '==', '!=' and instanceof (without code generation). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | runtime/vm/flow_graph_compiler_x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "vm/ast_printer.h" 7 #include "vm/ast_printer.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/intermediate_language.h" 9 #include "vm/intermediate_language.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void EffectGraphVisitor::VisitStringConcatNode(StringConcatNode* node) { 243 void EffectGraphVisitor::VisitStringConcatNode(StringConcatNode* node) {
244 Bailout("EffectGraphVisitor::VisitStringConcatNode"); 244 Bailout("EffectGraphVisitor::VisitStringConcatNode");
245 } 245 }
246 246
247 247
248 // <Expression> :: Comparison { kind: Token::Kind 248 // <Expression> :: Comparison { kind: Token::Kind
249 // left: <Expression> 249 // left: <Expression>
250 // right: <Expression> } 250 // right: <Expression> }
251 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { 251 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) {
252 if (Token::IsInstanceofOperator(node->kind())) { 252 if (Token::IsInstanceofOperator(node->kind())) {
253 Bailout("instanceof not yet implemented"); 253 ArgumentGraphVisitor for_left_value(owner(), temp_index());
254 } else if ((node->kind() == Token::kEQ) || (node->kind() == Token::kNE)) { 254 node->left()->Visit(&for_left_value);
255 Bailout("'==' or '!=' comparison not yet implemented"); 255 Append(for_left_value);
256 InstanceOfComp* instance_of = new InstanceOfComp(
257 node->id(),
258 node->token_index(),
259 for_left_value.value(),
260 node->right()->AsTypeNode()->type(),
261 (node->kind() == Token::kISNOT));
262 ReturnComputation(instance_of);
263 return;
256 } 264 }
257 if ((node->kind() == Token::kEQ_STRICT) || 265 if ((node->kind() == Token::kEQ_STRICT) ||
258 (node->kind() == Token::kNE_STRICT)) { 266 (node->kind() == Token::kNE_STRICT)) {
259 ValueGraphVisitor for_left_value(owner(), temp_index()); 267 ValueGraphVisitor for_left_value(owner(), temp_index());
260 node->left()->Visit(&for_left_value); 268 node->left()->Visit(&for_left_value);
261 Append(for_left_value); 269 Append(for_left_value);
262 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index()); 270 ValueGraphVisitor for_right_value(owner(), for_left_value.temp_index());
263 node->right()->Visit(&for_right_value); 271 node->right()->Visit(&for_right_value);
264 Append(for_right_value); 272 Append(for_right_value);
265 StrictCompareComp* comp = new StrictCompareComp( 273 StrictCompareComp* comp = new StrictCompareComp(
266 node->kind(), for_left_value.value(), for_right_value.value()); 274 node->kind(), for_left_value.value(), for_right_value.value());
267 ReturnComputation(comp); 275 ReturnComputation(comp);
268 return; 276 return;
269 } 277 }
270 278
271 ArgumentGraphVisitor for_left_value(owner(), temp_index()); 279 ArgumentGraphVisitor for_left_value(owner(), temp_index());
272 node->left()->Visit(&for_left_value); 280 node->left()->Visit(&for_left_value);
273 Append(for_left_value); 281 Append(for_left_value);
274 ArgumentGraphVisitor for_right_value(owner(), for_left_value.temp_index()); 282 ArgumentGraphVisitor for_right_value(owner(), for_left_value.temp_index());
275 node->right()->Visit(&for_right_value); 283 node->right()->Visit(&for_right_value);
276 Append(for_right_value); 284 Append(for_right_value);
277 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2); 285 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2);
278 arguments->Add(for_left_value.value()); 286 arguments->Add(for_left_value.value());
279 arguments->Add(for_right_value.value()); 287 arguments->Add(for_right_value.value());
280 const String& name = String::ZoneHandle(String::NewSymbol(node->Name())); 288 // 'kNE' is not overloadable, must implement as kEQ and negation.
281 InstanceCallComp* call = 289 // Boolean negation '!' cannot be overloaded neither.
282 new InstanceCallComp(node->id(), node->token_index(), name, 290 if (node->kind() == Token::kNE) {
283 arguments, Array::ZoneHandle(), 2); 291 const String& name = String::ZoneHandle(String::NewSymbol("=="));
284 ReturnComputation(call); 292 InstanceCallComp* call_equal =
293 new InstanceCallComp(node->id(), node->token_index(), name,
294 arguments, Array::ZoneHandle(), 2);
295 AddInstruction(new BindInstr(temp_index(), call_equal));
296 Value* eq_result = new TempVal(temp_index());
297 if (FLAG_enable_type_checks) {
298 Bailout("GenerateConditionTypeCheck in kNE");
299 }
300 BooleanNegateComp* negate = new BooleanNegateComp(eq_result);
301 ReturnComputation(negate);
302 } else {
303 const String& name = String::ZoneHandle(String::NewSymbol(node->Name()));
304 InstanceCallComp* call =
305 new InstanceCallComp(node->id(), node->token_index(), name,
306 arguments, Array::ZoneHandle(), 2);
307 ReturnComputation(call);
308 }
285 } 309 }
286 310
287 311
288 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) { 312 void EffectGraphVisitor::VisitUnaryOpNode(UnaryOpNode* node) {
289 // "!" cannot be overloaded, therefore do not call operator. 313 // "!" cannot be overloaded, therefore do not call operator.
290 if (node->kind() == Token::kNOT) { 314 if (node->kind() == Token::kNOT) {
291 Bailout("EffectGraphVisitor::VisitUnaryOpNode NOT"); 315 ValueGraphVisitor for_value(owner(), temp_index());
316 node->operand()->Visit(&for_value);
317 Append(for_value);
318 if (FLAG_enable_type_checks) {
319 Bailout("GenerateConditionTypeCheck in kNOT");
320 }
321 BooleanNegateComp* negate = new BooleanNegateComp(for_value.value());
322 ReturnComputation(negate);
323 return;
292 } 324 }
293 ArgumentGraphVisitor for_value(owner(), temp_index()); 325 ArgumentGraphVisitor for_value(owner(), temp_index());
294 node->operand()->Visit(&for_value); 326 node->operand()->Visit(&for_value);
295 Append(for_value); 327 Append(for_value);
296 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); 328 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1);
297 arguments->Add(for_value.value()); 329 arguments->Add(for_value.value());
298 const String& name = 330 const String& name =
299 String::ZoneHandle(String::NewSymbol((node->kind() == Token::kSUB) 331 String::ZoneHandle(String::NewSymbol((node->kind() == Token::kSUB)
300 ? Token::Str(Token::kNEGATE) 332 ? Token::Str(Token::kNEGATE)
301 : node->Name())); 333 : node->Name()));
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 963
932 void FlowGraphPrinter::VisitInstanceSetter(InstanceSetterComp* comp) { 964 void FlowGraphPrinter::VisitInstanceSetter(InstanceSetterComp* comp) {
933 OS::Print("InstanceSetter("); 965 OS::Print("InstanceSetter(");
934 comp->receiver()->Accept(this); 966 comp->receiver()->Accept(this);
935 OS::Print(", "); 967 OS::Print(", ");
936 comp->value()->Accept(this); 968 comp->value()->Accept(this);
937 OS::Print(")"); 969 OS::Print(")");
938 } 970 }
939 971
940 972
973 void FlowGraphPrinter::VisitBooleanNegate(BooleanNegateComp* comp) {
974 OS::Print("! ");
975 comp->value()->Accept(this);
976 }
977
978
979 void FlowGraphPrinter::VisitInstanceOf(InstanceOfComp* comp) {
980 comp->value()->Accept(this);
981 OS::Print(" %s %s",
982 comp->negate_result() ? "ISNOT" : "IS",
983 String::Handle(comp->type().Name()).ToCString());
984 }
985
941 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) { 986 void FlowGraphPrinter::VisitJoinEntry(JoinEntryInstr* instr) {
942 OS::Print("%2d: [join]", instr->block_number()); 987 OS::Print("%2d: [join]", instr->block_number());
943 } 988 }
944 989
945 990
946 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) { 991 void FlowGraphPrinter::VisitTargetEntry(TargetEntryInstr* instr) {
947 OS::Print("%2d: [target]", instr->block_number()); 992 OS::Print("%2d: [target]", instr->block_number());
948 } 993 }
949 994
950 995
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 char* chars = reinterpret_cast<char*>( 1062 char* chars = reinterpret_cast<char*>(
1018 Isolate::Current()->current_zone()->Allocate(len)); 1063 Isolate::Current()->current_zone()->Allocate(len));
1019 OS::SNPrint(chars, len, kFormat, function_name, reason); 1064 OS::SNPrint(chars, len, kFormat, function_name, reason);
1020 const Error& error = Error::Handle( 1065 const Error& error = Error::Handle(
1021 LanguageError::New(String::Handle(String::New(chars)))); 1066 LanguageError::New(String::Handle(String::New(chars))));
1022 Isolate::Current()->long_jump_base()->Jump(1, error); 1067 Isolate::Current()->long_jump_base()->Jump(1, error);
1023 } 1068 }
1024 1069
1025 1070
1026 } // namespace dart 1071 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_compiler_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698