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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1084153002: Make continuations last in CPS IR constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../dart2jslib.dart'; 10 import '../dart2jslib.dart';
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 616 }
617 617
618 ir.Primitive _buildInvokeStatic(Element element, 618 ir.Primitive _buildInvokeStatic(Element element,
619 Selector selector, 619 Selector selector,
620 List<ir.Primitive> arguments, 620 List<ir.Primitive> arguments,
621 SourceInformation sourceInformation) { 621 SourceInformation sourceInformation) {
622 assert(!element.isLocal); 622 assert(!element.isLocal);
623 assert(!element.isInstanceMember); 623 assert(!element.isInstanceMember);
624 assert(isOpen); 624 assert(isOpen);
625 return _continueWithExpression( 625 return _continueWithExpression(
626 (k) => new ir.InvokeStatic(element, selector, k, arguments, 626 (k) => new ir.InvokeStatic(element, selector, arguments, k,
627 sourceInformation)); 627 sourceInformation));
628 } 628 }
629 629
630 ir.Primitive _buildInvokeSuper(Element target, 630 ir.Primitive _buildInvokeSuper(Element target,
631 Selector selector, 631 Selector selector,
632 List<ir.Primitive> arguments) { 632 List<ir.Primitive> arguments) {
633 assert(target.isInstanceMember); 633 assert(target.isInstanceMember);
634 assert(isOpen); 634 assert(isOpen);
635 return _continueWithExpression( 635 return _continueWithExpression(
636 (k) => new ir.InvokeMethodDirectly( 636 (k) => new ir.InvokeMethodDirectly(
637 buildThis(), target, selector, k, arguments)); 637 buildThis(), target, selector, arguments, k));
638 } 638 }
639 639
640 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver, 640 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver,
641 Selector selector, 641 Selector selector,
642 List<ir.Primitive> arguments, 642 List<ir.Primitive> arguments,
643 {SourceInformation sourceInformation}) { 643 {SourceInformation sourceInformation}) {
644 assert(isOpen); 644 assert(isOpen);
645 return _continueWithExpression( 645 return _continueWithExpression(
646 (k) => new ir.InvokeMethod(receiver, selector, k, arguments, 646 (k) => new ir.InvokeMethod(receiver, selector, arguments, k,
647 sourceInformation: sourceInformation)); 647 sourceInformation: sourceInformation));
648 } 648 }
649 649
650 ir.Primitive _buildInvokeCall(ir.Primitive target, 650 ir.Primitive _buildInvokeCall(ir.Primitive target,
651 CallStructure callStructure, 651 CallStructure callStructure,
652 List<ir.Definition> arguments, 652 List<ir.Definition> arguments,
653 {SourceInformation sourceInformation}) { 653 {SourceInformation sourceInformation}) {
654 Selector selector = callStructure.callSelector; 654 Selector selector = callStructure.callSelector;
655 return _buildInvokeDynamic(target, selector, arguments, 655 return _buildInvokeDynamic(target, selector, arguments,
656 sourceInformation: sourceInformation); 656 sourceInformation: sourceInformation);
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 /// the argument values are defined by [arguments]. 1166 /// the argument values are defined by [arguments].
1167 ir.Primitive buildConstructorInvocation(FunctionElement element, 1167 ir.Primitive buildConstructorInvocation(FunctionElement element,
1168 CallStructure callStructure, 1168 CallStructure callStructure,
1169 DartType type, 1169 DartType type,
1170 List<ir.Primitive> arguments); 1170 List<ir.Primitive> arguments);
1171 1171
1172 /// Create a string concatenation of the [arguments]. 1172 /// Create a string concatenation of the [arguments].
1173 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) { 1173 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) {
1174 assert(isOpen); 1174 assert(isOpen);
1175 return _continueWithExpression( 1175 return _continueWithExpression(
1176 (k) => new ir.ConcatenateStrings(k, arguments)); 1176 (k) => new ir.ConcatenateStrings(arguments, k));
1177 } 1177 }
1178 1178
1179 /// Create an invocation of the `call` method of [functionExpression], where 1179 /// Create an invocation of the `call` method of [functionExpression], where
1180 /// the structure of arguments are given by [callStructure]. 1180 /// the structure of arguments are given by [callStructure].
1181 ir.Primitive buildCallInvocation( 1181 ir.Primitive buildCallInvocation(
1182 ir.Primitive functionExpression, 1182 ir.Primitive functionExpression,
1183 CallStructure callStructure, 1183 CallStructure callStructure,
1184 List<ir.Definition> arguments, 1184 List<ir.Definition> arguments,
1185 {SourceInformation sourceInformation}) { 1185 {SourceInformation sourceInformation}) {
1186 return _buildInvokeCall(functionExpression, callStructure, arguments, 1186 return _buildInvokeCall(functionExpression, callStructure, arguments,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 // let cont iteratorInvoked(iterator) = 1454 // let cont iteratorInvoked(iterator) =
1455 // [ ] 1455 // [ ]
1456 // in expressionReceiver.iterator () iteratorInvoked 1456 // in expressionReceiver.iterator () iteratorInvoked
1457 ir.Primitive expressionReceiver = buildExpression(this); 1457 ir.Primitive expressionReceiver = buildExpression(this);
1458 List<ir.Primitive> emptyArguments = <ir.Primitive>[]; 1458 List<ir.Primitive> emptyArguments = <ir.Primitive>[];
1459 ir.Parameter iterator = new ir.Parameter(null); 1459 ir.Parameter iterator = new ir.Parameter(null);
1460 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]); 1460 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]);
1461 add(new ir.LetCont(iteratorInvoked, 1461 add(new ir.LetCont(iteratorInvoked,
1462 new ir.InvokeMethod(expressionReceiver, 1462 new ir.InvokeMethod(expressionReceiver,
1463 new Selector.getter("iterator", null), 1463 new Selector.getter("iterator", null),
1464 iteratorInvoked, 1464 emptyArguments,
1465 emptyArguments))); 1465 iteratorInvoked)));
1466 1466
1467 // Fill with: 1467 // Fill with:
1468 // let cont loop(x, ...) = 1468 // let cont loop(x, ...) =
1469 // let cont moveNextInvoked(condition) = 1469 // let cont moveNextInvoked(condition) =
1470 // [ ] 1470 // [ ]
1471 // in iterator.moveNext () moveNextInvoked 1471 // in iterator.moveNext () moveNextInvoked
1472 // in loop(v, ...) 1472 // in loop(v, ...)
1473 JumpCollector loop = new BackwardJumpCollector(environment, target: target); 1473 JumpCollector loop = new BackwardJumpCollector(environment, target: target);
1474 addRecursiveContinuation(loop); 1474 addRecursiveContinuation(loop);
1475 ir.Parameter condition = new ir.Parameter(null); 1475 ir.Parameter condition = new ir.Parameter(null);
1476 ir.Continuation moveNextInvoked = new ir.Continuation([condition]); 1476 ir.Continuation moveNextInvoked = new ir.Continuation([condition]);
1477 add(new ir.LetCont(moveNextInvoked, 1477 add(new ir.LetCont(moveNextInvoked,
1478 new ir.InvokeMethod(iterator, 1478 new ir.InvokeMethod(iterator,
1479 new Selector.call("moveNext", null, 0), 1479 new Selector.call("moveNext", null, 0),
1480 moveNextInvoked, 1480 emptyArguments,
1481 emptyArguments))); 1481 moveNextInvoked)));
1482 1482
1483 // As a delimited term, build: 1483 // As a delimited term, build:
1484 // <<BODY>> = 1484 // <<BODY>> =
1485 // _enterScope(); 1485 // _enterScope();
1486 // [[variableDeclaration]] 1486 // [[variableDeclaration]]
1487 // let cont currentInvoked(currentValue) = 1487 // let cont currentInvoked(currentValue) =
1488 // [[a = currentValue]]; 1488 // [[a = currentValue]];
1489 // [ ] 1489 // [ ]
1490 // in iterator.current () currentInvoked 1490 // in iterator.current () currentInvoked
1491 IrBuilder bodyBuilder = makeDelimitedBuilder(); 1491 IrBuilder bodyBuilder = makeDelimitedBuilder();
1492 bodyBuilder._enterScope(closureScope); 1492 bodyBuilder._enterScope(closureScope);
1493 if (buildVariableDeclaration != null) { 1493 if (buildVariableDeclaration != null) {
1494 buildVariableDeclaration(bodyBuilder); 1494 buildVariableDeclaration(bodyBuilder);
1495 } 1495 }
1496 ir.Parameter currentValue = new ir.Parameter(null); 1496 ir.Parameter currentValue = new ir.Parameter(null);
1497 ir.Continuation currentInvoked = new ir.Continuation([currentValue]); 1497 ir.Continuation currentInvoked = new ir.Continuation([currentValue]);
1498 bodyBuilder.add(new ir.LetCont(currentInvoked, 1498 bodyBuilder.add(new ir.LetCont(currentInvoked,
1499 new ir.InvokeMethod(iterator, new Selector.getter("current", null), 1499 new ir.InvokeMethod(iterator, new Selector.getter("current", null),
1500 currentInvoked, emptyArguments))); 1500 emptyArguments, currentInvoked)));
1501 // TODO(sra): Does this cover all cases? The general setter case include 1501 // TODO(sra): Does this cover all cases? The general setter case include
1502 // super. 1502 // super.
1503 // TODO(johnniwinther): Extract this as a provided strategy. 1503 // TODO(johnniwinther): Extract this as a provided strategy.
1504 if (Elements.isLocal(variableElement)) { 1504 if (Elements.isLocal(variableElement)) {
1505 bodyBuilder.buildLocalVariableSet(variableElement, currentValue); 1505 bodyBuilder.buildLocalVariableSet(variableElement, currentValue);
1506 } else if (Elements.isErroneous(variableElement)) { 1506 } else if (Elements.isErroneous(variableElement)) {
1507 bodyBuilder.buildErroneousInvocation(variableElement, 1507 bodyBuilder.buildErroneousInvocation(variableElement,
1508 new Selector.setter(variableElement.name, variableElement.library), 1508 new Selector.setter(variableElement.name, variableElement.library),
1509 <ir.Primitive>[currentValue]); 1509 <ir.Primitive>[currentValue]);
1510 } else if (Elements.isStaticOrTopLevel(variableElement)) { 1510 } else if (Elements.isStaticOrTopLevel(variableElement)) {
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 2285
2286 @override 2286 @override
2287 ir.Primitive buildConstructorInvocation(ConstructorElement element, 2287 ir.Primitive buildConstructorInvocation(ConstructorElement element,
2288 CallStructure callStructure, 2288 CallStructure callStructure,
2289 DartType type, 2289 DartType type,
2290 List<ir.Primitive> arguments) { 2290 List<ir.Primitive> arguments) {
2291 assert(isOpen); 2291 assert(isOpen);
2292 Selector selector = 2292 Selector selector =
2293 new Selector(SelectorKind.CALL, element.memberName, callStructure); 2293 new Selector(SelectorKind.CALL, element.memberName, callStructure);
2294 return _continueWithExpression( 2294 return _continueWithExpression(
2295 (k) => new ir.InvokeConstructor(type, element, selector, k, 2295 (k) => new ir.InvokeConstructor(type, element, selector,
2296 arguments)); 2296 arguments, k));
2297 } 2297 }
2298 } 2298 }
2299 2299
2300 /// State shared between JsIrBuilders within the same function. 2300 /// State shared between JsIrBuilders within the same function.
2301 /// 2301 ///
2302 /// Note that this is not shared between builders of nested functions. 2302 /// Note that this is not shared between builders of nested functions.
2303 class JsIrBuilderSharedState { 2303 class JsIrBuilderSharedState {
2304 /// Maps boxed locals to their location. These locals are not part of 2304 /// Maps boxed locals to their location. These locals are not part of
2305 /// the environment. 2305 /// the environment.
2306 final Map<Local, ClosureLocation> boxedVariables = {}; 2306 final Map<Local, ClosureLocation> boxedVariables = {};
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 } 2540 }
2541 2541
2542 ir.Primitive buildInvokeDirectly(FunctionElement target, 2542 ir.Primitive buildInvokeDirectly(FunctionElement target,
2543 ir.Primitive receiver, 2543 ir.Primitive receiver,
2544 List<ir.Primitive> arguments) { 2544 List<ir.Primitive> arguments) {
2545 assert(isOpen); 2545 assert(isOpen);
2546 Selector selector = 2546 Selector selector =
2547 new Selector.call(target.name, target.library, arguments.length); 2547 new Selector.call(target.name, target.library, arguments.length);
2548 return _continueWithExpression( 2548 return _continueWithExpression(
2549 (k) => new ir.InvokeMethodDirectly( 2549 (k) => new ir.InvokeMethodDirectly(
2550 receiver, target, selector, k, arguments)); 2550 receiver, target, selector, arguments, k));
2551 } 2551 }
2552 2552
2553 /// Loads parameters to a constructor body into the environment. 2553 /// Loads parameters to a constructor body into the environment.
2554 /// 2554 ///
2555 /// The header for a constructor body differs from other functions in that 2555 /// The header for a constructor body differs from other functions in that
2556 /// some parameters are already boxed, and the box is passed as an argument 2556 /// some parameters are already boxed, and the box is passed as an argument
2557 /// instead of being created in the header. 2557 /// instead of being created in the header.
2558 void buildConstructorBodyHeader(Iterable<Local> parameters, 2558 void buildConstructorBodyHeader(Iterable<Local> parameters,
2559 ClosureScope closureScope) { 2559 ClosureScope closureScope) {
2560 _createThisParameter(); 2560 _createThisParameter();
(...skipping 20 matching lines...) Expand all
2581 Iterable<ir.Primitive> typeArguments = 2581 Iterable<ir.Primitive> typeArguments =
2582 interface.typeArguments.map((DartType argument) { 2582 interface.typeArguments.map((DartType argument) {
2583 return type.treatAsRaw 2583 return type.treatAsRaw
2584 ? buildNullLiteral() 2584 ? buildNullLiteral()
2585 : buildTypeExpression(argument); 2585 : buildTypeExpression(argument);
2586 }); 2586 });
2587 arguments = new List<ir.Primitive>.from(arguments) 2587 arguments = new List<ir.Primitive>.from(arguments)
2588 ..addAll(typeArguments); 2588 ..addAll(typeArguments);
2589 } 2589 }
2590 return _continueWithExpression( 2590 return _continueWithExpression(
2591 (k) => new ir.InvokeConstructor(type, element, selector, k, 2591 (k) => new ir.InvokeConstructor(type, element, selector,
2592 arguments)); 2592 arguments, k));
2593 } 2593 }
2594 2594
2595 ir.Primitive buildTypeExpression(DartType type) { 2595 ir.Primitive buildTypeExpression(DartType type) {
2596 if (type is TypeVariableType) { 2596 if (type is TypeVariableType) {
2597 return buildTypeVariableAccess(buildThis(), type); 2597 return buildTypeVariableAccess(buildThis(), type);
2598 } else { 2598 } else {
2599 assert(type is InterfaceType); 2599 assert(type is InterfaceType);
2600 List<ir.Primitive> arguments = <ir.Primitive>[]; 2600 List<ir.Primitive> arguments = <ir.Primitive>[];
2601 type.forEachTypeVariable((TypeVariableType variable) { 2601 type.forEachTypeVariable((TypeVariableType variable) {
2602 ir.Primitive value = buildTypeVariableAccess(buildThis(), variable); 2602 ir.Primitive value = buildTypeVariableAccess(buildThis(), variable);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 } 2698 }
2699 2699
2700 /// Synthetic parameter to a JavaScript factory method that takes the type 2700 /// Synthetic parameter to a JavaScript factory method that takes the type
2701 /// argument given for the type variable [variable]. 2701 /// argument given for the type variable [variable].
2702 class TypeInformationParameter implements Local { 2702 class TypeInformationParameter implements Local {
2703 final TypeVariableElement variable; 2703 final TypeVariableElement variable;
2704 final ExecutableElement executableContext; 2704 final ExecutableElement executableContext;
2705 TypeInformationParameter(this.variable, this.executableContext); 2705 TypeInformationParameter(this.variable, this.executableContext);
2706 String get name => variable.name; 2706 String get name => variable.name;
2707 } 2707 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698