| 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_system_builder; | 5 library dartino_compiler.dartino_system_builder; |
| 6 | 6 |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:compiler/src/constants/values.dart' show | 9 import 'package:compiler/src/constants/values.dart' show |
| 10 ConstantValue, | 10 ConstantValue, |
| 11 ConstructedConstantValue, | 11 ConstructedConstantValue, |
| 12 DeferredConstantValue, | 12 DeferredConstantValue, |
| 13 FunctionConstantValue, | 13 FunctionConstantValue, |
| 14 IntConstantValue, | 14 IntConstantValue, |
| 15 ListConstantValue, | 15 ListConstantValue, |
| 16 MapConstantValue, | 16 MapConstantValue, |
| 17 StringConstantValue; | 17 StringConstantValue; |
| 18 | 18 |
| 19 import 'package:compiler/src/elements/elements.dart' show | 19 import 'package:compiler/src/elements/elements.dart' show |
| 20 ClassElement, | 20 ClassElement, |
| 21 ConstructorElement, | 21 ConstructorElement, |
| 22 Element, | 22 Element, |
| 23 FieldElement, | 23 FieldElement, |
| 24 FunctionElement, | 24 FunctionElement, |
| 25 FunctionSignature, | 25 FunctionSignature, |
| 26 MemberElement; | 26 MemberElement; |
| 27 | 27 |
| 28 import 'package:compiler/src/universe/call_structure.dart' show | 28 import 'package:compiler/src/universe/call_structure.dart' show |
| 29 CallStructure; | 29 CallStructure; |
| 30 | 30 |
| 31 import 'package:persistent/persistent.dart' show | 31 import 'package:persistent/persistent.dart' show |
| 32 PersistentMap; | 32 PersistentMap; |
| 33 | 33 |
| 34 import 'fletch_constants.dart' show | 34 import 'dartino_constants.dart' show |
| 35 FletchClassConstant, | 35 DartinoClassConstant, |
| 36 FletchFunctionConstant, | 36 DartinoFunctionConstant, |
| 37 FletchClassInstanceConstant; | 37 DartinoClassInstanceConstant; |
| 38 | 38 |
| 39 import 'fletch_class_builder.dart'; | 39 import 'dartino_class_builder.dart'; |
| 40 import 'fletch_context.dart'; | 40 import 'dartino_context.dart'; |
| 41 import 'fletch_function_builder.dart'; | 41 import 'dartino_function_builder.dart'; |
| 42 | 42 |
| 43 import '../fletch_system.dart'; | 43 import '../dartino_system.dart'; |
| 44 import '../vm_commands.dart'; | 44 import '../vm_commands.dart'; |
| 45 | 45 |
| 46 class FletchSystemBuilder { | 46 class DartinoSystemBuilder { |
| 47 final FletchSystem predecessorSystem; | 47 final DartinoSystem predecessorSystem; |
| 48 final int functionIdStart; | 48 final int functionIdStart; |
| 49 final int classIdStart; | 49 final int classIdStart; |
| 50 | 50 |
| 51 final List<FletchFunctionBuilder> _newFunctions = <FletchFunctionBuilder>[]; | 51 final List<DartinoFunctionBuilder> _newFunctions = <DartinoFunctionBuilder>[]; |
| 52 final Map<int, FletchClassBuilder> _newClasses = <int, FletchClassBuilder>{}; | 52 final Map<int, DartinoClassBuilder> _newClasses = <int, DartinoClassBuilder>{}
; |
| 53 final Map<ConstantValue, int> _newConstants = <ConstantValue, int>{}; | 53 final Map<ConstantValue, int> _newConstants = <ConstantValue, int>{}; |
| 54 final Map<ParameterStubSignature, FletchFunctionBuilder> _newParameterStubs = | 54 final Map<ParameterStubSignature, DartinoFunctionBuilder> _newParameterStubs = |
| 55 <ParameterStubSignature, FletchFunctionBuilder>{}; | 55 <ParameterStubSignature, DartinoFunctionBuilder>{}; |
| 56 | 56 |
| 57 final Map<int, int> _newGettersByFieldIndex = <int, int>{}; | 57 final Map<int, int> _newGettersByFieldIndex = <int, int>{}; |
| 58 final Map<int, int> _newSettersByFieldIndex = <int, int>{}; | 58 final Map<int, int> _newSettersByFieldIndex = <int, int>{}; |
| 59 | 59 |
| 60 final List<FletchFunction> _removedFunctions = <FletchFunction>[]; | 60 final List<DartinoFunction> _removedFunctions = <DartinoFunction>[]; |
| 61 | 61 |
| 62 final Map<Element, FletchFunctionBuilder> _functionBuildersByElement = | 62 final Map<Element, DartinoFunctionBuilder> _functionBuildersByElement = |
| 63 <Element, FletchFunctionBuilder>{}; | 63 <Element, DartinoFunctionBuilder>{}; |
| 64 | 64 |
| 65 final Map<ClassElement, FletchClassBuilder> _classBuildersByElement = | 65 final Map<ClassElement, DartinoClassBuilder> _classBuildersByElement = |
| 66 <ClassElement, FletchClassBuilder>{}; | 66 <ClassElement, DartinoClassBuilder>{}; |
| 67 | 67 |
| 68 final Map<ConstructorElement, FletchFunctionBuilder> | 68 final Map<ConstructorElement, DartinoFunctionBuilder> |
| 69 _newConstructorInitializers = | 69 _newConstructorInitializers = |
| 70 <ConstructorElement, FletchFunctionBuilder>{}; | 70 <ConstructorElement, DartinoFunctionBuilder>{}; |
| 71 | 71 |
| 72 // TODO(ajohnsen): By function/class? | 72 // TODO(ajohnsen): By function/class? |
| 73 final Map<Element, List<FunctionElement>> _replaceUsage = | 73 final Map<Element, List<FunctionElement>> _replaceUsage = |
| 74 <Element, List<FunctionElement>>{}; | 74 <Element, List<FunctionElement>>{}; |
| 75 | 75 |
| 76 final Map<int, int> _newTearoffsById = <int, int>{}; | 76 final Map<int, int> _newTearoffsById = <int, int>{}; |
| 77 | 77 |
| 78 final int maxInt64 = (1 << 63) - 1; | 78 final int maxInt64 = (1 << 63) - 1; |
| 79 final int minInt64 = -(1 << 63); | 79 final int minInt64 = -(1 << 63); |
| 80 | 80 |
| 81 final Map<int, String> _symbolByFletchSelectorId = <int, String>{}; | 81 final Map<int, String> _symbolByDartinoSelectorId = <int, String>{}; |
| 82 | 82 |
| 83 FletchSystemBuilder(FletchSystem predecessorSystem) | 83 DartinoSystemBuilder(DartinoSystem predecessorSystem) |
| 84 : this.predecessorSystem = predecessorSystem, | 84 : this.predecessorSystem = predecessorSystem, |
| 85 this.functionIdStart = predecessorSystem.computeMaxFunctionId() + 1, | 85 this.functionIdStart = predecessorSystem.computeMaxFunctionId() + 1, |
| 86 this.classIdStart = predecessorSystem.computeMaxClassId() + 1; | 86 this.classIdStart = predecessorSystem.computeMaxClassId() + 1; |
| 87 | 87 |
| 88 int lookupConstantIdByValue(ConstantValue value) { | 88 int lookupConstantIdByValue(ConstantValue value) { |
| 89 int id = _newConstants[value]; | 89 int id = _newConstants[value]; |
| 90 if (id != null) return id; | 90 if (id != null) return id; |
| 91 FletchConstant constant = predecessorSystem.lookupConstantByValue(value); | 91 DartinoConstant constant = predecessorSystem.lookupConstantByValue(value); |
| 92 return constant?.id; | 92 return constant?.id; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void replaceUsage(Element element, FunctionElement usage) { | 95 void replaceUsage(Element element, FunctionElement usage) { |
| 96 _replaceUsage.putIfAbsent(element, () => []).add(usage); | 96 _replaceUsage.putIfAbsent(element, () => []).add(usage); |
| 97 } | 97 } |
| 98 | 98 |
| 99 FletchFunctionBuilder newFunctionBuilder( | 99 DartinoFunctionBuilder newFunctionBuilder( |
| 100 FletchFunctionKind kind, | 100 DartinoFunctionKind kind, |
| 101 int arity, | 101 int arity, |
| 102 {String name, | 102 {String name, |
| 103 Element element, | 103 Element element, |
| 104 FunctionSignature signature, | 104 FunctionSignature signature, |
| 105 int memberOf, | 105 int memberOf, |
| 106 Element mapByElement}) { | 106 Element mapByElement}) { |
| 107 int nextFunctionId = functionIdStart + _newFunctions.length; | 107 int nextFunctionId = functionIdStart + _newFunctions.length; |
| 108 FletchFunctionBuilder builder = new FletchFunctionBuilder( | 108 DartinoFunctionBuilder builder = new DartinoFunctionBuilder( |
| 109 nextFunctionId, | 109 nextFunctionId, |
| 110 kind, | 110 kind, |
| 111 arity, | 111 arity, |
| 112 name: name, | 112 name: name, |
| 113 element: element, | 113 element: element, |
| 114 signature: signature, | 114 signature: signature, |
| 115 memberOf: memberOf); | 115 memberOf: memberOf); |
| 116 _newFunctions.add(builder); | 116 _newFunctions.add(builder); |
| 117 if (mapByElement != null) { | 117 if (mapByElement != null) { |
| 118 _functionBuildersByElement[mapByElement] = builder; | 118 _functionBuildersByElement[mapByElement] = builder; |
| 119 } | 119 } |
| 120 return builder; | 120 return builder; |
| 121 } | 121 } |
| 122 | 122 |
| 123 FletchFunctionBuilder newFunctionBuilderWithSignature( | 123 DartinoFunctionBuilder newFunctionBuilderWithSignature( |
| 124 String name, | 124 String name, |
| 125 Element element, | 125 Element element, |
| 126 FunctionSignature signature, | 126 FunctionSignature signature, |
| 127 int memberOf, | 127 int memberOf, |
| 128 {FletchFunctionKind kind: FletchFunctionKind.NORMAL, | 128 {DartinoFunctionKind kind: DartinoFunctionKind.NORMAL, |
| 129 Element mapByElement}) { | 129 Element mapByElement}) { |
| 130 int arity = signature.parameterCount + (memberOf != null ? 1 : 0); | 130 int arity = signature.parameterCount + (memberOf != null ? 1 : 0); |
| 131 return newFunctionBuilder( | 131 return newFunctionBuilder( |
| 132 kind, | 132 kind, |
| 133 arity, | 133 arity, |
| 134 name: name, | 134 name: name, |
| 135 element: element, | 135 element: element, |
| 136 signature: signature, | 136 signature: signature, |
| 137 memberOf: memberOf, | 137 memberOf: memberOf, |
| 138 mapByElement: mapByElement); | 138 mapByElement: mapByElement); |
| 139 } | 139 } |
| 140 | 140 |
| 141 FletchFunctionBase lookupFunction(int functionId) { | 141 DartinoFunctionBase lookupFunction(int functionId) { |
| 142 if (functionId < functionIdStart) { | 142 if (functionId < functionIdStart) { |
| 143 return predecessorSystem.lookupFunctionById(functionId); | 143 return predecessorSystem.lookupFunctionById(functionId); |
| 144 } else { | 144 } else { |
| 145 return lookupFunctionBuilder(functionId); | 145 return lookupFunctionBuilder(functionId); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 FletchFunctionBuilder lookupFunctionBuilder(int functionId) { | 149 DartinoFunctionBuilder lookupFunctionBuilder(int functionId) { |
| 150 return _newFunctions[functionId - functionIdStart]; | 150 return _newFunctions[functionId - functionIdStart]; |
| 151 } | 151 } |
| 152 | 152 |
| 153 FletchFunctionBase lookupFunctionByElement(Element element) { | 153 DartinoFunctionBase lookupFunctionByElement(Element element) { |
| 154 FletchFunctionBase function = _functionBuildersByElement[element]; | 154 DartinoFunctionBase function = _functionBuildersByElement[element]; |
| 155 if (function != null) return function; | 155 if (function != null) return function; |
| 156 return predecessorSystem.lookupFunctionByElement(element); | 156 return predecessorSystem.lookupFunctionByElement(element); |
| 157 } | 157 } |
| 158 | 158 |
| 159 FletchFunctionBuilder lookupFunctionBuilderByElement(Element element) { | 159 DartinoFunctionBuilder lookupFunctionBuilderByElement(Element element) { |
| 160 return _functionBuildersByElement[element]; | 160 return _functionBuildersByElement[element]; |
| 161 } | 161 } |
| 162 | 162 |
| 163 FletchFunctionBase lookupConstructorInitializerByElement( | 163 DartinoFunctionBase lookupConstructorInitializerByElement( |
| 164 ConstructorElement element) { | 164 ConstructorElement element) { |
| 165 assert(element.isImplementation); | 165 assert(element.isImplementation); |
| 166 FletchFunctionBase function = _newConstructorInitializers[element]; | 166 DartinoFunctionBase function = _newConstructorInitializers[element]; |
| 167 if (function != null) return function; | 167 if (function != null) return function; |
| 168 return predecessorSystem.lookupConstructorInitializerByElement(element); | 168 return predecessorSystem.lookupConstructorInitializerByElement(element); |
| 169 } | 169 } |
| 170 | 170 |
| 171 FletchFunctionBuilder newConstructorInitializer(ConstructorElement element) { | 171 DartinoFunctionBuilder newConstructorInitializer(ConstructorElement element) { |
| 172 assert(element.isImplementation); | 172 assert(element.isImplementation); |
| 173 FletchFunctionBuilder builder = newFunctionBuilderWithSignature( | 173 DartinoFunctionBuilder builder = newFunctionBuilderWithSignature( |
| 174 element.name, | 174 element.name, |
| 175 element, | 175 element, |
| 176 element.functionSignature, | 176 element.functionSignature, |
| 177 null, | 177 null, |
| 178 kind: FletchFunctionKind.INITIALIZER_LIST); | 178 kind: DartinoFunctionKind.INITIALIZER_LIST); |
| 179 _newConstructorInitializers[element] = builder; | 179 _newConstructorInitializers[element] = builder; |
| 180 return builder; | 180 return builder; |
| 181 } | 181 } |
| 182 | 182 |
| 183 int lookupTearOffById(int functionId) { | 183 int lookupTearOffById(int functionId) { |
| 184 int id = _newTearoffsById[functionId]; | 184 int id = _newTearoffsById[functionId]; |
| 185 if (id != null) return id; | 185 if (id != null) return id; |
| 186 return predecessorSystem.lookupTearOffById(functionId); | 186 return predecessorSystem.lookupTearOffById(functionId); |
| 187 } | 187 } |
| 188 | 188 |
| 189 FletchFunctionBuilder newTearOff(FletchFunctionBase function, int classId) { | 189 DartinoFunctionBuilder newTearOff(DartinoFunctionBase function, int classId) { |
| 190 FletchFunctionBuilder builder = newFunctionBuilderWithSignature( | 190 DartinoFunctionBuilder builder = newFunctionBuilderWithSignature( |
| 191 'call', | 191 'call', |
| 192 null, | 192 null, |
| 193 function.signature, | 193 function.signature, |
| 194 classId); | 194 classId); |
| 195 _newTearoffsById[function.functionId] = builder.functionId; | 195 _newTearoffsById[function.functionId] = builder.functionId; |
| 196 return builder; | 196 return builder; |
| 197 } | 197 } |
| 198 | 198 |
| 199 /// Return a getter for [fieldIndex] if it already exists, return null | 199 /// Return a getter for [fieldIndex] if it already exists, return null |
| 200 /// otherwise. | 200 /// otherwise. |
| 201 int lookupGetterByFieldIndex(int fieldIndex) { | 201 int lookupGetterByFieldIndex(int fieldIndex) { |
| 202 int functionId = _newGettersByFieldIndex[fieldIndex]; | 202 int functionId = _newGettersByFieldIndex[fieldIndex]; |
| 203 if (functionId == null) { | 203 if (functionId == null) { |
| 204 return predecessorSystem.lookupGetterByFieldIndex(fieldIndex); | 204 return predecessorSystem.lookupGetterByFieldIndex(fieldIndex); |
| 205 } | 205 } |
| 206 return functionId; | 206 return functionId; |
| 207 } | 207 } |
| 208 | 208 |
| 209 /// Create a new getter for [fieldIndex]. | 209 /// Create a new getter for [fieldIndex]. |
| 210 FletchFunctionBuilder newGetter(int fieldIndex) { | 210 DartinoFunctionBuilder newGetter(int fieldIndex) { |
| 211 FletchFunctionBuilder builder = | 211 DartinoFunctionBuilder builder = |
| 212 newFunctionBuilder(FletchFunctionKind.ACCESSOR, 1); | 212 newFunctionBuilder(DartinoFunctionKind.ACCESSOR, 1); |
| 213 _newGettersByFieldIndex[fieldIndex] = builder.functionId; | 213 _newGettersByFieldIndex[fieldIndex] = builder.functionId; |
| 214 return builder; | 214 return builder; |
| 215 } | 215 } |
| 216 | 216 |
| 217 /// Return a getter for [fieldIndex]. If one doesn't already exists, one will | 217 /// Return a getter for [fieldIndex]. If one doesn't already exists, one will |
| 218 /// be created. | 218 /// be created. |
| 219 int getGetterByFieldIndex(int fieldIndex) { | 219 int getGetterByFieldIndex(int fieldIndex) { |
| 220 int id = lookupGetterByFieldIndex(fieldIndex); | 220 int id = lookupGetterByFieldIndex(fieldIndex); |
| 221 if (id != null) return id; | 221 if (id != null) return id; |
| 222 FletchFunctionBuilder stub = newGetter(fieldIndex); | 222 DartinoFunctionBuilder stub = newGetter(fieldIndex); |
| 223 stub.assembler | 223 stub.assembler |
| 224 ..loadParameter(0) | 224 ..loadParameter(0) |
| 225 ..loadField(fieldIndex) | 225 ..loadField(fieldIndex) |
| 226 ..ret() | 226 ..ret() |
| 227 ..methodEnd(); | 227 ..methodEnd(); |
| 228 return stub.functionId; | 228 return stub.functionId; |
| 229 } | 229 } |
| 230 | 230 |
| 231 /// Return a setter for [fieldIndex] if it already exists, return null | 231 /// Return a setter for [fieldIndex] if it already exists, return null |
| 232 /// otherwise. | 232 /// otherwise. |
| 233 int lookupSetterByFieldIndex(int fieldIndex) { | 233 int lookupSetterByFieldIndex(int fieldIndex) { |
| 234 int functionId = _newSettersByFieldIndex[fieldIndex]; | 234 int functionId = _newSettersByFieldIndex[fieldIndex]; |
| 235 if (functionId == null) { | 235 if (functionId == null) { |
| 236 return predecessorSystem.lookupSetterByFieldIndex(fieldIndex); | 236 return predecessorSystem.lookupSetterByFieldIndex(fieldIndex); |
| 237 } | 237 } |
| 238 return functionId; | 238 return functionId; |
| 239 } | 239 } |
| 240 | 240 |
| 241 /// Create a new setter for [fieldIndex]. | 241 /// Create a new setter for [fieldIndex]. |
| 242 FletchFunctionBuilder newSetter(int fieldIndex) { | 242 DartinoFunctionBuilder newSetter(int fieldIndex) { |
| 243 FletchFunctionBuilder builder = | 243 DartinoFunctionBuilder builder = |
| 244 newFunctionBuilder(FletchFunctionKind.ACCESSOR, 2); | 244 newFunctionBuilder(DartinoFunctionKind.ACCESSOR, 2); |
| 245 _newSettersByFieldIndex[fieldIndex] = builder.functionId; | 245 _newSettersByFieldIndex[fieldIndex] = builder.functionId; |
| 246 return builder; | 246 return builder; |
| 247 } | 247 } |
| 248 | 248 |
| 249 /// Return a setter for [fieldIndex]. If one doesn't already exists, one will | 249 /// Return a setter for [fieldIndex]. If one doesn't already exists, one will |
| 250 /// be created. | 250 /// be created. |
| 251 int getSetterByFieldIndex(int fieldIndex) { | 251 int getSetterByFieldIndex(int fieldIndex) { |
| 252 int id = lookupSetterByFieldIndex(fieldIndex); | 252 int id = lookupSetterByFieldIndex(fieldIndex); |
| 253 if (id != null) return id; | 253 if (id != null) return id; |
| 254 FletchFunctionBuilder stub = newSetter(fieldIndex); | 254 DartinoFunctionBuilder stub = newSetter(fieldIndex); |
| 255 stub.assembler | 255 stub.assembler |
| 256 ..loadParameter(0) | 256 ..loadParameter(0) |
| 257 ..loadParameter(1) | 257 ..loadParameter(1) |
| 258 ..storeField(fieldIndex) | 258 ..storeField(fieldIndex) |
| 259 // Top is at this point the rhs argument, thus the return value. | 259 // Top is at this point the rhs argument, thus the return value. |
| 260 ..ret() | 260 ..ret() |
| 261 ..methodEnd(); | 261 ..methodEnd(); |
| 262 return stub.functionId; | 262 return stub.functionId; |
| 263 } | 263 } |
| 264 | 264 |
| 265 void forgetFunction(FletchFunction function) { | 265 void forgetFunction(DartinoFunction function) { |
| 266 _removedFunctions.add(function); | 266 _removedFunctions.add(function); |
| 267 } | 267 } |
| 268 | 268 |
| 269 List<FletchFunctionBuilder> getNewFunctions() => _newFunctions; | 269 List<DartinoFunctionBuilder> getNewFunctions() => _newFunctions; |
| 270 | 270 |
| 271 FletchClassBuilder getTearoffClassBuilder( | 271 DartinoClassBuilder getTearoffClassBuilder( |
| 272 FletchFunctionBase function, | 272 DartinoFunctionBase function, |
| 273 FletchClassBuilder superclass) { | 273 DartinoClassBuilder superclass) { |
| 274 int functionId = lookupTearOffById(function.functionId); | 274 int functionId = lookupTearOffById(function.functionId); |
| 275 if (functionId == null) return null; | 275 if (functionId == null) return null; |
| 276 FletchFunctionBase functionBuilder = lookupFunction(functionId); | 276 DartinoFunctionBase functionBuilder = lookupFunction(functionId); |
| 277 FletchClassBuilder classBuilder = | 277 DartinoClassBuilder classBuilder = |
| 278 lookupClassBuilder(functionBuilder.memberOf); | 278 lookupClassBuilder(functionBuilder.memberOf); |
| 279 if (classBuilder != null) return classBuilder; | 279 if (classBuilder != null) return classBuilder; |
| 280 FletchClass cls = lookupClass(functionBuilder.memberOf); | 280 DartinoClass cls = lookupClass(functionBuilder.memberOf); |
| 281 return newClassBuilderInternal(cls, superclass); | 281 return newClassBuilderInternal(cls, superclass); |
| 282 } | 282 } |
| 283 | 283 |
| 284 FletchClassBuilder newClassBuilderInternal( | 284 DartinoClassBuilder newClassBuilderInternal( |
| 285 FletchClass klass, | 285 DartinoClass klass, |
| 286 FletchClassBuilder superclass) { | 286 DartinoClassBuilder superclass) { |
| 287 FletchClassBuilder builder = new FletchPatchClassBuilder( | 287 DartinoClassBuilder builder = new DartinoPatchClassBuilder( |
| 288 klass, superclass); | 288 klass, superclass); |
| 289 assert(_newClasses[klass.classId] == null); | 289 assert(_newClasses[klass.classId] == null); |
| 290 _newClasses[klass.classId] = builder; | 290 _newClasses[klass.classId] = builder; |
| 291 return builder; | 291 return builder; |
| 292 } | 292 } |
| 293 | 293 |
| 294 FletchClassBuilder newPatchClassBuilder( | 294 DartinoClassBuilder newPatchClassBuilder( |
| 295 int classId, | 295 int classId, |
| 296 FletchClassBuilder superclass) { | 296 DartinoClassBuilder superclass) { |
| 297 FletchClass klass = lookupClass(classId); | 297 DartinoClass klass = lookupClass(classId); |
| 298 return newClassBuilderInternal(klass, superclass); | 298 return newClassBuilderInternal(klass, superclass); |
| 299 } | 299 } |
| 300 | 300 |
| 301 FletchClassBuilder newClassBuilder( | 301 DartinoClassBuilder newClassBuilder( |
| 302 ClassElement element, | 302 ClassElement element, |
| 303 FletchClassBuilder superclass, | 303 DartinoClassBuilder superclass, |
| 304 bool isBuiltin, | 304 bool isBuiltin, |
| 305 {int extraFields: 0}) { | 305 {int extraFields: 0}) { |
| 306 if (element != null) { | 306 if (element != null) { |
| 307 FletchClass klass = predecessorSystem.lookupClassByElement(element); | 307 DartinoClass klass = predecessorSystem.lookupClassByElement(element); |
| 308 if (klass != null) { | 308 if (klass != null) { |
| 309 FletchClassBuilder builder = newClassBuilderInternal(klass, superclass); | 309 DartinoClassBuilder builder = newClassBuilderInternal(klass, superclass)
; |
| 310 _classBuildersByElement[element] = builder; | 310 _classBuildersByElement[element] = builder; |
| 311 return builder; | 311 return builder; |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 int nextClassId = classIdStart + _newClasses.length; | 315 int nextClassId = classIdStart + _newClasses.length; |
| 316 FletchClassBuilder builder = new FletchNewClassBuilder( | 316 DartinoClassBuilder builder = new DartinoNewClassBuilder( |
| 317 nextClassId, | 317 nextClassId, |
| 318 element, | 318 element, |
| 319 superclass, | 319 superclass, |
| 320 isBuiltin, | 320 isBuiltin, |
| 321 extraFields); | 321 extraFields); |
| 322 _newClasses[nextClassId] = builder; | 322 _newClasses[nextClassId] = builder; |
| 323 if (element != null) _classBuildersByElement[element] = builder; | 323 if (element != null) _classBuildersByElement[element] = builder; |
| 324 return builder; | 324 return builder; |
| 325 } | 325 } |
| 326 | 326 |
| 327 FletchClass lookupClass(int classId) { | 327 DartinoClass lookupClass(int classId) { |
| 328 return predecessorSystem.classesById[classId]; | 328 return predecessorSystem.classesById[classId]; |
| 329 } | 329 } |
| 330 | 330 |
| 331 FletchClassBuilder lookupClassBuilder(int classId) { | 331 DartinoClassBuilder lookupClassBuilder(int classId) { |
| 332 return _newClasses[classId]; | 332 return _newClasses[classId]; |
| 333 } | 333 } |
| 334 | 334 |
| 335 FletchClassBuilder lookupClassBuilderByElement(ClassElement element) { | 335 DartinoClassBuilder lookupClassBuilderByElement(ClassElement element) { |
| 336 return _classBuildersByElement[element]; | 336 return _classBuildersByElement[element]; |
| 337 } | 337 } |
| 338 | 338 |
| 339 Iterable<FletchClassBuilder> getNewClasses() => _newClasses.values; | 339 Iterable<DartinoClassBuilder> getNewClasses() => _newClasses.values; |
| 340 | 340 |
| 341 void registerConstant(ConstantValue constant, FletchContext context) { | 341 void registerConstant(ConstantValue constant, DartinoContext context) { |
| 342 if (predecessorSystem.lookupConstantByValue(constant) != null) return; | 342 if (predecessorSystem.lookupConstantByValue(constant) != null) return; |
| 343 _newConstants.putIfAbsent(constant, () { | 343 _newConstants.putIfAbsent(constant, () { |
| 344 if (constant.isConstructedObject) { | 344 if (constant.isConstructedObject) { |
| 345 context.registerConstructedConstantValue(constant); | 345 context.registerConstructedConstantValue(constant); |
| 346 } else if (constant.isFunction) { | 346 } else if (constant.isFunction) { |
| 347 context.registerFunctionConstantValue(constant); | 347 context.registerFunctionConstantValue(constant); |
| 348 } | 348 } |
| 349 for (ConstantValue value in constant.getDependencies()) { | 349 for (ConstantValue value in constant.getDependencies()) { |
| 350 registerConstant(value, context); | 350 registerConstant(value, context); |
| 351 } | 351 } |
| 352 // TODO(zarah): Compute max constant id (as for functions an classes) | 352 // TODO(zarah): Compute max constant id (as for functions an classes) |
| 353 // instead of using constantsById.length | 353 // instead of using constantsById.length |
| 354 return predecessorSystem.constantsById.length + _newConstants.length; | 354 return predecessorSystem.constantsById.length + _newConstants.length; |
| 355 }); | 355 }); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void registerSymbol(String symbol, int fletchSelectorId) { | 358 void registerSymbol(String symbol, int dartinoSelectorId) { |
| 359 _symbolByFletchSelectorId[fletchSelectorId] = symbol; | 359 _symbolByDartinoSelectorId[dartinoSelectorId] = symbol; |
| 360 } | 360 } |
| 361 | 361 |
| 362 FletchFunctionBase lookupParameterStub(ParameterStubSignature signature) { | 362 DartinoFunctionBase lookupParameterStub(ParameterStubSignature signature) { |
| 363 FletchFunctionBuilder stub = _newParameterStubs[signature]; | 363 DartinoFunctionBuilder stub = _newParameterStubs[signature]; |
| 364 if (stub != null) return stub; | 364 if (stub != null) return stub; |
| 365 return predecessorSystem.lookupParameterStub(signature); | 365 return predecessorSystem.lookupParameterStub(signature); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void registerParameterStub( | 368 void registerParameterStub( |
| 369 ParameterStubSignature signature, | 369 ParameterStubSignature signature, |
| 370 FletchFunctionBuilder stub) { | 370 DartinoFunctionBuilder stub) { |
| 371 assert(lookupParameterStub(signature) == null); | 371 assert(lookupParameterStub(signature) == null); |
| 372 _newParameterStubs[signature] = stub; | 372 _newParameterStubs[signature] = stub; |
| 373 } | 373 } |
| 374 | 374 |
| 375 FletchSystem computeSystem(FletchContext context, List<VmCommand> commands) { | 375 DartinoSystem computeSystem(DartinoContext context, List<VmCommand> commands)
{ |
| 376 // TODO(ajohnsen): Consider if the incremental compiler should be aware of | 376 // TODO(ajohnsen): Consider if the incremental compiler should be aware of |
| 377 // callMain, when detecting changes. | 377 // callMain, when detecting changes. |
| 378 FunctionElement callMain = | 378 FunctionElement callMain = |
| 379 context.backend.fletchSystemLibrary.findLocal('callMain'); | 379 context.backend.dartinoSystemLibrary.findLocal('callMain'); |
| 380 replaceUsage(callMain, context.compiler.mainFunction); | 380 replaceUsage(callMain, context.compiler.mainFunction); |
| 381 | 381 |
| 382 int changes = 0; | 382 int changes = 0; |
| 383 | 383 |
| 384 // Remove all removed FletchFunctions. | 384 // Remove all removed DartinoFunctions. |
| 385 for (FletchFunction function in _removedFunctions) { | 385 for (DartinoFunction function in _removedFunctions) { |
| 386 commands.add(new RemoveFromMap(MapId.methods, function.functionId)); | 386 commands.add(new RemoveFromMap(MapId.methods, function.functionId)); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Create all new FletchFunctions. | 389 // Create all new DartinoFunctions. |
| 390 List<FletchFunction> functions = <FletchFunction>[]; | 390 List<DartinoFunction> functions = <DartinoFunction>[]; |
| 391 for (FletchFunctionBuilder builder in _newFunctions) { | 391 for (DartinoFunctionBuilder builder in _newFunctions) { |
| 392 context.compiler.reporter.withCurrentElement(builder.element, () { | 392 context.compiler.reporter.withCurrentElement(builder.element, () { |
| 393 functions.add(builder.finalizeFunction(context, commands)); | 393 functions.add(builder.finalizeFunction(context, commands)); |
| 394 }); | 394 }); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // Create all new FletchClasses. | 397 // Create all new DartinoClasses. |
| 398 List<FletchClass> classes = <FletchClass>[]; | 398 List<DartinoClass> classes = <DartinoClass>[]; |
| 399 for (FletchClassBuilder builder in _newClasses.values) { | 399 for (DartinoClassBuilder builder in _newClasses.values) { |
| 400 classes.add(builder.finalizeClass(context, commands)); | 400 classes.add(builder.finalizeClass(context, commands)); |
| 401 changes++; | 401 changes++; |
| 402 } | 402 } |
| 403 | 403 |
| 404 // Create all statics. | 404 // Create all statics. |
| 405 // TODO(ajohnsen): Should be part of the fletch system. Does not work with | 405 // TODO(ajohnsen): Should be part of the dartino system. Does not work with |
| 406 // incremental. | 406 // incremental. |
| 407 if (predecessorSystem.isEmpty) { | 407 if (predecessorSystem.isEmpty) { |
| 408 context.forEachStatic((element, index) { | 408 context.forEachStatic((element, index) { |
| 409 FletchFunctionBuilder initializer = | 409 DartinoFunctionBuilder initializer = |
| 410 context.backend.lazyFieldInitializers[element]; | 410 context.backend.lazyFieldInitializers[element]; |
| 411 if (initializer != null) { | 411 if (initializer != null) { |
| 412 commands.add(new PushFromMap(MapId.methods, initializer.functionId)); | 412 commands.add(new PushFromMap(MapId.methods, initializer.functionId)); |
| 413 commands.add(const PushNewInitializer()); | 413 commands.add(const PushNewInitializer()); |
| 414 } else { | 414 } else { |
| 415 commands.add(const PushNull()); | 415 commands.add(const PushNull()); |
| 416 } | 416 } |
| 417 }); | 417 }); |
| 418 commands.add(new ChangeStatics(context.staticIndices.length)); | 418 commands.add(new ChangeStatics(context.staticIndices.length)); |
| 419 changes++; | 419 changes++; |
| 420 } | 420 } |
| 421 | 421 |
| 422 // Create all FletchConstants. | 422 // Create all DartinoConstants. |
| 423 PersistentMap<int, FletchConstant> constantsById = | 423 PersistentMap<int, DartinoConstant> constantsById = |
| 424 predecessorSystem.constantsById; | 424 predecessorSystem.constantsById; |
| 425 PersistentMap<ConstantValue, FletchConstant> constantsByValue = | 425 PersistentMap<ConstantValue, DartinoConstant> constantsByValue = |
| 426 predecessorSystem.constantsByValue; | 426 predecessorSystem.constantsByValue; |
| 427 _newConstants.forEach((constant, int id) { | 427 _newConstants.forEach((constant, int id) { |
| 428 void addList(List<ConstantValue> list, bool isByteList) { | 428 void addList(List<ConstantValue> list, bool isByteList) { |
| 429 for (ConstantValue entry in list) { | 429 for (ConstantValue entry in list) { |
| 430 int entryId = lookupConstantIdByValue(entry); | 430 int entryId = lookupConstantIdByValue(entry); |
| 431 commands.add(new PushFromMap(MapId.constants, entryId)); | 431 commands.add(new PushFromMap(MapId.constants, entryId)); |
| 432 if (entry.isInt) { | 432 if (entry.isInt) { |
| 433 IntConstantValue constant = entry; | 433 IntConstantValue constant = entry; |
| 434 int value = constant.primitiveValue; | 434 int value = constant.primitiveValue; |
| 435 if (value & 0xFF == value) continue; | 435 if (value & 0xFF == value) continue; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 458 if (value > maxInt64 || value < minInt64) { | 458 if (value > maxInt64 || value < minInt64) { |
| 459 assert(context.enableBigint); | 459 assert(context.enableBigint); |
| 460 bool negative = value < 0; | 460 bool negative = value < 0; |
| 461 value = negative ? -value : value; | 461 value = negative ? -value : value; |
| 462 var parts = new List(); | 462 var parts = new List(); |
| 463 while (value != 0) { | 463 while (value != 0) { |
| 464 parts.add(value & 0xffffffff); | 464 parts.add(value & 0xffffffff); |
| 465 value >>= 32; | 465 value >>= 32; |
| 466 } | 466 } |
| 467 | 467 |
| 468 // TODO(ajohnsen): Avoid usage of builders (should be FletchClass). | 468 // TODO(ajohnsen): Avoid usage of builders (should be DartinoClass). |
| 469 FletchClassBuilder bigintClassBuilder = | 469 DartinoClassBuilder bigintClassBuilder = |
| 470 _classBuildersByElement[context.backend.bigintClass]; | 470 _classBuildersByElement[context.backend.bigintClass]; |
| 471 FletchClassBuilder uint32DigitsClassBuilder = | 471 DartinoClassBuilder uint32DigitsClassBuilder = |
| 472 _classBuildersByElement[context.backend.uint32DigitsClass]; | 472 _classBuildersByElement[context.backend.uint32DigitsClass]; |
| 473 | 473 |
| 474 commands.add(new PushNewBigInteger( | 474 commands.add(new PushNewBigInteger( |
| 475 negative, | 475 negative, |
| 476 parts, | 476 parts, |
| 477 MapId.classes, | 477 MapId.classes, |
| 478 bigintClassBuilder.classId, | 478 bigintClassBuilder.classId, |
| 479 uint32DigitsClassBuilder.classId)); | 479 uint32DigitsClassBuilder.classId)); |
| 480 } else { | 480 } else { |
| 481 commands.add(new PushNewInteger(constant.primitiveValue)); | 481 commands.add(new PushNewInteger(constant.primitiveValue)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 498 } else if (constant.isList) { | 498 } else if (constant.isList) { |
| 499 addList(constant.entries, true); | 499 addList(constant.entries, true); |
| 500 } else if (constant.isMap) { | 500 } else if (constant.isMap) { |
| 501 MapConstantValue value = constant; | 501 MapConstantValue value = constant; |
| 502 addList(value.keys, false); | 502 addList(value.keys, false); |
| 503 addList(value.values, false); | 503 addList(value.values, false); |
| 504 commands.add(new PushConstantMap(value.length * 2)); | 504 commands.add(new PushConstantMap(value.length * 2)); |
| 505 } else if (constant.isFunction) { | 505 } else if (constant.isFunction) { |
| 506 FunctionConstantValue value = constant; | 506 FunctionConstantValue value = constant; |
| 507 FunctionElement element = value.element; | 507 FunctionElement element = value.element; |
| 508 FletchFunctionBase function = lookupFunctionByElement(element); | 508 DartinoFunctionBase function = lookupFunctionByElement(element); |
| 509 int tearoffId = lookupTearOffById(function.functionId); | 509 int tearoffId = lookupTearOffById(function.functionId); |
| 510 FletchFunctionBase tearoff = lookupFunction(tearoffId); | 510 DartinoFunctionBase tearoff = lookupFunction(tearoffId); |
| 511 commands | 511 commands |
| 512 ..add(new PushFromMap(MapId.classes, tearoff.memberOf)) | 512 ..add(new PushFromMap(MapId.classes, tearoff.memberOf)) |
| 513 ..add(const PushNewInstance()); | 513 ..add(const PushNewInstance()); |
| 514 } else if (constant.isConstructedObject) { | 514 } else if (constant.isConstructedObject) { |
| 515 ConstructedConstantValue value = constant; | 515 ConstructedConstantValue value = constant; |
| 516 ClassElement classElement = value.type.element; | 516 ClassElement classElement = value.type.element; |
| 517 // TODO(ajohnsen): Avoid usage of builders (should be FletchClass). | 517 // TODO(ajohnsen): Avoid usage of builders (should be DartinoClass). |
| 518 FletchClassBuilder classBuilder = _classBuildersByElement[classElement]; | 518 DartinoClassBuilder classBuilder = _classBuildersByElement[classElement]
; |
| 519 | 519 |
| 520 void addIfField(MemberElement member) { | 520 void addIfField(MemberElement member) { |
| 521 if (!member.isField || member.isStatic || member.isPatch) return; | 521 if (!member.isField || member.isStatic || member.isPatch) return; |
| 522 FieldElement fieldElement = member; | 522 FieldElement fieldElement = member; |
| 523 ConstantValue fieldValue = value.fields[fieldElement]; | 523 ConstantValue fieldValue = value.fields[fieldElement]; |
| 524 int fieldId = lookupConstantIdByValue(fieldValue); | 524 int fieldId = lookupConstantIdByValue(fieldValue); |
| 525 commands.add(new PushFromMap(MapId.constants, fieldId)); | 525 commands.add(new PushFromMap(MapId.constants, fieldId)); |
| 526 } | 526 } |
| 527 | 527 |
| 528 // Adds all the fields of [currentClass] in order starting from the top | 528 // Adds all the fields of [currentClass] in order starting from the top |
| 529 // of the inheritance chain, and for each class adds non-patch fields | 529 // of the inheritance chain, and for each class adds non-patch fields |
| 530 // before patch fields. | 530 // before patch fields. |
| 531 void addFields(ClassElement currentClass) { | 531 void addFields(ClassElement currentClass) { |
| 532 if (currentClass.superclass != null) { | 532 if (currentClass.superclass != null) { |
| 533 addFields(currentClass.superclass); | 533 addFields(currentClass.superclass); |
| 534 } | 534 } |
| 535 currentClass.forEachLocalMember(addIfField); | 535 currentClass.forEachLocalMember(addIfField); |
| 536 if (currentClass.isPatched) { | 536 if (currentClass.isPatched) { |
| 537 currentClass.patch.forEachLocalMember(addIfField); | 537 currentClass.patch.forEachLocalMember(addIfField); |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 addFields(classElement); | 541 addFields(classElement); |
| 542 | 542 |
| 543 commands | 543 commands |
| 544 ..add(new PushFromMap(MapId.classes, classBuilder.classId)) | 544 ..add(new PushFromMap(MapId.classes, classBuilder.classId)) |
| 545 ..add(const PushNewInstance()); | 545 ..add(const PushNewInstance()); |
| 546 } else if (constant is FletchClassInstanceConstant) { | 546 } else if (constant is DartinoClassInstanceConstant) { |
| 547 commands | 547 commands |
| 548 ..add(new PushFromMap(MapId.classes, constant.classId)) | 548 ..add(new PushFromMap(MapId.classes, constant.classId)) |
| 549 ..add(const PushNewInstance()); | 549 ..add(const PushNewInstance()); |
| 550 } else if (constant.isType) { | 550 } else if (constant.isType) { |
| 551 // TODO(kasperl): Implement proper support for class literals. At this | 551 // TODO(kasperl): Implement proper support for class literals. At this |
| 552 // point, we've already issues unimplemented errors for the individual | 552 // point, we've already issues unimplemented errors for the individual |
| 553 // accesses to the class literals, so we just let the class literal | 553 // accesses to the class literals, so we just let the class literal |
| 554 // turn into null in the runtime. | 554 // turn into null in the runtime. |
| 555 commands.add(const PushNull()); | 555 commands.add(const PushNull()); |
| 556 } else { | 556 } else { |
| 557 throw "Unsupported constant: ${constant.toStructuredString()}"; | 557 throw "Unsupported constant: ${constant.toStructuredString()}"; |
| 558 } | 558 } |
| 559 FletchConstant fletchConstant = new FletchConstant(id, MapId.constants); | 559 DartinoConstant dartinoConstant = new DartinoConstant(id, MapId.constants)
; |
| 560 constantsByValue = constantsByValue.insert(constant, fletchConstant); | 560 constantsByValue = constantsByValue.insert(constant, dartinoConstant); |
| 561 constantsById = constantsById.insert(id, fletchConstant); | 561 constantsById = constantsById.insert(id, dartinoConstant); |
| 562 commands.add(new PopToMap(MapId.constants, id)); | 562 commands.add(new PopToMap(MapId.constants, id)); |
| 563 }); | 563 }); |
| 564 | 564 |
| 565 // Set super class for classes, now they are resolved. | 565 // Set super class for classes, now they are resolved. |
| 566 for (FletchClass klass in classes) { | 566 for (DartinoClass klass in classes) { |
| 567 if (!klass.hasSuperclassId) continue; | 567 if (!klass.hasSuperclassId) continue; |
| 568 commands.add(new PushFromMap(MapId.classes, klass.classId)); | 568 commands.add(new PushFromMap(MapId.classes, klass.classId)); |
| 569 commands.add(new PushFromMap(MapId.classes, klass.superclassId)); | 569 commands.add(new PushFromMap(MapId.classes, klass.superclassId)); |
| 570 commands.add(const ChangeSuperClass()); | 570 commands.add(const ChangeSuperClass()); |
| 571 changes++; | 571 changes++; |
| 572 } | 572 } |
| 573 | 573 |
| 574 // Change constants for the functions, now that classes and constants has | 574 // Change constants for the functions, now that classes and constants has |
| 575 // been added. | 575 // been added. |
| 576 for (FletchFunction function in functions) { | 576 for (DartinoFunction function in functions) { |
| 577 List<FletchConstant> constants = function.constants; | 577 List<DartinoConstant> constants = function.constants; |
| 578 for (int i = 0; i < constants.length; i++) { | 578 for (int i = 0; i < constants.length; i++) { |
| 579 FletchConstant constant = constants[i]; | 579 DartinoConstant constant = constants[i]; |
| 580 commands | 580 commands |
| 581 ..add(new PushFromMap(MapId.methods, function.functionId)) | 581 ..add(new PushFromMap(MapId.methods, function.functionId)) |
| 582 ..add(new PushFromMap(constant.mapId, constant.id)) | 582 ..add(new PushFromMap(constant.mapId, constant.id)) |
| 583 ..add(new ChangeMethodLiteral(i)); | 583 ..add(new ChangeMethodLiteral(i)); |
| 584 changes++; | 584 changes++; |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 | 587 |
| 588 // Compute all scheme changes. | 588 // Compute all scheme changes. |
| 589 for (FletchClassBuilder builder in _newClasses.values) { | 589 for (DartinoClassBuilder builder in _newClasses.values) { |
| 590 if (builder.computeSchemaChange(commands)) changes++; | 590 if (builder.computeSchemaChange(commands)) changes++; |
| 591 } | 591 } |
| 592 | 592 |
| 593 List<FletchFunction> changedFunctions = <FletchFunction>[]; | 593 List<DartinoFunction> changedFunctions = <DartinoFunction>[]; |
| 594 for (Element element in _replaceUsage.keys) { | 594 for (Element element in _replaceUsage.keys) { |
| 595 // Don't modify already replaced elements. | 595 // Don't modify already replaced elements. |
| 596 if (lookupFunctionBuilderByElement(element) != null) continue; | 596 if (lookupFunctionBuilderByElement(element) != null) continue; |
| 597 | 597 |
| 598 FletchFunction function = | 598 DartinoFunction function = |
| 599 predecessorSystem.lookupFunctionByElement(element); | 599 predecessorSystem.lookupFunctionByElement(element); |
| 600 // Due to false positive, the element can be uncompiled. | 600 // Due to false positive, the element can be uncompiled. |
| 601 if (function == null) continue; | 601 if (function == null) continue; |
| 602 | 602 |
| 603 bool constantsChanged = false; | 603 bool constantsChanged = false; |
| 604 List<FletchConstant> constants = function.constants.toList(); | 604 List<DartinoConstant> constants = function.constants.toList(); |
| 605 for (int i = 0; i < constants.length; i++) { | 605 for (int i = 0; i < constants.length; i++) { |
| 606 FletchConstant constant = constants[i]; | 606 DartinoConstant constant = constants[i]; |
| 607 if (constant.mapId != MapId.methods) continue; | 607 if (constant.mapId != MapId.methods) continue; |
| 608 for (var usage in _replaceUsage[element]) { | 608 for (var usage in _replaceUsage[element]) { |
| 609 FletchFunction oldFunction = | 609 DartinoFunction oldFunction = |
| 610 predecessorSystem.lookupFunctionByElement(usage); | 610 predecessorSystem.lookupFunctionByElement(usage); |
| 611 if (oldFunction == null) continue; | 611 if (oldFunction == null) continue; |
| 612 if (oldFunction.functionId != constant.id) continue; | 612 if (oldFunction.functionId != constant.id) continue; |
| 613 FletchFunctionBuilder newFunction = | 613 DartinoFunctionBuilder newFunction = |
| 614 lookupFunctionBuilderByElement(usage); | 614 lookupFunctionBuilderByElement(usage); |
| 615 | 615 |
| 616 // If the method didn't really change, ignore. | 616 // If the method didn't really change, ignore. |
| 617 if (newFunction == null) continue; | 617 if (newFunction == null) continue; |
| 618 | 618 |
| 619 constant = new FletchConstant(newFunction.functionId, MapId.methods); | 619 constant = new DartinoConstant(newFunction.functionId, MapId.methods); |
| 620 commands | 620 commands |
| 621 ..add(new PushFromMap(MapId.methods, function.functionId)) | 621 ..add(new PushFromMap(MapId.methods, function.functionId)) |
| 622 ..add(new PushFromMap(constant.mapId, constant.id)) | 622 ..add(new PushFromMap(constant.mapId, constant.id)) |
| 623 ..add(new ChangeMethodLiteral(i)); | 623 ..add(new ChangeMethodLiteral(i)); |
| 624 constants[i] = constant; | 624 constants[i] = constant; |
| 625 constantsChanged = true; | 625 constantsChanged = true; |
| 626 changes++; | 626 changes++; |
| 627 break; | 627 break; |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 | 630 |
| 631 if (constantsChanged) { | 631 if (constantsChanged) { |
| 632 changedFunctions.add(function.withReplacedConstants(constants)); | 632 changedFunctions.add(function.withReplacedConstants(constants)); |
| 633 } | 633 } |
| 634 } | 634 } |
| 635 | 635 |
| 636 commands.add(new CommitChanges(changes)); | 636 commands.add(new CommitChanges(changes)); |
| 637 | 637 |
| 638 PersistentMap<int, FletchClass> classesById = predecessorSystem.classesById; | 638 PersistentMap<int, DartinoClass> classesById = predecessorSystem.classesById
; |
| 639 PersistentMap<ClassElement, FletchClass> classesByElement = | 639 PersistentMap<ClassElement, DartinoClass> classesByElement = |
| 640 predecessorSystem.classesByElement; | 640 predecessorSystem.classesByElement; |
| 641 | 641 |
| 642 for (FletchClass klass in classes) { | 642 for (DartinoClass klass in classes) { |
| 643 classesById = classesById.insert(klass.classId, klass); | 643 classesById = classesById.insert(klass.classId, klass); |
| 644 if (klass.element != null) { | 644 if (klass.element != null) { |
| 645 classesByElement = classesByElement.insert(klass.element, klass); | 645 classesByElement = classesByElement.insert(klass.element, klass); |
| 646 } | 646 } |
| 647 } | 647 } |
| 648 | 648 |
| 649 PersistentMap<int, FletchFunction> functionsById = | 649 PersistentMap<int, DartinoFunction> functionsById = |
| 650 predecessorSystem.functionsById; | 650 predecessorSystem.functionsById; |
| 651 PersistentMap<Element, FletchFunction> functionsByElement = | 651 PersistentMap<Element, DartinoFunction> functionsByElement = |
| 652 predecessorSystem.functionsByElement; | 652 predecessorSystem.functionsByElement; |
| 653 | 653 |
| 654 for (FletchFunction function in changedFunctions) { | 654 for (DartinoFunction function in changedFunctions) { |
| 655 assert(functionsById[function.functionId] != null); | 655 assert(functionsById[function.functionId] != null); |
| 656 functionsById = functionsById.insert(function.functionId, function); | 656 functionsById = functionsById.insert(function.functionId, function); |
| 657 Element element = function.element; | 657 Element element = function.element; |
| 658 if (element != null) { | 658 if (element != null) { |
| 659 assert(functionsByElement[element] != null); | 659 assert(functionsByElement[element] != null); |
| 660 functionsByElement = functionsByElement.insert(element, function); | 660 functionsByElement = functionsByElement.insert(element, function); |
| 661 } | 661 } |
| 662 } | 662 } |
| 663 | 663 |
| 664 for (FletchFunction function in _removedFunctions) { | 664 for (DartinoFunction function in _removedFunctions) { |
| 665 functionsById = functionsById.delete(function.functionId); | 665 functionsById = functionsById.delete(function.functionId); |
| 666 Element element = function.element; | 666 Element element = function.element; |
| 667 if (element != null) { | 667 if (element != null) { |
| 668 functionsByElement = functionsByElement.delete(element); | 668 functionsByElement = functionsByElement.delete(element); |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 | 671 |
| 672 for (FletchFunction function in functions) { | 672 for (DartinoFunction function in functions) { |
| 673 functionsById = functionsById.insert(function.functionId, function); | 673 functionsById = functionsById.insert(function.functionId, function); |
| 674 } | 674 } |
| 675 | 675 |
| 676 _functionBuildersByElement.forEach((element, builder) { | 676 _functionBuildersByElement.forEach((element, builder) { |
| 677 functionsByElement = functionsByElement.insert( | 677 functionsByElement = functionsByElement.insert( |
| 678 element, | 678 element, |
| 679 functionsById[builder.functionId], | 679 functionsById[builder.functionId], |
| 680 (oldValue, newValue) { | 680 (oldValue, newValue) { |
| 681 throw "Unexpected element in predecessorSystem."; | 681 throw "Unexpected element in predecessorSystem."; |
| 682 }); | 682 }); |
| 683 }); | 683 }); |
| 684 | 684 |
| 685 PersistentMap<ConstructorElement, FletchFunction> | 685 PersistentMap<ConstructorElement, DartinoFunction> |
| 686 constructorInitializersByElement = | 686 constructorInitializersByElement = |
| 687 predecessorSystem.constructorInitializersByElement; | 687 predecessorSystem.constructorInitializersByElement; |
| 688 | 688 |
| 689 _newConstructorInitializers.forEach((element, builder) { | 689 _newConstructorInitializers.forEach((element, builder) { |
| 690 constructorInitializersByElement = | 690 constructorInitializersByElement = |
| 691 constructorInitializersByElement.insert( | 691 constructorInitializersByElement.insert( |
| 692 element, functionsById[builder.functionId]); | 692 element, functionsById[builder.functionId]); |
| 693 }); | 693 }); |
| 694 | 694 |
| 695 PersistentMap<int, int> tearoffsById = predecessorSystem.tearoffsById; | 695 PersistentMap<int, int> tearoffsById = predecessorSystem.tearoffsById; |
| 696 _newTearoffsById.forEach((int functionId, int stubId) { | 696 _newTearoffsById.forEach((int functionId, int stubId) { |
| 697 tearoffsById = tearoffsById.insert(functionId, stubId); | 697 tearoffsById = tearoffsById.insert(functionId, stubId); |
| 698 }); | 698 }); |
| 699 | 699 |
| 700 PersistentMap<int, String> symbolByFletchSelectorId = | 700 PersistentMap<int, String> symbolByDartinoSelectorId = |
| 701 predecessorSystem.symbolByFletchSelectorId; | 701 predecessorSystem.symbolByDartinoSelectorId; |
| 702 _symbolByFletchSelectorId.forEach((int id, String name) { | 702 _symbolByDartinoSelectorId.forEach((int id, String name) { |
| 703 symbolByFletchSelectorId = symbolByFletchSelectorId.insert(id, name); | 703 symbolByDartinoSelectorId = symbolByDartinoSelectorId.insert(id, name); |
| 704 }); | 704 }); |
| 705 | 705 |
| 706 PersistentMap<int, int> gettersByFieldIndex = | 706 PersistentMap<int, int> gettersByFieldIndex = |
| 707 predecessorSystem.gettersByFieldIndex; | 707 predecessorSystem.gettersByFieldIndex; |
| 708 _newGettersByFieldIndex.forEach((int fieldIndex, int functionId) { | 708 _newGettersByFieldIndex.forEach((int fieldIndex, int functionId) { |
| 709 gettersByFieldIndex = gettersByFieldIndex.insert(fieldIndex, functionId); | 709 gettersByFieldIndex = gettersByFieldIndex.insert(fieldIndex, functionId); |
| 710 }); | 710 }); |
| 711 | 711 |
| 712 PersistentMap<int, int> settersByFieldIndex = | 712 PersistentMap<int, int> settersByFieldIndex = |
| 713 predecessorSystem.settersByFieldIndex; | 713 predecessorSystem.settersByFieldIndex; |
| 714 _newSettersByFieldIndex.forEach((int fieldIndex, int functionId) { | 714 _newSettersByFieldIndex.forEach((int fieldIndex, int functionId) { |
| 715 settersByFieldIndex = settersByFieldIndex.insert(fieldIndex, functionId); | 715 settersByFieldIndex = settersByFieldIndex.insert(fieldIndex, functionId); |
| 716 }); | 716 }); |
| 717 | 717 |
| 718 PersistentMap<ParameterStubSignature, FletchFunction> parameterStubs = | 718 PersistentMap<ParameterStubSignature, DartinoFunction> parameterStubs = |
| 719 predecessorSystem.parameterStubs; | 719 predecessorSystem.parameterStubs; |
| 720 _newParameterStubs.forEach((signature, functionBuilder) { | 720 _newParameterStubs.forEach((signature, functionBuilder) { |
| 721 FletchFunction function = functionsById[functionBuilder.functionId]; | 721 DartinoFunction function = functionsById[functionBuilder.functionId]; |
| 722 parameterStubs = parameterStubs.insert(signature, function); | 722 parameterStubs = parameterStubs.insert(signature, function); |
| 723 }); | 723 }); |
| 724 | 724 |
| 725 return new FletchSystem( | 725 return new DartinoSystem( |
| 726 functionsById, | 726 functionsById, |
| 727 functionsByElement, | 727 functionsByElement, |
| 728 constructorInitializersByElement, | 728 constructorInitializersByElement, |
| 729 tearoffsById, | 729 tearoffsById, |
| 730 classesById, | 730 classesById, |
| 731 classesByElement, | 731 classesByElement, |
| 732 constantsById, | 732 constantsById, |
| 733 constantsByValue, | 733 constantsByValue, |
| 734 symbolByFletchSelectorId, | 734 symbolByDartinoSelectorId, |
| 735 gettersByFieldIndex, | 735 gettersByFieldIndex, |
| 736 settersByFieldIndex, | 736 settersByFieldIndex, |
| 737 parameterStubs); | 737 parameterStubs); |
| 738 } | 738 } |
| 739 } | 739 } |
| OLD | NEW |