OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc.fletch_class_builder; | 5 library dartino_compiler.dartino_class_builder; |
6 | 6 |
7 import 'package:compiler/src/dart_types.dart'; | 7 import 'package:compiler/src/dart_types.dart'; |
8 import 'package:compiler/src/elements/elements.dart'; | 8 import 'package:compiler/src/elements/elements.dart'; |
9 import 'package:compiler/src/universe/selector.dart'; | 9 import 'package:compiler/src/universe/selector.dart'; |
10 import 'package:persistent/persistent.dart'; | 10 import 'package:persistent/persistent.dart'; |
11 | 11 |
12 import 'fletch_function_builder.dart'; | 12 import 'dartino_function_builder.dart'; |
13 import 'fletch_context.dart'; | 13 import 'dartino_context.dart'; |
14 import 'fletch_backend.dart'; | 14 import 'dartino_backend.dart'; |
15 | 15 |
16 import '../fletch_system.dart'; | 16 import '../dartino_system.dart'; |
17 import '../vm_commands.dart'; | 17 import '../vm_commands.dart'; |
18 | 18 |
19 // TODO(ahe): Remove this import. | 19 // TODO(ahe): Remove this import. |
20 import '../incremental/fletchc_incremental.dart' show | 20 import '../incremental/dartino_compiler_incremental.dart' show |
21 IncrementalCompilationFailed; | 21 IncrementalCompilationFailed; |
22 | 22 |
23 abstract class FletchClassBuilder { | 23 abstract class DartinoClassBuilder { |
24 int get classId; | 24 int get classId; |
25 ClassElement get element; | 25 ClassElement get element; |
26 FletchClassBuilder get superclass; | 26 DartinoClassBuilder get superclass; |
27 int get fields; | 27 int get fields; |
28 | 28 |
29 /** | 29 /** |
30 * Returns the number of instance fields of all the super classes of this | 30 * Returns the number of instance fields of all the super classes of this |
31 * class. | 31 * class. |
32 * | 32 * |
33 * If this class has no super class (if it's Object), 0 is returned. | 33 * If this class has no super class (if it's Object), 0 is returned. |
34 */ | 34 */ |
35 int get superclassFields => hasSuperClass ? superclass.fields : 0; | 35 int get superclassFields => hasSuperClass ? superclass.fields : 0; |
36 | 36 |
37 bool get hasSuperClass => superclass != null; | 37 bool get hasSuperClass => superclass != null; |
38 | 38 |
39 void addToMethodTable(int selector, FletchFunctionBase functionBase); | 39 void addToMethodTable(int selector, DartinoFunctionBase functionBase); |
40 void removeFromMethodTable(FletchFunctionBase function); | 40 void removeFromMethodTable(DartinoFunctionBase function); |
41 | 41 |
42 void addField(FieldElement field); | 42 void addField(FieldElement field); |
43 void removeField(FieldElement field); | 43 void removeField(FieldElement field); |
44 | 44 |
45 // Add a selector for is-tests. The selector is only to be hit with the | 45 // Add a selector for is-tests. The selector is only to be hit with the |
46 // InvokeTest bytecode, as the function is not guraranteed to be valid. | 46 // InvokeTest bytecode, as the function is not guraranteed to be valid. |
47 void addIsSelector(int selector); | 47 void addIsSelector(int selector); |
48 void createIsFunctionEntry(FletchBackend backend, int arity); | 48 void createIsFunctionEntry(DartinoBackend backend, int arity); |
49 void updateImplicitAccessors(FletchBackend backend); | 49 void updateImplicitAccessors(DartinoBackend backend); |
50 | 50 |
51 FletchClass finalizeClass( | 51 DartinoClass finalizeClass( |
52 FletchContext context, | 52 DartinoContext context, |
53 List<VmCommand> commands); | 53 List<VmCommand> commands); |
54 | 54 |
55 // The method table for a class is a mapping from Fletch's integer | 55 // The method table for a class is a mapping from Dartino's integer |
56 // selectors to method ids. It contains all methods defined for a | 56 // selectors to method ids. It contains all methods defined for a |
57 // class including the implicit accessors. The returned map is not sorted. | 57 // class including the implicit accessors. The returned map is not sorted. |
58 // TODO(ajohnsen): Remove once not used by feature_test anymore. | 58 // TODO(ajohnsen): Remove once not used by feature_test anymore. |
59 PersistentMap<int, int> computeMethodTable(); | 59 PersistentMap<int, int> computeMethodTable(); |
60 | 60 |
61 bool computeSchemaChange(List<VmCommand> commands) { | 61 bool computeSchemaChange(List<VmCommand> commands) { |
62 return false; | 62 return false; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void forEachField(ClassElement c, void action(FieldElement field)) { | 66 void forEachField(ClassElement c, void action(FieldElement field)) { |
67 List classes = []; | 67 List classes = []; |
68 while (c != null) { | 68 while (c != null) { |
69 classes.add(c); | 69 classes.add(c); |
70 c = c.superclass; | 70 c = c.superclass; |
71 } | 71 } |
72 for (int i = classes.length - 1; i >= 0; i--) { | 72 for (int i = classes.length - 1; i >= 0; i--) { |
73 classes[i].implementation.forEachInstanceField((_, FieldElement field) { | 73 classes[i].implementation.forEachInstanceField((_, FieldElement field) { |
74 action(field); | 74 action(field); |
75 }); | 75 }); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 class FletchNewClassBuilder extends FletchClassBuilder { | 79 class DartinoNewClassBuilder extends DartinoClassBuilder { |
80 final int classId; | 80 final int classId; |
81 final ClassElement element; | 81 final ClassElement element; |
82 final FletchClassBuilder superclass; | 82 final DartinoClassBuilder superclass; |
83 final bool isBuiltin; | 83 final bool isBuiltin; |
84 | 84 |
85 // The extra fields are synthetic fields not represented in any Dart source | 85 // The extra fields are synthetic fields not represented in any Dart source |
86 // code. They are used for the synthetic closure classes that are introduced | 86 // code. They are used for the synthetic closure classes that are introduced |
87 // behind the scenes. | 87 // behind the scenes. |
88 final int extraFields; | 88 final int extraFields; |
89 | 89 |
90 final Map<int, int> _implicitAccessorTable = <int, int>{}; | 90 final Map<int, int> _implicitAccessorTable = <int, int>{}; |
91 final Map<int, FletchFunctionBase> _methodTable = <int, FletchFunctionBase>{}; | 91 final Map<int, DartinoFunctionBase> _methodTable = <int, DartinoFunctionBase>{
}; |
92 | 92 |
93 FletchNewClassBuilder( | 93 DartinoNewClassBuilder( |
94 this.classId, | 94 this.classId, |
95 this.element, | 95 this.element, |
96 this.superclass, | 96 this.superclass, |
97 this.isBuiltin, | 97 this.isBuiltin, |
98 this.extraFields); | 98 this.extraFields); |
99 | 99 |
100 int get fields { | 100 int get fields { |
101 int count = superclassFields + extraFields; | 101 int count = superclassFields + extraFields; |
102 if (element != null) { | 102 if (element != null) { |
103 // TODO(kasperl): Once we change compiled class to be immutable, we | 103 // TODO(kasperl): Once we change compiled class to be immutable, we |
104 // should cache the field count. | 104 // should cache the field count. |
105 element.implementation.forEachInstanceField((_, __) { count++; }); | 105 element.implementation.forEachInstanceField((_, __) { count++; }); |
106 } | 106 } |
107 return count; | 107 return count; |
108 } | 108 } |
109 | 109 |
110 void addToMethodTable(int selector, FletchFunctionBase functionBase) { | 110 void addToMethodTable(int selector, DartinoFunctionBase functionBase) { |
111 _methodTable[selector] = functionBase; | 111 _methodTable[selector] = functionBase; |
112 } | 112 } |
113 | 113 |
114 void addField(FieldElement field) { | 114 void addField(FieldElement field) { |
115 throw new StateError("Fields should not be added to a new class."); | 115 throw new StateError("Fields should not be added to a new class."); |
116 } | 116 } |
117 | 117 |
118 void removeField(FieldElement field) { | 118 void removeField(FieldElement field) { |
119 // TODO(ahe): Change this to a StateError when bug in incremental compiler | 119 // TODO(ahe): Change this to a StateError when bug in incremental compiler |
120 // is fixed (tested by super_is_parameter). | 120 // is fixed (tested by super_is_parameter). |
121 throw new IncrementalCompilationFailed( | 121 throw new IncrementalCompilationFailed( |
122 "Can't remove a field ($field) from a new class ($element)"); | 122 "Can't remove a field ($field) from a new class ($element)"); |
123 } | 123 } |
124 | 124 |
125 void removeFromMethodTable(FletchFunctionBase function) { | 125 void removeFromMethodTable(DartinoFunctionBase function) { |
126 throw new StateError("Methods should not be removed from a new class."); | 126 throw new StateError("Methods should not be removed from a new class."); |
127 } | 127 } |
128 | 128 |
129 void addIsSelector(int selector) { | 129 void addIsSelector(int selector) { |
130 // TODO(ajohnsen): 'null' is a placeholder. Generate dummy function? | 130 // TODO(ajohnsen): 'null' is a placeholder. Generate dummy function? |
131 _methodTable[selector] = null; | 131 _methodTable[selector] = null; |
132 } | 132 } |
133 | 133 |
134 PersistentMap<int, int> computeMethodTable() { | 134 PersistentMap<int, int> computeMethodTable() { |
135 PersistentMap<int, int> result = new PersistentMap<int, int>(); | 135 PersistentMap<int, int> result = new PersistentMap<int, int>(); |
136 List<int> selectors = _implicitAccessorTable.keys.toList() | 136 List<int> selectors = _implicitAccessorTable.keys.toList() |
137 ..addAll(_methodTable.keys); | 137 ..addAll(_methodTable.keys); |
138 for (int selector in selectors) { | 138 for (int selector in selectors) { |
139 if (_methodTable.containsKey(selector)) { | 139 if (_methodTable.containsKey(selector)) { |
140 FletchFunctionBase function = _methodTable[selector]; | 140 DartinoFunctionBase function = _methodTable[selector]; |
141 int functionId = function == null ? 0 : function.functionId; | 141 int functionId = function == null ? 0 : function.functionId; |
142 result = result.insert(selector, functionId); | 142 result = result.insert(selector, functionId); |
143 } else { | 143 } else { |
144 result = result.insert(selector, _implicitAccessorTable[selector]); | 144 result = result.insert(selector, _implicitAccessorTable[selector]); |
145 } | 145 } |
146 } | 146 } |
147 return result; | 147 return result; |
148 } | 148 } |
149 | 149 |
150 void updateImplicitAccessors(FletchBackend backend) { | 150 void updateImplicitAccessors(DartinoBackend backend) { |
151 _implicitAccessorTable.clear(); | 151 _implicitAccessorTable.clear(); |
152 // If we don't have an element (stub class), we don't have anything to | 152 // If we don't have an element (stub class), we don't have anything to |
153 // generate accessors for. | 153 // generate accessors for. |
154 if (element == null) return; | 154 if (element == null) return; |
155 // TODO(ajohnsen): Don't do this once dart2js can enqueue field getters in | 155 // TODO(ajohnsen): Don't do this once dart2js can enqueue field getters in |
156 // CodegenEnqueuer. | 156 // CodegenEnqueuer. |
157 int fieldIndex = superclassFields; | 157 int fieldIndex = superclassFields; |
158 element.implementation.forEachInstanceField((enclosing, field) { | 158 element.implementation.forEachInstanceField((enclosing, field) { |
159 var getter = new Selector.getter(field.memberName); | 159 var getter = new Selector.getter(field.memberName); |
160 int getterSelector = backend.context.toFletchSelector(getter); | 160 int getterSelector = backend.context.toDartinoSelector(getter); |
161 _implicitAccessorTable[getterSelector] = backend.makeGetter(fieldIndex); | 161 _implicitAccessorTable[getterSelector] = backend.makeGetter(fieldIndex); |
162 | 162 |
163 if (!field.isFinal) { | 163 if (!field.isFinal) { |
164 var setter = new Selector.setter(new Name(field.name, field.library)); | 164 var setter = new Selector.setter(new Name(field.name, field.library)); |
165 var setterSelector = backend.context.toFletchSelector(setter); | 165 var setterSelector = backend.context.toDartinoSelector(setter); |
166 _implicitAccessorTable[setterSelector] = backend.makeSetter(fieldIndex); | 166 _implicitAccessorTable[setterSelector] = backend.makeSetter(fieldIndex); |
167 } | 167 } |
168 | 168 |
169 fieldIndex++; | 169 fieldIndex++; |
170 }); | 170 }); |
171 } | 171 } |
172 | 172 |
173 void createIsFunctionEntry(FletchBackend backend, int arity) { | 173 void createIsFunctionEntry(DartinoBackend backend, int arity) { |
174 int fletchSelector = backend.context.toFletchIsSelector( | 174 int dartinoSelector = backend.context.toDartinoIsSelector( |
175 backend.compiler.coreClasses.functionClass); | 175 backend.compiler.coreClasses.functionClass); |
176 addIsSelector(fletchSelector); | 176 addIsSelector(dartinoSelector); |
177 fletchSelector = backend.context.toFletchIsSelector( | 177 dartinoSelector = backend.context.toDartinoIsSelector( |
178 backend.compiler.coreClasses.functionClass, arity); | 178 backend.compiler.coreClasses.functionClass, arity); |
179 addIsSelector(fletchSelector); | 179 addIsSelector(dartinoSelector); |
180 } | 180 } |
181 | 181 |
182 FletchClass finalizeClass( | 182 DartinoClass finalizeClass( |
183 FletchContext context, | 183 DartinoContext context, |
184 List<VmCommand> commands) { | 184 List<VmCommand> commands) { |
185 if (isBuiltin) { | 185 if (isBuiltin) { |
186 int nameId = context.getSymbolId(element.name); | 186 int nameId = context.getSymbolId(element.name); |
187 commands.add(new PushBuiltinClass(nameId, fields)); | 187 commands.add(new PushBuiltinClass(nameId, fields)); |
188 } else { | 188 } else { |
189 commands.add(new PushNewClass(fields)); | 189 commands.add(new PushNewClass(fields)); |
190 } | 190 } |
191 | 191 |
192 commands.add(const Dup()); | 192 commands.add(const Dup()); |
193 commands.add(new PopToMap(MapId.classes, classId)); | 193 commands.add(new PopToMap(MapId.classes, classId)); |
194 | 194 |
195 PersistentMap<int, int> methodTable = computeMethodTable(); | 195 PersistentMap<int, int> methodTable = computeMethodTable(); |
196 for (int selector in methodTable.keys.toList()..sort()) { | 196 for (int selector in methodTable.keys.toList()..sort()) { |
197 int functionId = methodTable[selector]; | 197 int functionId = methodTable[selector]; |
198 commands.add(new PushNewInteger(selector)); | 198 commands.add(new PushNewInteger(selector)); |
199 commands.add(new PushFromMap(MapId.methods, functionId)); | 199 commands.add(new PushFromMap(MapId.methods, functionId)); |
200 } | 200 } |
201 commands.add(new ChangeMethodTable(methodTable.length)); | 201 commands.add(new ChangeMethodTable(methodTable.length)); |
202 | 202 |
203 List<FieldElement> fieldsList = new List<FieldElement>(fields); | 203 List<FieldElement> fieldsList = new List<FieldElement>(fields); |
204 int index = 0; | 204 int index = 0; |
205 forEachField(element, (field) { | 205 forEachField(element, (field) { |
206 fieldsList[index++] = field; | 206 fieldsList[index++] = field; |
207 }); | 207 }); |
208 | 208 |
209 return new FletchClass( | 209 return new DartinoClass( |
210 classId, | 210 classId, |
211 // TODO(ajohnsen): Take name in FletchClassBuilder constructor. | 211 // TODO(ajohnsen): Take name in DartinoClassBuilder constructor. |
212 element == null ? '<internal>' : element.name, | 212 element == null ? '<internal>' : element.name, |
213 element, | 213 element, |
214 superclass == null ? -1 : superclass.classId, | 214 superclass == null ? -1 : superclass.classId, |
215 superclassFields, | 215 superclassFields, |
216 methodTable, | 216 methodTable, |
217 fieldsList); | 217 fieldsList); |
218 } | 218 } |
219 | 219 |
220 String toString() => "FletchClassBuilder($element, $classId)"; | 220 String toString() => "DartinoClassBuilder($element, $classId)"; |
221 } | 221 } |
222 | 222 |
223 class FletchPatchClassBuilder extends FletchClassBuilder { | 223 class DartinoPatchClassBuilder extends DartinoClassBuilder { |
224 final FletchClass klass; | 224 final DartinoClass klass; |
225 final FletchClassBuilder superclass; | 225 final DartinoClassBuilder superclass; |
226 | 226 |
227 final Map<int, int> _implicitAccessorTable = <int, int>{}; | 227 final Map<int, int> _implicitAccessorTable = <int, int>{}; |
228 final Map<int, FletchFunctionBase> _newMethods = <int, FletchFunctionBase>{}; | 228 final Map<int, DartinoFunctionBase> _newMethods = <int, DartinoFunctionBase>{}
; |
229 final Set<FletchFunctionBase> _removedMethods = new Set<FletchFunctionBase>(); | 229 final Set<DartinoFunctionBase> _removedMethods = new Set<DartinoFunctionBase>(
); |
230 final Set<FieldElement> _removedFields = new Set<FieldElement>(); | 230 final Set<FieldElement> _removedFields = new Set<FieldElement>(); |
231 final List<int> _removedAccessors = <int>[]; | 231 final List<int> _removedAccessors = <int>[]; |
232 bool _fieldsChanged = false; | 232 bool _fieldsChanged = false; |
233 | 233 |
234 // TODO(ajohnsen): Reconsider bookkeeping of extra fields (this is really only | 234 // TODO(ajohnsen): Reconsider bookkeeping of extra fields (this is really only |
235 // extra super-class fields). | 235 // extra super-class fields). |
236 int extraFields = 0; | 236 int extraFields = 0; |
237 | 237 |
238 // TODO(ajohnsen): Can the element change? | 238 // TODO(ajohnsen): Can the element change? |
239 FletchPatchClassBuilder(this.klass, this.superclass); | 239 DartinoPatchClassBuilder(this.klass, this.superclass); |
240 | 240 |
241 int get classId => klass.classId; | 241 int get classId => klass.classId; |
242 ClassElement get element => klass.element; | 242 ClassElement get element => klass.element; |
243 int get fields => klass.fields.length; | 243 int get fields => klass.fields.length; |
244 | 244 |
245 void addToMethodTable(int selector, FletchFunctionBase functionBase) { | 245 void addToMethodTable(int selector, DartinoFunctionBase functionBase) { |
246 _newMethods[selector] = functionBase; | 246 _newMethods[selector] = functionBase; |
247 } | 247 } |
248 | 248 |
249 void removeFromMethodTable(FletchFunctionBase function) { | 249 void removeFromMethodTable(DartinoFunctionBase function) { |
250 assert(function != null); | 250 assert(function != null); |
251 _removedMethods.add(function); | 251 _removedMethods.add(function); |
252 } | 252 } |
253 | 253 |
254 void removeField(FieldElement field) { | 254 void removeField(FieldElement field) { |
255 if (field.enclosingClass != element) extraFields--; | 255 if (field.enclosingClass != element) extraFields--; |
256 _fieldsChanged = true; | 256 _fieldsChanged = true; |
257 _removedFields.add(field); | 257 _removedFields.add(field); |
258 } | 258 } |
259 | 259 |
260 void addField(FieldElement field) { | 260 void addField(FieldElement field) { |
261 if (field.enclosingClass != element) extraFields++; | 261 if (field.enclosingClass != element) extraFields++; |
262 _fieldsChanged = true; | 262 _fieldsChanged = true; |
263 } | 263 } |
264 | 264 |
265 void addIsSelector(int selector) { | 265 void addIsSelector(int selector) { |
266 // TODO(ajohnsen): Implement. | 266 // TODO(ajohnsen): Implement. |
267 } | 267 } |
268 | 268 |
269 void createIsFunctionEntry(FletchBackend backend, int arity) { | 269 void createIsFunctionEntry(DartinoBackend backend, int arity) { |
270 // TODO(ajohnsen): Implement. | 270 // TODO(ajohnsen): Implement. |
271 } | 271 } |
272 | 272 |
273 void updateImplicitAccessors(FletchBackend backend) { | 273 void updateImplicitAccessors(DartinoBackend backend) { |
274 // If we don't have an element (stub class), we don't have anything to | 274 // If we don't have an element (stub class), we don't have anything to |
275 // generate accessors for. | 275 // generate accessors for. |
276 if (element == null) return; | 276 if (element == null) return; |
277 // TODO(ajohnsen): Don't do this once dart2js can enqueue field getters in | 277 // TODO(ajohnsen): Don't do this once dart2js can enqueue field getters in |
278 // CodegenEnqueuer. | 278 // CodegenEnqueuer. |
279 int fieldIndex = superclassFields + extraFields; | 279 int fieldIndex = superclassFields + extraFields; |
280 element.implementation.forEachInstanceField((enclosing, field) { | 280 element.implementation.forEachInstanceField((enclosing, field) { |
281 var getter = new Selector.getter(new Name(field.name, field.library)); | 281 var getter = new Selector.getter(new Name(field.name, field.library)); |
282 int getterSelector = backend.context.toFletchSelector(getter); | 282 int getterSelector = backend.context.toDartinoSelector(getter); |
283 _implicitAccessorTable[getterSelector] = backend.makeGetter(fieldIndex); | 283 _implicitAccessorTable[getterSelector] = backend.makeGetter(fieldIndex); |
284 | 284 |
285 if (!field.isFinal) { | 285 if (!field.isFinal) { |
286 var setter = new Selector.setter(new Name(field.name, field.library)); | 286 var setter = new Selector.setter(new Name(field.name, field.library)); |
287 var setterSelector = backend.context.toFletchSelector(setter); | 287 var setterSelector = backend.context.toDartinoSelector(setter); |
288 _implicitAccessorTable[setterSelector] = backend.makeSetter(fieldIndex); | 288 _implicitAccessorTable[setterSelector] = backend.makeSetter(fieldIndex); |
289 } | 289 } |
290 | 290 |
291 fieldIndex++; | 291 fieldIndex++; |
292 }); | 292 }); |
293 | 293 |
294 for (FieldElement field in _removedFields) { | 294 for (FieldElement field in _removedFields) { |
295 Selector getter = | 295 Selector getter = |
296 new Selector.getter(new Name(field.name, field.library)); | 296 new Selector.getter(new Name(field.name, field.library)); |
297 int getterSelector = backend.context.toFletchSelector(getter); | 297 int getterSelector = backend.context.toDartinoSelector(getter); |
298 _removedAccessors.add(getterSelector); | 298 _removedAccessors.add(getterSelector); |
299 | 299 |
300 if (!field.isFinal) { | 300 if (!field.isFinal) { |
301 Selector setter = | 301 Selector setter = |
302 new Selector.setter(new Name(field.name, field.library)); | 302 new Selector.setter(new Name(field.name, field.library)); |
303 int setterSelector = backend.context.toFletchSelector(setter); | 303 int setterSelector = backend.context.toDartinoSelector(setter); |
304 _removedAccessors.add(setterSelector); | 304 _removedAccessors.add(setterSelector); |
305 } | 305 } |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 PersistentMap<int, int> computeMethodTable() { | 309 PersistentMap<int, int> computeMethodTable() { |
310 PersistentMap<int, int> methodTable = klass.methodTable; | 310 PersistentMap<int, int> methodTable = klass.methodTable; |
311 | 311 |
312 for (int selector in _removedAccessors) { | 312 for (int selector in _removedAccessors) { |
313 methodTable = methodTable.delete(selector); | 313 methodTable = methodTable.delete(selector); |
314 } | 314 } |
315 | 315 |
316 for (FletchFunctionBase function in _removedMethods) { | 316 for (DartinoFunctionBase function in _removedMethods) { |
317 methodTable.forEachKeyValue((int selector, int functionId) { | 317 methodTable.forEachKeyValue((int selector, int functionId) { |
318 if (functionId == function.functionId) { | 318 if (functionId == function.functionId) { |
319 methodTable = methodTable.delete(selector); | 319 methodTable = methodTable.delete(selector); |
320 } | 320 } |
321 }); | 321 }); |
322 } | 322 } |
323 | 323 |
324 // TODO(ajohnsen): Generate this from add/remove field operations. | 324 // TODO(ajohnsen): Generate this from add/remove field operations. |
325 _implicitAccessorTable.forEach((int selector, int functionId) { | 325 _implicitAccessorTable.forEach((int selector, int functionId) { |
326 methodTable = methodTable.insert(selector, functionId); | 326 methodTable = methodTable.insert(selector, functionId); |
327 }); | 327 }); |
328 | 328 |
329 _newMethods.forEach((int selector, FletchFunctionBase function) { | 329 _newMethods.forEach((int selector, DartinoFunctionBase function) { |
330 methodTable = methodTable.insert(selector, function.functionId); | 330 methodTable = methodTable.insert(selector, function.functionId); |
331 }); | 331 }); |
332 | 332 |
333 return methodTable; | 333 return methodTable; |
334 } | 334 } |
335 | 335 |
336 FletchClass finalizeClass( | 336 DartinoClass finalizeClass( |
337 FletchContext context, | 337 DartinoContext context, |
338 List<VmCommand> commands) { | 338 List<VmCommand> commands) { |
339 // TODO(ajohnsen): We need to figure out when to do this. It should be after | 339 // TODO(ajohnsen): We need to figure out when to do this. It should be after |
340 // we have updated class fields, but before we hit 'computeSystem'. | 340 // we have updated class fields, but before we hit 'computeSystem'. |
341 updateImplicitAccessors(context.backend); | 341 updateImplicitAccessors(context.backend); |
342 | 342 |
343 commands.add(new PushFromMap(MapId.classes, classId)); | 343 commands.add(new PushFromMap(MapId.classes, classId)); |
344 | 344 |
345 PersistentMap<int, int> methodTable = computeMethodTable(); | 345 PersistentMap<int, int> methodTable = computeMethodTable(); |
346 for (int selector in methodTable.keys.toList()..sort()) { | 346 for (int selector in methodTable.keys.toList()..sort()) { |
347 int functionId = methodTable[selector]; | 347 int functionId = methodTable[selector]; |
348 commands.add(new PushNewInteger(selector)); | 348 commands.add(new PushNewInteger(selector)); |
349 commands.add(new PushFromMap(MapId.methods, functionId)); | 349 commands.add(new PushFromMap(MapId.methods, functionId)); |
350 } | 350 } |
351 commands.add(new ChangeMethodTable(methodTable.length)); | 351 commands.add(new ChangeMethodTable(methodTable.length)); |
352 | 352 |
353 List<FieldElement> fieldsList = <FieldElement>[]; | 353 List<FieldElement> fieldsList = <FieldElement>[]; |
354 forEachField(element, (field) { fieldsList.add(field); }); | 354 forEachField(element, (field) { fieldsList.add(field); }); |
355 | 355 |
356 return new FletchClass( | 356 return new DartinoClass( |
357 classId, | 357 classId, |
358 // TODO(ajohnsen): Take name in FletchClassBuilder constructor. | 358 // TODO(ajohnsen): Take name in DartinoClassBuilder constructor. |
359 element == null ? '<internal>' : element.name, | 359 element == null ? '<internal>' : element.name, |
360 element, | 360 element, |
361 superclass == null ? -1 : superclass.classId, | 361 superclass == null ? -1 : superclass.classId, |
362 superclassFields + extraFields, | 362 superclassFields + extraFields, |
363 methodTable, | 363 methodTable, |
364 fieldsList); | 364 fieldsList); |
365 } | 365 } |
366 | 366 |
367 bool computeSchemaChange(List<VmCommand> commands) { | 367 bool computeSchemaChange(List<VmCommand> commands) { |
368 if (!_fieldsChanged) return false; | 368 if (!_fieldsChanged) return false; |
(...skipping 25 matching lines...) Expand all Loading... |
394 } | 394 } |
395 commands.add(new PushNewArray(afterFields.length * 2)); | 395 commands.add(new PushNewArray(afterFields.length * 2)); |
396 | 396 |
397 // Finally, ask the runtime to change the schemas! | 397 // Finally, ask the runtime to change the schemas! |
398 int fieldCountDelta = afterFields.length - klass.fields.length; | 398 int fieldCountDelta = afterFields.length - klass.fields.length; |
399 commands.add(new ChangeSchemas(numberOfClasses, fieldCountDelta)); | 399 commands.add(new ChangeSchemas(numberOfClasses, fieldCountDelta)); |
400 | 400 |
401 return true; | 401 return true; |
402 } | 402 } |
403 } | 403 } |
OLD | NEW |