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

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

Issue 848363002: Allow LetCont to bind multiple continuations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 (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 dart2js.ir_nodes_sexpr; 5 library dart2js.ir_nodes_sexpr;
6 6
7 import '../constants/values.dart'; 7 import '../constants/values.dart';
8 import '../util/util.dart'; 8 import '../util/util.dart';
9 import 'cps_ir_nodes.dart'; 9 import 'cps_ir_nodes.dart';
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 String visitLetPrim(LetPrim node) { 71 String visitLetPrim(LetPrim node) {
72 String name = newValueName(node.primitive); 72 String name = newValueName(node.primitive);
73 String value = visit(node.primitive); 73 String value = visit(node.primitive);
74 String body = indentBlock(() => visit(node.body)); 74 String body = indentBlock(() => visit(node.body));
75 return '$indentation(LetPrim ($name $value)\n$body)'; 75 return '$indentation(LetPrim ($name $value)\n$body)';
76 } 76 }
77 77
78 String visitLetCont(LetCont node) { 78 String visitLetCont(LetCont node) {
79 String cont = newContinuationName(node.continuation); 79 String conts;
80 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and 80 bool first = true;
81 // should recurse to [visit]. Currently we can't do that, because the 81 for (Continuation continuation in node.continuations) {
82 // unstringifier_test produces [LetConts] with dummy arguments on them. 82 String name = newContinuationName(continuation);
83 String parameters = node.continuation.parameters 83 if (continuation.isRecursive) name = 'rec $name';
84 .map((p) => '${decorator(p, newValueName(p))}') 84 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and
85 .join(' '); 85 // should recurse to [visit]. Currently we can't do that, because the
86 String contBody = 86 // unstringifier_test produces [LetConts] with dummy arguments on them.
87 indentBlock(() => indentBlock(() => visit(node.continuation.body))); 87 String parameters = continuation.parameters
88 .map((p) => '${decorator(p, newValueName(p))}')
89 .join(' ');
90 String body =
91 indentBlock(() => indentBlock(() => visit(continuation.body)));
92 if (first) {
93 first = false;
94 conts = '($name ($parameters)\n$body)';
95 } else {
96 // Each subsequent line is indented additional spaces to align it
97 // with the previous continuation.
98 String indent = '$indentation${' ' * '(LetCont ('.length}';
99 conts = '$conts\n$indent($name ($parameters)\n$body)';
100 }
101 }
88 String body = indentBlock(() => visit(node.body)); 102 String body = indentBlock(() => visit(node.body));
89 String op = node.continuation.isRecursive ? 'LetCont*' : 'LetCont'; 103 return '$indentation($LetCont ($conts)\n$body)';
90 return '$indentation($op ($cont ($parameters)\n'
91 '$contBody)\n'
92 '$body)';
93 } 104 }
94 105
95 String formatArguments(Invoke node) { 106 String formatArguments(Invoke node) {
96 int positionalArgumentCount = node.selector.positionalArgumentCount; 107 int positionalArgumentCount = node.selector.positionalArgumentCount;
97 List<String> args = new List<String>(); 108 List<String> args = new List<String>();
98 args.addAll( 109 args.addAll(
99 node.arguments.getRange(0, positionalArgumentCount).map(access)); 110 node.arguments.getRange(0, positionalArgumentCount).map(access));
100 for (int i = 0; i < node.selector.namedArgumentCount; ++i) { 111 for (int i = 0; i < node.selector.namedArgumentCount; ++i) {
101 String name = node.selector.namedArguments[i]; 112 String name = node.selector.namedArguments[i];
102 Definition arg = node.arguments[positionalArgumentCount + i].definition; 113 String arg = access(node.arguments[positionalArgumentCount + i]);
103 args.add("($name: $arg)"); 114 args.add("($name: $arg)");
104 } 115 }
105 return '(${args.join(' ')})'; 116 return '(${args.join(' ')})';
106 } 117 }
107 118
108 String visitInvokeStatic(InvokeStatic node) { 119 String visitInvokeStatic(InvokeStatic node) {
109 String name = node.target.name; 120 String name = node.target.name;
110 String cont = access(node.continuation); 121 String cont = access(node.continuation);
111 String args = formatArguments(node); 122 String args = formatArguments(node);
112 return '$indentation(InvokeStatic $name $args $cont)'; 123 return '$indentation(InvokeStatic $name $args $cont)';
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 void setReturnContinuation(Continuation node) { 366 void setReturnContinuation(Continuation node) {
356 assert(!_names.containsKey(node) || _names[node] == 'return'); 367 assert(!_names.containsKey(node) || _names[node] == 'return');
357 _names[node] = 'return'; 368 _names[node] = 'return';
358 } 369 }
359 370
360 String getName(Node node) { 371 String getName(Node node) {
361 assert(_names.containsKey(node)); 372 assert(_names.containsKey(node));
362 return _names[node]; 373 return _names[node];
363 } 374 }
364 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698