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

Side by Side Diff: dart/frog/leg/emitter.dart

Issue 9453021: Start supporting fixed length and immutable lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Handle constant list expressions. Created 8 years, 9 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
« no previous file with comments | « dart/frog/leg/compile_time_constants.dart ('k') | dart/frog/leg/lib/js_helper.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 handler.writeJsCodeForVariable(buffer, element); 519 handler.writeJsCodeForVariable(buffer, element);
520 }); 520 });
521 buffer.add(';\n'); 521 buffer.add(';\n');
522 } 522 }
523 } 523 }
524 524
525 void emitCompileTimeConstants(StringBuffer buffer) { 525 void emitCompileTimeConstants(StringBuffer buffer) {
526 CompileTimeConstantHandler handler = compiler.compileTimeConstantHandler; 526 CompileTimeConstantHandler handler = compiler.compileTimeConstantHandler;
527 List<Constant> constants = handler.getConstantsForEmission(); 527 List<Constant> constants = handler.getConstantsForEmission();
528 String prototype = "${namer.ISOLATE}.prototype"; 528 String prototype = "${namer.ISOLATE}.prototype";
529 emitMakeConstantList(prototype, buffer);
529 for (Constant constant in constants) { 530 for (Constant constant in constants) {
530 String name = handler.getNameForConstant(constant); 531 String name = handler.getNameForConstant(constant);
531 buffer.add('$prototype.$name = '); 532 buffer.add('$prototype.$name = ');
532 handler.writeJsCode(buffer, constant); 533 handler.writeJsCode(buffer, constant);
533 buffer.add(';\n'); 534 buffer.add(';\n');
534 } 535 }
535 } 536 }
536 537
538 void emitMakeConstantList(String prototype, StringBuffer buffer) {
539 buffer.add(prototype);
540 buffer.add(@'''.makeConstantList = function(list) {
541 list.immutable$list = true;
542 list.fixed$length = true;
543 return list;
544 };
545 ''');
546 }
547
537 void emitStaticFinalFieldInitializations(StringBuffer buffer) { 548 void emitStaticFinalFieldInitializations(StringBuffer buffer) {
538 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; 549 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
539 List<VariableElement> staticFinalFields = 550 List<VariableElement> staticFinalFields =
540 constants.getStaticFinalFieldsForEmission(); 551 constants.getStaticFinalFieldsForEmission();
541 for (VariableElement element in staticFinalFields) { 552 for (VariableElement element in staticFinalFields) {
542 buffer.add('${namer.isolatePropertyAccess(element)} = '); 553 buffer.add('${namer.isolatePropertyAccess(element)} = ');
543 compiler.withCurrentElement(element, () { 554 compiler.withCurrentElement(element, () {
544 constants.writeJsCodeForVariable(buffer, element); 555 constants.writeJsCodeForVariable(buffer, element);
545 }); 556 });
546 buffer.add(';\n'); 557 buffer.add(';\n');
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 emitCompileTimeConstants(buffer); 628 emitCompileTimeConstants(buffer);
618 emitStaticFinalFieldInitializations(buffer); 629 emitStaticFinalFieldInitializations(buffer);
619 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 630 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
620 Element main = compiler.mainApp.find(Compiler.MAIN); 631 Element main = compiler.mainApp.find(Compiler.MAIN);
621 buffer.add('${namer.isolateAccess(main)}();\n'); 632 buffer.add('${namer.isolateAccess(main)}();\n');
622 compiler.assembledCode = buffer.toString(); 633 compiler.assembledCode = buffer.toString();
623 }); 634 });
624 return compiler.assembledCode; 635 return compiler.assembledCode;
625 } 636 }
626 } 637 }
OLDNEW
« no previous file with comments | « dart/frog/leg/compile_time_constants.dart ('k') | dart/frog/leg/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698