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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_fragment.dart

Issue 1458703007: dart2js cps: Refactor CallExpressions into Primitives. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/cps_ir/cps_fragment.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_fragment.dart b/pkg/compiler/lib/src/cps_ir/cps_fragment.dart
index 7fc2ae38373fb2bd8cac048dd568cec129d9ae34..db1c719ea767a4b1f148d4081a4dcaab37a5eaf1 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_fragment.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_fragment.dart
@@ -127,31 +127,21 @@ class CpsFragment {
/// continuation parameter (i.e. the return value of the invocation).
///
/// The continuation body becomes the new hole.
sra1 2015/11/19 21:41:45 The comment needs rewriting
asgerf 2015/11/20 16:23:53 Done.
- Parameter invokeMethod(Primitive receiver,
+ Primitive invokeMethod(Primitive receiver,
Selector selector,
TypeMask mask,
List<Primitive> arguments) {
- Continuation cont = new Continuation(<Parameter>[new Parameter(null)]);
- InvokeMethod invoke =
- new InvokeMethod(receiver, selector, mask, arguments, cont,
- sourceInformation);
- put(new LetCont(cont, invoke));
- context = cont;
- return cont.parameters.single;
+ return letPrim(new InvokeMethod(receiver, selector, mask, arguments,
+ sourceInformation));
}
/// Inserts an invocation. binds its continuation, and returns the
/// continuation parameter (i.e. the return value of the invocation).
///
/// The continuation body becomes the new hole.
sra1 2015/11/19 21:41:45 rewrite comment
asgerf 2015/11/20 16:23:53 Done.
- Parameter invokeStatic(FunctionElement target, List<Primitive> arguments) {
- Continuation cont = new Continuation(<Parameter>[new Parameter(null)]);
- InvokeStatic invoke =
- new InvokeStatic(target, new Selector.fromElement(target), arguments,
- cont, sourceInformation);
- put(new LetCont(cont, invoke));
- context = cont;
- return cont.parameters.single;
+ Primitive invokeStatic(FunctionElement target, List<Primitive> arguments) {
+ return letPrim(new InvokeStatic(target, new Selector.fromElement(target),
+ arguments, sourceInformation));
}
/// Inserts an invocation to a static function that throws an error.
@@ -253,10 +243,45 @@ class CpsFragment {
Continuation letCont([List<Parameter> parameters]) {
if (parameters == null) parameters = <Parameter>[];
Continuation cont = new Continuation(parameters);
+ bindContinuation(cont);
+ return cont;
+ }
+
+ /// Binds an existing continuation at this position.
+ ///
+ /// The LetCont body becomes the new hole.
+ void bindContinuation(Continuation cont) {
LetCont let = new LetCont(cont, null);
put(let);
context = let;
- return cont;
+ }
+
+ /// Inlines [target] at the current position, substituting the provided
+ /// arguments.
+ ///
+ /// Returns a primitive containing the function's return value.
+ ///
+ /// The new hole is the the point after [target] has returned. The fragment
+ /// remains open, even if [target] never returns.
+ ///
+ /// The [target] function is destroyed and should not be reused.
+ Primitive inlineFunction(FunctionDefinition target,
+ List<Primitive> arguments,
+ Primitive thisArgument,
+ {Entity hint}) {
+ if (thisArgument != null) {
+ thisArgument.substituteFor(target.thisParameter);
+ }
+ for (int i = 0; i < arguments.length; ++i) {
+ arguments[i].substituteFor(target.parameters[i]);
+ }
+ Continuation returnCont = target.returnContinuation;
+ bindContinuation(returnCont);
+ put(target.body);
+ Parameter returnValue = returnCont.parameters.single;
+ returnValue.hint = hint;
+ context = returnCont;
+ return returnValue;
}
/// Returns a fragment whose context is the body of the given continuation.

Powered by Google App Engine
This is Rietveld 408576698