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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/new_emitter/emitter.dart

Issue 1091613003: Revert "dart2js: add compiler builtins to the core-runtime." (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) 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.new_js_emitter.emitter; 5 library dart2js.new_js_emitter.emitter;
6 6
7 import 'package:_internal/compiler/js_lib/shared/embedded_names.dart' show
8 JsBuiltin;
9
10 import '../program_builder.dart' show ProgramBuilder; 7 import '../program_builder.dart' show ProgramBuilder;
11 import '../model.dart'; 8 import '../model.dart';
12 import 'model_emitter.dart'; 9 import 'model_emitter.dart';
13 import '../../common.dart'; 10 import '../../common.dart';
14 import '../../elements/elements.dart' show FieldElement; 11 import '../../elements/elements.dart' show FieldElement;
15 import '../../js/js.dart' as js; 12 import '../../js/js.dart' as js;
16 13
17 import '../../js_backend/js_backend.dart' show 14 import '../../js_backend/js_backend.dart' show
18 JavaScriptBackend, 15 JavaScriptBackend,
19 Namer; 16 Namer;
20 17
21 import '../js_emitter.dart' show 18 import '../js_emitter.dart' show
22 NativeEmitter; 19 NativeEmitter;
23 20
24 import '../js_emitter.dart' as emitterTask show 21 import '../js_emitter.dart' as emitterTask show
25 Emitter; 22 Emitter;
26 23
27 import '../../util/util.dart' show
28 NO_LOCATION_SPANNABLE;
29
30 class Emitter implements emitterTask.Emitter { 24 class Emitter implements emitterTask.Emitter {
31 final Compiler _compiler; 25 final Compiler _compiler;
32 final Namer namer; 26 final Namer namer;
33 final ModelEmitter _emitter; 27 final ModelEmitter _emitter;
34 28
35 JavaScriptBackend get _backend => _compiler.backend;
36
37 Emitter(Compiler compiler, Namer namer, NativeEmitter nativeEmitter) 29 Emitter(Compiler compiler, Namer namer, NativeEmitter nativeEmitter)
38 : this._compiler = compiler, 30 : this._compiler = compiler,
39 this.namer = namer, 31 this.namer = namer,
40 _emitter = new ModelEmitter(compiler, namer, nativeEmitter); 32 _emitter = new ModelEmitter(compiler, namer, nativeEmitter);
41 33
42 @override 34 @override
43 int emitProgram(ProgramBuilder programBuilder) { 35 int emitProgram(ProgramBuilder programBuilder) {
44 Program program = programBuilder.buildProgram(); 36 Program program = programBuilder.buildProgram();
45 return _emitter.emitProgram(program); 37 return _emitter.emitProgram(program);
46 } 38 }
(...skipping 20 matching lines...) Expand all
67 return _emitter.generateEmbeddedGlobalAccess(global); 59 return _emitter.generateEmbeddedGlobalAccess(global);
68 } 60 }
69 61
70 @override 62 @override
71 // TODO(herhut): Use a single shared function. 63 // TODO(herhut): Use a single shared function.
72 js.Expression generateFunctionThatReturnsNull() { 64 js.Expression generateFunctionThatReturnsNull() {
73 return js.js('function() {}'); 65 return js.js('function() {}');
74 } 66 }
75 67
76 js.PropertyAccess _globalPropertyAccess(Element element) { 68 js.PropertyAccess _globalPropertyAccess(Element element) {
77 String name = namer.globalPropertyName(element); 69 String name = namer.globalPropertyName(element);
78 js.PropertyAccess pa = new js.PropertyAccess.field( 70 js.PropertyAccess pa = new js.PropertyAccess.field(
79 new js.VariableUse(namer.globalObjectFor(element)), 71 new js.VariableUse(namer.globalObjectFor(element)),
80 name); 72 name);
81 return pa; 73 return pa;
82 } 74 }
83 75
84 @override 76 @override
85 js.Expression isolateLazyInitializerAccess(FieldElement element) { 77 js.Expression isolateLazyInitializerAccess(FieldElement element) {
86 return js.js('#.#', [namer.globalObjectFor(element), 78 return js.js('#.#', [namer.globalObjectFor(element),
87 namer.lazyInitializerName(element)]); 79 namer.lazyInitializerName(element)]);
88 } 80 }
89 81
90 @override 82 @override
91 js.Expression isolateStaticClosureAccess(FunctionElement element) { 83 js.Expression isolateStaticClosureAccess(FunctionElement element) {
92 return _emitter.generateStaticClosureAccess(element); 84 return _emitter.generateStaticClosureAccess(element);
(...skipping 30 matching lines...) Expand all
123 } 115 }
124 116
125 @override 117 @override
126 js.Expression typeAccess(Element element) { 118 js.Expression typeAccess(Element element) {
127 // TODO(floitsch): minify 'ensureResolved'. 119 // TODO(floitsch): minify 'ensureResolved'.
128 // TODO(floitsch): don't emit `ensureResolved` for eager classes. 120 // TODO(floitsch): don't emit `ensureResolved` for eager classes.
129 return js.js('#.ensureResolved()', _globalPropertyAccess(element)); 121 return js.js('#.ensureResolved()', _globalPropertyAccess(element));
130 } 122 }
131 123
132 @override 124 @override
133 js.Template templateForBuiltin(JsBuiltin builtin) { 125 void invalidateCaches() {}
134 String typeNameProperty = ModelEmitter.typeNameProperty;
135
136 switch (builtin) {
137 case JsBuiltin.dartObjectConstructor:
138 return js.js.expressionTemplateYielding(
139 typeAccess(_compiler.objectClass));
140
141 case JsBuiltin.isFunctionType:
142 return _backend.rti.representationGenerator.templateForIsFunctionType;
143
144 case JsBuiltin.isFunctionTypeLiteral:
145 String functionClassName =
146 _backend.namer.runtimeTypeName(compiler.functionClass);
147
148 return jsAst.js.expressionTemplateFor(
149 '#.$typeNameProperty === "$functionClassName"');
150
151 case JsBuiltin.typeName:
152 return jsAst.js.expressionTemplateFor("#.$typeNameProperty");
153
154 case JsBuiltin.rawRuntimeType:
155 return jsAst.js.expressionTemplateFor("#.constructor");
156
157 case JsBuiltin.createFunctionType:
158 return _backend.rti.representationGenerator
159 .templateForCreateFunctionType;
160
161 default:
162 _compiler.internalError(NO_LOCATION_SPANNABLE,
163 "Unhandled Builtin: $builtin");
164 return null;
165 }
166 }
167
168 @override
169 void invalidateCaches() {
170 }
171 } 126 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/js_emitter.dart ('k') | pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698