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_context; | 5 library dartino_compiler.dartino_context; |
6 | 6 |
7 import 'package:compiler/src/tree/tree.dart' show | 7 import 'package:compiler/src/tree/tree.dart' show |
8 Node; | 8 Node; |
9 | 9 |
10 import 'package:compiler/src/elements/elements.dart' show | 10 import 'package:compiler/src/elements/elements.dart' show |
11 ClassElement, | 11 ClassElement, |
12 Element, | 12 Element, |
13 FieldElement, | 13 FieldElement, |
14 FunctionElement, | 14 FunctionElement, |
15 FunctionSignature, | 15 FunctionSignature, |
16 LibraryElement, | 16 LibraryElement, |
17 ParameterElement, | 17 ParameterElement, |
18 Name; | 18 Name; |
19 | 19 |
20 import 'package:compiler/src/resolution/tree_elements.dart' show | 20 import 'package:compiler/src/resolution/tree_elements.dart' show |
21 TreeElements; | 21 TreeElements; |
22 | 22 |
23 import 'package:compiler/src/universe/selector.dart' show | 23 import 'package:compiler/src/universe/selector.dart' show |
24 Selector; | 24 Selector; |
25 | 25 |
26 import 'package:compiler/src/constants/expressions.dart' show | 26 import 'package:compiler/src/constants/expressions.dart' show |
27 ConstantExpression; | 27 ConstantExpression; |
28 | 28 |
29 import 'package:compiler/src/constants/values.dart' show | 29 import 'package:compiler/src/constants/values.dart' show |
30 ConstantValue, | 30 ConstantValue, |
31 ConstructedConstantValue, | 31 ConstructedConstantValue, |
32 FunctionConstantValue; | 32 FunctionConstantValue; |
33 | 33 |
34 import 'fletch_compiler_implementation.dart' show | 34 import 'dartino_compiler_implementation.dart' show |
35 FletchCompilerImplementation; | 35 DartinoCompilerImplementation; |
36 | 36 |
37 export 'fletch_compiler_implementation.dart' show | 37 export 'dartino_compiler_implementation.dart' show |
38 FletchCompilerImplementation; | 38 DartinoCompilerImplementation; |
39 | 39 |
40 import 'fletch_backend.dart' show | 40 import 'dartino_backend.dart' show |
41 FletchBackend; | 41 DartinoBackend; |
42 | 42 |
43 export 'fletch_backend.dart' show | 43 export 'dartino_backend.dart' show |
44 FletchBackend; | 44 DartinoBackend; |
45 | 45 |
46 export 'bytecode_assembler.dart' show | 46 export 'bytecode_assembler.dart' show |
47 BytecodeAssembler, | 47 BytecodeAssembler, |
48 BytecodeLabel; | 48 BytecodeLabel; |
49 | 49 |
50 import 'fletch_native_descriptor.dart' show | 50 import 'dartino_native_descriptor.dart' show |
51 FletchNativeDescriptor; | 51 DartinoNativeDescriptor; |
52 | 52 |
53 import 'fletch_selector.dart' show | 53 import 'dartino_selector.dart' show |
54 FletchSelector, | 54 DartinoSelector, |
55 SelectorKind; | 55 SelectorKind; |
56 | 56 |
57 export 'fletch_native_descriptor.dart' show | 57 export 'dartino_native_descriptor.dart' show |
58 FletchNativeDescriptor; | 58 DartinoNativeDescriptor; |
59 | 59 |
60 import 'fletch_registry.dart' show | 60 import 'dartino_registry.dart' show |
61 FletchRegistry; | 61 DartinoRegistry; |
62 | 62 |
63 class FletchContext { | 63 class DartinoContext { |
64 final FletchCompilerImplementation compiler; | 64 final DartinoCompilerImplementation compiler; |
65 | 65 |
66 Map<String, FletchNativeDescriptor> nativeDescriptors; | 66 Map<String, DartinoNativeDescriptor> nativeDescriptors; |
67 | 67 |
68 Set<String> names = new Set<String>(); | 68 Set<String> names = new Set<String>(); |
69 | 69 |
70 Map<FieldElement, int> staticIndices = <FieldElement, int>{}; | 70 Map<FieldElement, int> staticIndices = <FieldElement, int>{}; |
71 | 71 |
72 Map<LibraryElement, String> libraryTag = <LibraryElement, String>{}; | 72 Map<LibraryElement, String> libraryTag = <LibraryElement, String>{}; |
73 List<String> symbols = <String>[]; | 73 List<String> symbols = <String>[]; |
74 Map<String, int> symbolIds = <String, int>{}; | 74 Map<String, int> symbolIds = <String, int>{}; |
75 Map<Name, String> nameToSymbol = <Name, String>{}; | 75 Map<Name, String> nameToSymbol = <Name, String>{}; |
76 Map<Selector, String> selectorToSymbol = <Selector, String>{}; | 76 Map<Selector, String> selectorToSymbol = <Selector, String>{}; |
77 | 77 |
78 FletchContext(this.compiler); | 78 DartinoContext(this.compiler); |
79 | 79 |
80 FletchBackend get backend => compiler.backend; | 80 DartinoBackend get backend => compiler.backend; |
81 | 81 |
82 bool get enableBigint { | 82 bool get enableBigint { |
83 String enableBigintConstant = compiler.environment['fletch.enable-bigint']; | 83 String enableBigintConstant = compiler.environment['dartino.enable-bigint']; |
84 return enableBigintConstant != "false"; | 84 return enableBigintConstant != "false"; |
85 } | 85 } |
86 | 86 |
87 void setNames(Map<String, String> names) { | 87 void setNames(Map<String, String> names) { |
88 // Generate symbols of the values. | 88 // Generate symbols of the values. |
89 for (String name in names.values) { | 89 for (String name in names.values) { |
90 this.names.add(name); | 90 this.names.add(name); |
91 getSymbolId(name); | 91 getSymbolId(name); |
92 } | 92 } |
93 } | 93 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 symbols.add(symbol); | 156 symbols.add(symbol); |
157 backend.systemBuilder.registerSymbol(symbol, id); | 157 backend.systemBuilder.registerSymbol(symbol, id); |
158 return id; | 158 return id; |
159 }); | 159 }); |
160 } | 160 } |
161 | 161 |
162 void forEachStatic(f(FieldElement element, int index)) { | 162 void forEachStatic(f(FieldElement element, int index)) { |
163 staticIndices.forEach(f); | 163 staticIndices.forEach(f); |
164 } | 164 } |
165 | 165 |
166 int toFletchSelector(Selector selector) { | 166 int toDartinoSelector(Selector selector) { |
167 String symbol = getSymbolFromSelector(selector); | 167 String symbol = getSymbolFromSelector(selector); |
168 int id = getSymbolId(symbol); | 168 int id = getSymbolId(symbol); |
169 SelectorKind kind = getFletchSelectorKind(selector); | 169 SelectorKind kind = getDartinoSelectorKind(selector); |
170 return FletchSelector.encode(id, kind, selector.argumentCount); | 170 return DartinoSelector.encode(id, kind, selector.argumentCount); |
171 } | 171 } |
172 | 172 |
173 int toFletchIsSelector(ClassElement classElement, [int arity]) { | 173 int toDartinoIsSelector(ClassElement classElement, [int arity]) { |
174 LibraryElement library = classElement.library; | 174 LibraryElement library = classElement.library; |
175 StringBuffer buffer = new StringBuffer(); | 175 StringBuffer buffer = new StringBuffer(); |
176 buffer.write("?is?"); | 176 buffer.write("?is?"); |
177 buffer.write(classElement.name); | 177 buffer.write(classElement.name); |
178 buffer.write("?"); | 178 buffer.write("?"); |
179 buffer.write(getLibraryTag(library)); | 179 buffer.write(getLibraryTag(library)); |
180 int id = getSymbolId(buffer.toString()); | 180 int id = getSymbolId(buffer.toString()); |
181 if (arity == null) return FletchSelector.encodeGetter(id); | 181 if (arity == null) return DartinoSelector.encodeGetter(id); |
182 return FletchSelector.encodeMethod(id, arity); | 182 return DartinoSelector.encodeMethod(id, arity); |
183 } | 183 } |
184 | 184 |
185 int toFletchTearoffIsSelector( | 185 int toDartinoTearoffIsSelector( |
186 String functionName, | 186 String functionName, |
187 ClassElement classElement) { | 187 ClassElement classElement) { |
188 LibraryElement library = classElement.library; | 188 LibraryElement library = classElement.library; |
189 StringBuffer buffer = new StringBuffer(); | 189 StringBuffer buffer = new StringBuffer(); |
190 buffer.write("?is?"); | 190 buffer.write("?is?"); |
191 buffer.write(functionName); | 191 buffer.write(functionName); |
192 buffer.write("?"); | 192 buffer.write("?"); |
193 buffer.write(classElement.name); | 193 buffer.write(classElement.name); |
194 buffer.write("?"); | 194 buffer.write("?"); |
195 buffer.write(getLibraryTag(library)); | 195 buffer.write(getLibraryTag(library)); |
196 int id = getSymbolId(buffer.toString()); | 196 int id = getSymbolId(buffer.toString()); |
197 return FletchSelector.encodeMethod(id, 0); | 197 return DartinoSelector.encodeMethod(id, 0); |
198 } | 198 } |
199 | 199 |
200 SelectorKind getFletchSelectorKind(Selector selector) { | 200 SelectorKind getDartinoSelectorKind(Selector selector) { |
201 if (selector.isGetter) return SelectorKind.Getter; | 201 if (selector.isGetter) return SelectorKind.Getter; |
202 if (selector.isSetter) return SelectorKind.Setter; | 202 if (selector.isSetter) return SelectorKind.Setter; |
203 return SelectorKind.Method; | 203 return SelectorKind.Method; |
204 } | 204 } |
205 | 205 |
206 void registerConstructedConstantValue(ConstructedConstantValue value) { | 206 void registerConstructedConstantValue(ConstructedConstantValue value) { |
207 ClassElement classElement = value.type.element; | 207 ClassElement classElement = value.type.element; |
208 backend.registerClassElement(classElement); | 208 backend.registerClassElement(classElement); |
209 // TODO(ahe): This should not be required. Also, instantiate type, | 209 // TODO(ahe): This should not be required. Also, instantiate type, |
210 // not class. | 210 // not class. |
211 FletchRegistry registry = new FletchRegistry(compiler); | 211 DartinoRegistry registry = new DartinoRegistry(compiler); |
212 registry.registerInstantiatedClass(classElement); | 212 registry.registerInstantiatedClass(classElement); |
213 } | 213 } |
214 | 214 |
215 void registerFunctionConstantValue(FunctionConstantValue value) { | 215 void registerFunctionConstantValue(FunctionConstantValue value) { |
216 backend.markFunctionConstantAsUsed(value); | 216 backend.markFunctionConstantAsUsed(value); |
217 } | 217 } |
218 | 218 |
219 // TODO(zarah): Remove this and use the FletchSystemBuilder | 219 // TODO(zarah): Remove this and use the DartinoSystemBuilder |
220 void markConstantUsed(ConstantValue constant) { | 220 void markConstantUsed(ConstantValue constant) { |
221 backend.systemBuilder.registerConstant(constant, this); | 221 backend.systemBuilder.registerConstant(constant, this); |
222 } | 222 } |
223 | 223 |
224 // TODO(zarah): Remove this and use the FletchSystemBuilder | 224 // TODO(zarah): Remove this and use the DartinoSystemBuilder |
225 int lookupConstantIdByValue(ConstantValue value) => | 225 int lookupConstantIdByValue(ConstantValue value) => |
226 backend.systemBuilder.lookupConstantIdByValue(value); | 226 backend.systemBuilder.lookupConstantIdByValue(value); |
227 | 227 |
228 /// If [isConst] is true, a compile-time error is reported. | 228 /// If [isConst] is true, a compile-time error is reported. |
229 ConstantExpression compileConstant( | 229 ConstantExpression compileConstant( |
230 Node node, | 230 Node node, |
231 TreeElements elements, | 231 TreeElements elements, |
232 {bool isConst}) { | 232 {bool isConst}) { |
233 ConstantExpression expression = | 233 ConstantExpression expression = |
234 inspectConstant(node, elements, isConst: isConst); | 234 inspectConstant(node, elements, isConst: isConst); |
(...skipping 12 matching lines...) Expand all Loading... |
247 ConstantExpression expression = | 247 ConstantExpression expression = |
248 compiler.resolver.constantCompiler.compileNode( | 248 compiler.resolver.constantCompiler.compileNode( |
249 node, elements, enforceConst: isConst); | 249 node, elements, enforceConst: isConst); |
250 return expression; | 250 return expression; |
251 } | 251 } |
252 | 252 |
253 ConstantValue getConstantValue(ConstantExpression expression) { | 253 ConstantValue getConstantValue(ConstantExpression expression) { |
254 return compiler.constants.getConstantValue(expression); | 254 return compiler.constants.getConstantValue(expression); |
255 } | 255 } |
256 } | 256 } |
OLD | NEW |