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

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: Remove unused code and fix long line 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 /// The JS name of a built-in method.
27 final Map<BuiltinMethod, String> BuiltinMethodName = <BuiltinMethod, String>{
karlklose 2015/08/12 13:00:46 Identifiers for globals should start with a lower
asgerf 2015/08/12 13:29:39 Done. I also decided to make it static to put it c
28 BuiltinMethod.Push: 'push',
29 BuiltinMethod.Pop: 'pop',
30 };
31
26 class CodegenBailout { 32 class CodegenBailout {
27 final tree_ir.Node node; 33 final tree_ir.Node node;
28 final String reason; 34 final String reason;
29 CodegenBailout(this.node, this.reason); 35 CodegenBailout(this.node, this.reason);
30 String get message { 36 String get message {
31 return 'bailout${node != null ? " on $node" : ""}: $reason'; 37 return 'bailout${node != null ? " on $node" : ""}: $reason';
32 } 38 }
33 } 39 }
34 40
35 class CodeGenerator extends tree_ir.StatementVisitor 41 class CodeGenerator extends tree_ir.StatementVisitor
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 case BuiltinOperator.IsNotNumber: 833 case BuiltinOperator.IsNotNumber:
828 return js.js("typeof # !== 'number'", args); 834 return js.js("typeof # !== 'number'", args);
829 case BuiltinOperator.IsFloor: 835 case BuiltinOperator.IsFloor:
830 return js.js("Math.floor(#) === #", args); 836 return js.js("Math.floor(#) === #", args);
831 case BuiltinOperator.IsNumberAndFloor: 837 case BuiltinOperator.IsNumberAndFloor:
832 return js.js("typeof # === 'number' && Math.floor(#) === #", args); 838 return js.js("typeof # === 'number' && Math.floor(#) === #", args);
833 } 839 }
834 } 840 }
835 841
836 @override 842 @override
843 js.Expression visitApplyBuiltinMethod(tree_ir.ApplyBuiltinMethod node) {
844 String name = BuiltinMethodName[node.method];
845 js.Expression receiver = visitExpression(node.receiver);
846 List<js.Expression> args = visitExpressionList(node.arguments);
847 return js.js('#.#(#)', [receiver, name, args]);
848 }
849
850 @override
837 js.Expression visitAwait(tree_ir.Await node) { 851 js.Expression visitAwait(tree_ir.Await node) {
838 return new js.Await(visitExpression(node.input)); 852 return new js.Await(visitExpression(node.input));
839 } 853 }
840 854
841 visitFunctionExpression(tree_ir.FunctionExpression node) { 855 visitFunctionExpression(tree_ir.FunctionExpression node) {
842 // FunctionExpressions are currently unused. 856 // FunctionExpressions are currently unused.
843 // We might need them if we want to emit raw JS nested functions. 857 // We might need them if we want to emit raw JS nested functions.
844 throw 'FunctionExpressions should not be used'; 858 throw 'FunctionExpressions should not be used';
845 } 859 }
846 } 860 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698