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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1713983002: dart2js cps: Add SetLength instruction. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Use trust-primitives and refine type of length to uint32' Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../closure.dart' show 9 import '../../closure.dart' show
10 ClosureClassElement; 10 ClosureClassElement;
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 } 1204 }
1205 } 1205 }
1206 return null; 1206 return null;
1207 } 1207 }
1208 1208
1209 int maxBit = maxBitOf(node); 1209 int maxBit = maxBitOf(node);
1210 if (maxBit != null && maxBit <= MAX_UINT31) return op; 1210 if (maxBit != null && maxBit <= MAX_UINT31) return op;
1211 return js.js('# >>> 0', [op]); 1211 return js.js('# >>> 0', [op]);
1212 } 1212 }
1213 1213
1214
1215 /// The JS name of a built-in method.
1216 static final Map<BuiltinMethod, String> builtinMethodName =
1217 const <BuiltinMethod, String>{
1218 BuiltinMethod.Push: 'push',
1219 BuiltinMethod.Pop: 'pop',
1220 };
1221
1222 @override 1214 @override
1223 js.Expression visitApplyBuiltinMethod(tree_ir.ApplyBuiltinMethod node) { 1215 js.Expression visitApplyBuiltinMethod(tree_ir.ApplyBuiltinMethod node) {
1224 String name = builtinMethodName[node.method];
1225 js.Expression receiver = visitExpression(node.receiver); 1216 js.Expression receiver = visitExpression(node.receiver);
1226 List<js.Expression> args = visitExpressionList(node.arguments); 1217 List<js.Expression> args = visitExpressionList(node.arguments);
1227 return js.js('#.#(#)', [receiver, name, args]); 1218 switch (node.method) {
1219 case BuiltinMethod.Push:
1220 return js.js('#.push(#)', [receiver, args]);
1221
1222 case BuiltinMethod.Pop:
1223 return js.js('#.pop()', [receiver]);
1224
1225 case BuiltinMethod.SetLength:
1226 return js.js('#.length = #', [receiver, args[0]]);
1227 }
1228 } 1228 }
1229 1229
1230 @override 1230 @override
1231 js.Expression visitAwait(tree_ir.Await node) { 1231 js.Expression visitAwait(tree_ir.Await node) {
1232 return new js.Await(visitExpression(node.input)); 1232 return new js.Await(visitExpression(node.input));
1233 } 1233 }
1234 1234
1235 /// Ensures that parameter defaults will be emitted. 1235 /// Ensures that parameter defaults will be emitted.
1236 /// 1236 ///
1237 /// Ideally, this should be done when generating the relevant stub methods, 1237 /// Ideally, this should be done when generating the relevant stub methods,
1238 /// since those are the ones that actually reference the constants, but those 1238 /// since those are the ones that actually reference the constants, but those
1239 /// are created by the emitter when it is too late to register new constants. 1239 /// are created by the emitter when it is too late to register new constants.
1240 /// 1240 ///
1241 /// For non-static methods, we have no way of knowing if the defaults are 1241 /// For non-static methods, we have no way of knowing if the defaults are
1242 /// actually used, so we conservatively register them all. 1242 /// actually used, so we conservatively register them all.
1243 void registerDefaultParameterValues(ExecutableElement element) { 1243 void registerDefaultParameterValues(ExecutableElement element) {
1244 if (element is! FunctionElement) return; 1244 if (element is! FunctionElement) return;
1245 FunctionElement function = element; 1245 FunctionElement function = element;
1246 if (function.isStatic) return; // Defaults are inlined at call sites. 1246 if (function.isStatic) return; // Defaults are inlined at call sites.
1247 function.functionSignature.forEachOptionalParameter((param) { 1247 function.functionSignature.forEachOptionalParameter((param) {
1248 ConstantValue constant = glue.getDefaultParameterValue(param); 1248 ConstantValue constant = glue.getDefaultParameterValue(param);
1249 registry.registerCompileTimeConstant(constant); 1249 registry.registerCompileTimeConstant(constant);
1250 }); 1250 });
1251 } 1251 }
1252 } 1252 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698