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

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

Issue 1092023002: CPS implementation of throw and rethrow. (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
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 // IrNodes are kept in a separate library to have precise control over their 5 // IrNodes are kept in a separate library to have precise control over their
6 // dependencies on other parts of the system. 6 // dependencies on other parts of the system.
7 library dart2js.ir_nodes; 7 library dart2js.ir_nodes;
8 8
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart' as values show ConstantValue; 10 import '../constants/values.dart' as values show ConstantValue;
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 final List<Reference<Primitive>> arguments; 423 final List<Reference<Primitive>> arguments;
424 final Reference<Continuation> continuation; 424 final Reference<Continuation> continuation;
425 425
426 ConcatenateStrings(List<Primitive> args, Continuation cont) 426 ConcatenateStrings(List<Primitive> args, Continuation cont)
427 : arguments = _referenceList(args), 427 : arguments = _referenceList(args),
428 continuation = new Reference<Continuation>(cont); 428 continuation = new Reference<Continuation>(cont);
429 429
430 accept(Visitor visitor) => visitor.visitConcatenateStrings(this); 430 accept(Visitor visitor) => visitor.visitConcatenateStrings(this);
431 } 431 }
432 432
433 /// Throw a value.
434 ///
435 /// Throw is an expression, i.e., it always occurs in tail position with
436 /// respect to a body or expression.
437 class Throw extends Expression {
438 Reference<Primitive> value;
439
440 Throw(Primitive value) : value = new Reference<Primitive>(value);
441
442 accept(Visitor visitor) => visitor.visitThrow(this);
443 }
444
445 /// Rethrow
446 ///
447 /// Rethrow can only occur inside a continuation bound by [LetHandler]. It
448 /// implicitly throws the exception parameter of the enclosing handler with
449 /// the same stack trace as the enclosing handler.
450 class Rethrow extends Expression {
451 accept(Visitor visitor) => visitor.visitRethrow(this);
452 }
453
454 /// A throw occurring in non-tail position.
455 ///
456 /// The CPS translation of an expression produces a primitive as the value
457 /// of the expression. For convenience in the implementation of the
458 /// translation, a [NonTailThrow] is used as that value. A cleanup pass
459 /// removes these and replaces them with [Throw] expressions.
460 class NonTailThrow extends Primitive {
461 final Reference<Primitive> value;
462
463 NonTailThrow(Primitive value) : value = new Reference<Primitive>(value);
464
465 accept(Visitor visitor) => visitor.visitNonTailThrow(this);
466 }
467
433 /// Gets the value from a [MutableVariable]. 468 /// Gets the value from a [MutableVariable].
434 /// 469 ///
435 /// [MutableVariable]s can be seen as ref cells that are not first-class 470 /// [MutableVariable]s can be seen as ref cells that are not first-class
436 /// values. A [LetPrim] with a [GetMutableVariable] can then be seen as: 471 /// values. A [LetPrim] with a [GetMutableVariable] can then be seen as:
437 /// 472 ///
438 /// let prim p = ![variable] in [body] 473 /// let prim p = ![variable] in [body]
439 /// 474 ///
440 class GetMutableVariable extends Primitive { 475 class GetMutableVariable extends Primitive {
441 final Reference<MutableVariable> variable; 476 final Reference<MutableVariable> variable;
442 477
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 T visitLetPrim(LetPrim node); 978 T visitLetPrim(LetPrim node);
944 T visitLetCont(LetCont node); 979 T visitLetCont(LetCont node);
945 T visitLetHandler(LetHandler node); 980 T visitLetHandler(LetHandler node);
946 T visitLetMutable(LetMutable node); 981 T visitLetMutable(LetMutable node);
947 T visitInvokeContinuation(InvokeContinuation node); 982 T visitInvokeContinuation(InvokeContinuation node);
948 T visitInvokeStatic(InvokeStatic node); 983 T visitInvokeStatic(InvokeStatic node);
949 T visitInvokeMethod(InvokeMethod node); 984 T visitInvokeMethod(InvokeMethod node);
950 T visitInvokeMethodDirectly(InvokeMethodDirectly node); 985 T visitInvokeMethodDirectly(InvokeMethodDirectly node);
951 T visitInvokeConstructor(InvokeConstructor node); 986 T visitInvokeConstructor(InvokeConstructor node);
952 T visitConcatenateStrings(ConcatenateStrings node); 987 T visitConcatenateStrings(ConcatenateStrings node);
988 T visitThrow(Throw node);
989 T visitRethrow(Rethrow node);
953 T visitBranch(Branch node); 990 T visitBranch(Branch node);
954 T visitTypeOperator(TypeOperator node); 991 T visitTypeOperator(TypeOperator node);
955 T visitSetMutableVariable(SetMutableVariable node); 992 T visitSetMutableVariable(SetMutableVariable node);
956 T visitDeclareFunction(DeclareFunction node); 993 T visitDeclareFunction(DeclareFunction node);
957 994
958 // Definitions. 995 // Definitions.
959 T visitLiteralList(LiteralList node); 996 T visitLiteralList(LiteralList node);
960 T visitLiteralMap(LiteralMap node); 997 T visitLiteralMap(LiteralMap node);
961 T visitConstant(Constant node); 998 T visitConstant(Constant node);
962 T visitReifyTypeVar(ReifyTypeVar node); 999 T visitReifyTypeVar(ReifyTypeVar node);
963 T visitCreateFunction(CreateFunction node); 1000 T visitCreateFunction(CreateFunction node);
964 T visitGetMutableVariable(GetMutableVariable node); 1001 T visitGetMutableVariable(GetMutableVariable node);
965 T visitParameter(Parameter node); 1002 T visitParameter(Parameter node);
966 T visitContinuation(Continuation node); 1003 T visitContinuation(Continuation node);
967 T visitMutableVariable(MutableVariable node); 1004 T visitMutableVariable(MutableVariable node);
1005 T visitNonTailThrow(NonTailThrow node);
968 1006
969 // JavaScript specific nodes. 1007 // JavaScript specific nodes.
970 1008
971 // Conditions. 1009 // Conditions.
972 T visitIsTrue(IsTrue node); 1010 T visitIsTrue(IsTrue node);
973 1011
974 // Expressions. 1012 // Expressions.
975 T visitSetField(SetField node); 1013 T visitSetField(SetField node);
976 1014
977 // Definitions. 1015 // Definitions.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 node.arguments.forEach(processReference); 1150 node.arguments.forEach(processReference);
1113 } 1151 }
1114 1152
1115 processConcatenateStrings(ConcatenateStrings node) {} 1153 processConcatenateStrings(ConcatenateStrings node) {}
1116 visitConcatenateStrings(ConcatenateStrings node) { 1154 visitConcatenateStrings(ConcatenateStrings node) {
1117 processConcatenateStrings(node); 1155 processConcatenateStrings(node);
1118 processReference(node.continuation); 1156 processReference(node.continuation);
1119 node.arguments.forEach(processReference); 1157 node.arguments.forEach(processReference);
1120 } 1158 }
1121 1159
1160 processThrow(Throw node) {}
1161 visitThrow(Throw node) {
1162 processThrow(node);
1163 processReference(node.value);
1164 }
1165
1166 processRethrow(Rethrow node) {}
1167 visitRethrow(Rethrow node) {
1168 processRethrow(node);
1169 }
1170
1122 processBranch(Branch node) {} 1171 processBranch(Branch node) {}
1123 visitBranch(Branch node) { 1172 visitBranch(Branch node) {
1124 processBranch(node); 1173 processBranch(node);
1125 processReference(node.trueContinuation); 1174 processReference(node.trueContinuation);
1126 processReference(node.falseContinuation); 1175 processReference(node.falseContinuation);
1127 visit(node.condition); 1176 visit(node.condition);
1128 } 1177 }
1129 1178
1130 processTypeOperator(TypeOperator node) {} 1179 processTypeOperator(TypeOperator node) {}
1131 visitTypeOperator(TypeOperator node) { 1180 visitTypeOperator(TypeOperator node) {
(...skipping 29 matching lines...) Expand all
1161 processLiteralMap(LiteralMap node) {} 1210 processLiteralMap(LiteralMap node) {}
1162 visitLiteralMap(LiteralMap node) { 1211 visitLiteralMap(LiteralMap node) {
1163 processLiteralMap(node); 1212 processLiteralMap(node);
1164 for (LiteralMapEntry entry in node.entries) { 1213 for (LiteralMapEntry entry in node.entries) {
1165 processReference(entry.key); 1214 processReference(entry.key);
1166 processReference(entry.value); 1215 processReference(entry.value);
1167 } 1216 }
1168 } 1217 }
1169 1218
1170 processConstant(Constant node) {} 1219 processConstant(Constant node) {}
1171 visitConstant(Constant node) => processConstant(node); 1220 visitConstant(Constant node) {
1221 processConstant(node);
1222 }
1172 1223
1173 processReifyTypeVar(ReifyTypeVar node) {} 1224 processReifyTypeVar(ReifyTypeVar node) {}
1174 visitReifyTypeVar(ReifyTypeVar node) => processReifyTypeVar(node); 1225 visitReifyTypeVar(ReifyTypeVar node) {
1226 processReifyTypeVar(node);
1227 }
1175 1228
1176 processCreateFunction(CreateFunction node) {} 1229 processCreateFunction(CreateFunction node) {}
1177 visitCreateFunction(CreateFunction node) { 1230 visitCreateFunction(CreateFunction node) {
1178 processCreateFunction(node); 1231 processCreateFunction(node);
1179 visit(node.definition); 1232 visit(node.definition);
1180 } 1233 }
1181 1234
1182 processMutableVariable(node) {} 1235 processMutableVariable(node) {}
1183 visitMutableVariable(MutableVariable node) { 1236 visitMutableVariable(MutableVariable node) {
1184 processMutableVariable(node); 1237 processMutableVariable(node);
1185 } 1238 }
1186 1239
1187 processGetMutableVariable(GetMutableVariable node) {} 1240 processGetMutableVariable(GetMutableVariable node) {}
1188 visitGetMutableVariable(GetMutableVariable node) { 1241 visitGetMutableVariable(GetMutableVariable node) {
1189 processGetMutableVariable(node); 1242 processGetMutableVariable(node);
1190 processReference(node.variable); 1243 processReference(node.variable);
1191 } 1244 }
1192 1245
1193 processParameter(Parameter node) {} 1246 processParameter(Parameter node) {}
1194 visitParameter(Parameter node) => processParameter(node); 1247 visitParameter(Parameter node) {
1248 processParameter(node);
1249 }
1195 1250
1196 processContinuation(Continuation node) {} 1251 processContinuation(Continuation node) {}
1197 visitContinuation(Continuation node) { 1252 visitContinuation(Continuation node) {
1198 processContinuation(node); 1253 processContinuation(node);
1199 node.parameters.forEach(visitParameter); 1254 node.parameters.forEach(visitParameter);
1200 if (node.body != null) visit(node.body); 1255 if (node.body != null) visit(node.body);
1201 } 1256 }
1202 1257
1203 // Conditions. 1258 // Conditions.
1204 1259
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 visitReadTypeVariable(ReadTypeVariable node) { 1313 visitReadTypeVariable(ReadTypeVariable node) {
1259 processReadTypeVariable(node); 1314 processReadTypeVariable(node);
1260 processReference(node.target); 1315 processReference(node.target);
1261 } 1316 }
1262 1317
1263 processTypeExpression(TypeExpression node) {} 1318 processTypeExpression(TypeExpression node) {}
1264 visitTypeExpression(TypeExpression node) { 1319 visitTypeExpression(TypeExpression node) {
1265 processTypeExpression(node); 1320 processTypeExpression(node);
1266 node.arguments.forEach(processReference); 1321 node.arguments.forEach(processReference);
1267 } 1322 }
1323
1324 processNonTailThrow(NonTailThrow node) {}
1325 visitNonTailThrow(NonTailThrow node) {
1326 processNonTailThrow(node);
1327 processReference(node.value);
1328 }
1268 } 1329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698