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

Side by Side Diff: pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart

Issue 737353002: cps-ir: Implement boolean conversion in and use it to implement '&&', '||', and '?:'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library tree_ir_builder; 5 library tree_ir_builder;
6 6
7 import '../dart2jslib.dart' as dart2js;
8 import '../dart_types.dart'; 7 import '../dart_types.dart';
9 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir;
11 import 'tree_ir_nodes.dart'; 10 import 'tree_ir_nodes.dart';
11 import 'package:compiler/src/js_backend/codegen/unsugar.dart'
12 as js_cps_ir show Boolify;
sigurdm 2014/11/20 12:47:28 package import
13 import 'package:compiler/src/constants/expressions.dart';
14 import 'package:compiler/src/constants/values.dart';
15 import 'package:compiler/src/common.dart' as dart2js;
12 16
13 /** 17 /**
14 * Builder translates from CPS-based IR to direct-style Tree. 18 * Builder translates from CPS-based IR to direct-style Tree.
15 * 19 *
16 * A call `Invoke(fun, cont, args)`, where cont is a singly-referenced 20 * A call `Invoke(fun, cont, args)`, where cont is a singly-referenced
17 * non-exit continuation `Cont(v, body)` is translated into a direct-style call 21 * non-exit continuation `Cont(v, body)` is translated into a direct-style call
18 * whose value is bound in the continuation body: 22 * whose value is bound in the continuation body:
19 * 23 *
20 * `LetVal(v, Invoke(fun, args), body)` 24 * `LetVal(v, Invoke(fun, args), body)`
21 * 25 *
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 Expression visitContinuation(cps_ir.Continuation node) { 470 Expression visitContinuation(cps_ir.Continuation node) {
467 // Until continuations with multiple uses are supported, they are not 471 // Until continuations with multiple uses are supported, they are not
468 // visited. 472 // visited.
469 compiler.internalError(compiler.currentElement, 'Unexpected IR node.'); 473 compiler.internalError(compiler.currentElement, 'Unexpected IR node.');
470 return null; 474 return null;
471 } 475 }
472 476
473 Expression visitIsTrue(cps_ir.IsTrue node) { 477 Expression visitIsTrue(cps_ir.IsTrue node) {
474 return getVariableReference(node.value); 478 return getVariableReference(node.value);
475 } 479 }
480
481 /**
482 * Boolean conversion maps any object o into a boolean. Boolean conversion is
483 * defined by the function application
484 * (bool v){
485 * assert(v != null);
486 * return identical(v, true);
487 * }(o)
488 */
489 Expression visitBoolify(js_cps_ir.Boolify node) {
490 /// TODO(karlklose): implement the assert(v != null) check.
491 return new InvokeStatic(
492 compiler.identicalFunction,
493 identicalSelector,
494 <Expression>[visitIsTrue(node), constantTrue]);
495 }
496
497 // Helpers.
498
499 dart2js.Selector get identicalSelector {
500 return new dart2js.Selector(
501 dart2js.SelectorKind.CALL,
502 'identical',
503 null,
504 2);
505 }
506
507 /// TOOD(karlklose): cache this?
508 Constant get constantTrue {
509 ConstantExpression trueValue =
510 new PrimitiveConstantExpression(new TrueConstantValue());
511 return new Constant(trueValue);
512 }
476 } 513 }
477 514
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698