OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library('native'); | 5 #library('native'); |
6 #import('../../lib/uri/uri.dart'); | 6 #import('../../lib/uri/uri.dart'); |
7 #import('leg.dart'); | 7 #import('leg.dart'); |
8 #import('elements/elements.dart'); | 8 #import('elements/elements.dart'); |
9 #import('scanner/scannerlib.dart'); | 9 #import('scanner/scannerlib.dart'); |
10 #import('ssa/ssa.dart'); | 10 #import('ssa/ssa.dart'); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 List<HInstruction> inputs = <HInstruction>[]; | 142 List<HInstruction> inputs = <HInstruction>[]; |
143 FunctionElement element = builder.work.element; | 143 FunctionElement element = builder.work.element; |
144 FunctionParameters parameters = element.computeParameters(builder.compiler); | 144 FunctionParameters parameters = element.computeParameters(builder.compiler); |
145 int i = 0; | 145 int i = 0; |
146 String receiver = ''; | 146 String receiver = ''; |
147 if (element.isInstanceMember()) { | 147 if (element.isInstanceMember()) { |
148 receiver = '\$$i.'; | 148 receiver = '\$$i.'; |
149 i++; | 149 i++; |
150 inputs.add(builder.localsHandler.readThis()); | 150 inputs.add(builder.localsHandler.readThis()); |
151 } | 151 } |
| 152 Compiler compiler = builder.compiler; |
152 parameters.forEachParameter((Element parameter) { | 153 parameters.forEachParameter((Element parameter) { |
| 154 Type type = parameter.computeType(compiler); |
| 155 HInstruction input = builder.localsHandler.readLocal(parameter); |
| 156 if (type is FunctionType) { |
| 157 // TODO(ngeoffray): by better analyzing the function type and |
| 158 // its formal parameters, we could just pass, eg closure.$call$0. |
| 159 builder.push(new HStatic(builder.interceptors.getClosureConverter())); |
| 160 List<HInstruction> callInputs = <HInstruction>[builder.pop(), input]; |
| 161 input = new HInvokeStatic(Selector.INVOCATION_1, callInputs); |
| 162 builder.add(input); |
| 163 } |
| 164 inputs.add(input); |
153 arguments.add('\$$i'); | 165 arguments.add('\$$i'); |
154 inputs.add(builder.localsHandler.readLocal(parameter)); | |
155 i++; | 166 i++; |
156 }); | 167 }); |
157 String foreignParameters = Strings.join(arguments, ','); | 168 String foreignParameters = Strings.join(arguments, ','); |
158 | 169 |
159 String dartMethodName; | 170 String dartMethodName; |
160 String nativeMethodName = element.name.slowToString(); | 171 String nativeMethodName = element.name.slowToString(); |
161 String nativeMethodCall; | 172 String nativeMethodCall; |
162 | 173 |
163 if (element.kind == ElementKind.FUNCTION) { | 174 if (element.kind == ElementKind.FUNCTION) { |
164 dartMethodName = builder.compiler.namer.instanceMethodName( | 175 dartMethodName = builder.compiler.namer.instanceMethodName( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } else if (!node.arguments.tail.isEmpty()) { | 256 } else if (!node.arguments.tail.isEmpty()) { |
246 builder.compiler.cancel('More than one argument to native'); | 257 builder.compiler.cancel('More than one argument to native'); |
247 } else { | 258 } else { |
248 LiteralString jsCode = node.arguments.head; | 259 LiteralString jsCode = node.arguments.head; |
249 int start = jsCode.value.slowToString()[0] === '@' ? 1 : 0; | 260 int start = jsCode.value.slowToString()[0] === '@' ? 1 : 0; |
250 builder.push(new HForeign(builder.unquote(jsCode, start), | 261 builder.push(new HForeign(builder.unquote(jsCode, start), |
251 const SourceString('Object'), | 262 const SourceString('Object'), |
252 <HInstruction>[])); | 263 <HInstruction>[])); |
253 } | 264 } |
254 } | 265 } |
OLD | NEW |