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

Unified Diff: pkg/compiler/lib/src/ssa/codegen.dart

Issue 839323003: Implementation of async-await transformation on js ast. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/codegen.dart
diff --git a/pkg/compiler/lib/src/ssa/codegen.dart b/pkg/compiler/lib/src/ssa/codegen.dart
index 0d4b38911d9bf6777dc1306ee7759f5b0aa1d29d..1a3977386278751a59642e22221ada032579cf45 100644
--- a/pkg/compiler/lib/src/ssa/codegen.dart
+++ b/pkg/compiler/lib/src/ssa/codegen.dart
@@ -52,7 +52,16 @@ class SsaCodeGeneratorTask extends CompilerTask {
js.Fun buildJavaScriptFunction(FunctionElement element,
List<js.Parameter> parameters,
js.Block body) {
- return attachPosition(new js.Fun(parameters, body), element);
+ js.AsyncModifier asyncModifier = element.asyncMarker.isAsync
+ ? (element.asyncMarker.isYielding
+ ? const js.AsyncModifier.asyncStar()
+ : const js.AsyncModifier.async())
+ : (element.asyncMarker.isYielding
+ ? const js.AsyncModifier.syncStar()
+ : const js.AsyncModifier.sync());
+
+ return attachPosition(
+ new js.Fun(parameters, body, asyncModifier: asyncModifier), element);
}
js.Expression generateCode(CodegenWorkItem work, HGraph graph) {
@@ -75,10 +84,13 @@ class SsaCodeGeneratorTask extends CompilerTask {
js.Expression generateMethod(CodegenWorkItem work, HGraph graph) {
return measure(() {
+ FunctionElement element = work.element;
+ if (element.asyncMarker != AsyncMarker.SYNC) {
+ work.registry.registerAsyncMarker(element);
+ }
SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work);
codegen.visitGraph(graph);
compiler.tracer.traceGraph("codegen", graph);
- FunctionElement element = work.element;
return buildJavaScriptFunction(element, codegen.parameters, codegen.body);
});
}
@@ -1969,6 +1981,16 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
}
}
+ visitAwait(HAwait node) {
+ use(node.inputs[0]);
+ push(new js.Await(pop()), node);
+ }
+
+ visitYield(HYield node) {
+ use(node.inputs[0]);
+ pushStatement(new js.DartYield(pop(), node.hasStar), node);
+ }
+
visitRangeConversion(HRangeConversion node) {
// Range conversion instructions are removed by the value range
// analyzer.
@@ -2047,7 +2069,15 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
if (helperName == 'wrapException') {
pushStatement(new js.Throw(value));
} else {
- pushStatement(new js.Return(value));
+ Element element = work.element;
+ if (element is FunctionElement && element.asyncMarker.isYielding) {
+ // `return <expr>;` is illegal in a sync* or async* function.
+ // To have the the async-translator working, we avoid introducing
+ // `return` nodes.
+ pushStatement(new js.ExpressionStatement(value));
+ } else {
+ pushStatement(new js.Return(value));
+ }
}
}
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698