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

Unified Diff: dart/pkg/dart2js_incremental/lib/library_updater.dart

Issue 636903002: Compute an incremental patch to JavaScript code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT bool.fromEnvironment. Created 6 years, 2 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 | « no previous file | dart/sdk/lib/_internal/compiler/implementation/apiimpl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/pkg/dart2js_incremental/lib/library_updater.dart
diff --git a/dart/pkg/dart2js_incremental/lib/library_updater.dart b/dart/pkg/dart2js_incremental/lib/library_updater.dart
index 246f7797e3cefcbe6e153f999adc814950af0068..33c69feff688aefc444a79b98b556b83122285a2 100644
--- a/dart/pkg/dart2js_incremental/lib/library_updater.dart
+++ b/dart/pkg/dart2js_incremental/lib/library_updater.dart
@@ -32,6 +32,16 @@ import 'package:compiler/implementation/source_file.dart' show
import 'package:compiler/implementation/tree/tree.dart' show
FunctionExpression;
+import 'package:compiler/implementation/js/js.dart' show
+ js;
+
+import 'package:compiler/implementation/js/js.dart' as jsAst;
+
+import 'package:compiler/implementation/js_emitter/js_emitter.dart' show
+ ClassBuilder;
+
+import 'package:compiler/js_lib/shared/embedded_names.dart' as embeddedNames;
+
import 'diff.dart' show
Difference,
computeDifference;
@@ -175,6 +185,61 @@ class LibraryUpdater {
List<Element> applyUpdates() {
return updates.map((Update update) => update.apply()).toList();
}
+
+ String computeUpdateJs() {
+ List<Element> updatedElements = applyUpdates();
+ compiler.progress.reset();
+ for (Element element in updatedElements) {
+ compiler.enqueuer.resolution.addToWorkList(element);
+ }
+ compiler.processQueue(compiler.enqueuer.resolution, null);
+
+ compiler.phase = Compiler.PHASE_DONE_RESOLVING;
+
+ for (Element element in updatedElements) {
+ compiler.enqueuer.codegen.addToWorkList(element);
+ }
+ compiler.processQueue(compiler.enqueuer.codegen, null);
+
+ jsAst.Block updates = new jsAst.Block.empty();
+ for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
+ updates.statements.add(computeMemberUpdateJs(element));
sra1 2014/10/07 18:03:06 Construct ASTs functionally. Don't modify construc
ahe 2014/10/08 12:09:45 I'm doing something like that.
+ }
+
+ if (updates.statements.length == 1) {
+ return prettyPrintJs(updates.statements.single);
+ } else {
+ return prettyPrintJs(updates);
+ }
+ }
+
+ jsAst.Node computeMemberUpdateJs(Element element) {
+ ClassBuilder builder = new ClassBuilder(element, compiler.backend.namer);
+
+ compiler.backend.emitter.oldEmitter.containerBuilder.addMember(
+ element, builder);
+ jsAst.Property property = builder.properties.single;
+ jsAst.Node name = property.name;
+ jsAst.Node function = property.value;
+ jsAst.Node globalObject = compiler.backend.namer.globalObjectFor(element);
+ jsAst.Expression globalFunctionsAccess =
+ compiler.backend.emitter.generateEmbeddedGlobalAccess(
+ embeddedNames.GLOBAL_FUNCTIONS);
+ jsAst.Node updateGlobalFunction =
+ js.statement(
+ '#.# = #.# = f', [globalFunctionsAccess, name, globalObject, name]);
+ // Create a scope by creating a new function. The updated function literal
+ // is passed as an argument to this function which ensures that temporary
+ // names in updateScope don't shadow global names.
floitsch 2014/10/07 15:56:58 The only temporary variable updateScope has is the
ahe 2014/10/07 16:32:40 Yes, but I know I want to add at least one more st
floitsch 2014/10/07 17:48:38 Maybe you could write it with conditions: if (#) #
sra1 2014/10/07 18:03:06 You can conditionally generate code with templates
ahe 2014/10/08 12:09:45 I think I'll avoid templates with conditionals in
+ jsAst.Fun updateScope = new jsAst.Fun(
+ [new jsAst.Parameter('f')], new jsAst.Block.empty());
floitsch 2014/10/07 15:56:58 does the following work? jsAst.Fun = js('function
ahe 2014/10/07 16:32:40 Yes. But doesn't scale to multiple statements. I
floitsch 2014/10/07 17:48:38 I think you don't even need a block: js('function
sra1 2014/10/07 18:03:06 It does work, with a minor tweak. Blocks (and ite
ahe 2014/10/08 12:09:45 That's pretty nifty, but I feel that this is more
+ updateScope.body.statements.add(updateGlobalFunction);
sra1 2014/10/07 18:03:06 Ditto: Construct ASTs functionally.
ahe 2014/10/08 12:09:45 I don't know what you mean by that.
+ return js.statement('(#)(#)', [updateScope, function]);
+ }
+
+ String prettyPrintJs(jsAst.Node node) {
+ return jsAst.prettyPrint(node, compiler).getText();
+ }
}
/// Represents an update (aka patch) of [before] to [after]. We use the word
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/apiimpl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698