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

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

Issue 1285173002: dart2js cps: Rewrite more List operations into JS array operations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: receiverIsNotNull -> optional param Created 5 years, 4 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
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 ClosureClassElement; 9 import '../../closure.dart' show ClosureClassElement;
10 import '../../common/codegen.dart' show CodegenRegistry; 10 import '../../common/codegen.dart' show CodegenRegistry;
11 import '../../constants/values.dart'; 11 import '../../constants/values.dart';
12 import '../../dart_types.dart'; 12 import '../../dart_types.dart';
13 import '../../diagnostics/invariant.dart' show invariant; 13 import '../../diagnostics/invariant.dart' show invariant;
14 import '../../diagnostics/spannable.dart' show CURRENT_ELEMENT_SPANNABLE; 14 import '../../diagnostics/spannable.dart' show CURRENT_ELEMENT_SPANNABLE;
15 import '../../elements/elements.dart'; 15 import '../../elements/elements.dart';
16 import '../../io/source_information.dart' show SourceInformation; 16 import '../../io/source_information.dart' show SourceInformation;
17 import '../../js/js.dart' as js; 17 import '../../js/js.dart' as js;
18 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 18 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
19 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; 19 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator, BuiltinMethod;
20 import '../../types/types.dart' show TypeMask; 20 import '../../types/types.dart' show TypeMask;
21 import '../../universe/universe.dart' show 21 import '../../universe/universe.dart' show
22 Selector, 22 Selector,
23 UniverseSelector; 23 UniverseSelector;
24 import '../../util/maplet.dart'; 24 import '../../util/maplet.dart';
25 25
26 class CodegenBailout { 26 class CodegenBailout {
27 final tree_ir.Node node; 27 final tree_ir.Node node;
28 final String reason; 28 final String reason;
29 CodegenBailout(this.node, this.reason); 29 CodegenBailout(this.node, this.reason);
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 return js.js("typeof # === 'number'", args); 826 return js.js("typeof # === 'number'", args);
827 case BuiltinOperator.IsNotNumber: 827 case BuiltinOperator.IsNotNumber:
828 return js.js("typeof # !== 'number'", args); 828 return js.js("typeof # !== 'number'", args);
829 case BuiltinOperator.IsFloor: 829 case BuiltinOperator.IsFloor:
830 return js.js("Math.floor(#) === #", args); 830 return js.js("Math.floor(#) === #", args);
831 case BuiltinOperator.IsNumberAndFloor: 831 case BuiltinOperator.IsNumberAndFloor:
832 return js.js("typeof # === 'number' && Math.floor(#) === #", args); 832 return js.js("typeof # === 'number' && Math.floor(#) === #", args);
833 } 833 }
834 } 834 }
835 835
836 /// The JS name of a built-in method.
837 static final Map<BuiltinMethod, String> builtinMethodName =
838 const <BuiltinMethod, String>{
839 BuiltinMethod.Push: 'push',
840 BuiltinMethod.Pop: 'pop',
841 };
842
843 @override
844 js.Expression visitApplyBuiltinMethod(tree_ir.ApplyBuiltinMethod node) {
845 String name = builtinMethodName[node.method];
846 js.Expression receiver = visitExpression(node.receiver);
847 List<js.Expression> args = visitExpressionList(node.arguments);
848 return js.js('#.#(#)', [receiver, name, args]);
849 }
850
836 @override 851 @override
837 js.Expression visitAwait(tree_ir.Await node) { 852 js.Expression visitAwait(tree_ir.Await node) {
838 return new js.Await(visitExpression(node.input)); 853 return new js.Await(visitExpression(node.input));
839 } 854 }
840 855
841 visitFunctionExpression(tree_ir.FunctionExpression node) { 856 visitFunctionExpression(tree_ir.FunctionExpression node) {
842 // FunctionExpressions are currently unused. 857 // FunctionExpressions are currently unused.
843 // We might need them if we want to emit raw JS nested functions. 858 // We might need them if we want to emit raw JS nested functions.
844 throw 'FunctionExpressions should not be used'; 859 throw 'FunctionExpressions should not be used';
845 } 860 }
846 } 861 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698