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

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

Issue 1184963006: dart2js cps: Better 'is int' checks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update comment Created 5 years, 6 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 '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; 10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator;
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) { 700 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) {
701 List<js.Expression> args = visitExpressionList(node.arguments); 701 List<js.Expression> args = visitExpressionList(node.arguments);
702 switch (node.operator) { 702 switch (node.operator) {
703 case BuiltinOperator.NumAdd: 703 case BuiltinOperator.NumAdd:
704 return new js.Binary('+', args[0], args[1]); 704 return new js.Binary('+', args[0], args[1]);
705 case BuiltinOperator.NumSubtract: 705 case BuiltinOperator.NumSubtract:
706 return new js.Binary('-', args[0], args[1]); 706 return new js.Binary('-', args[0], args[1]);
707 case BuiltinOperator.NumMultiply: 707 case BuiltinOperator.NumMultiply:
708 return new js.Binary('*', args[0], args[1]); 708 return new js.Binary('*', args[0], args[1]);
709 case BuiltinOperator.NumAnd: 709 case BuiltinOperator.NumAnd:
710 return js.js('(# & #) >>> 0', <js.Expression>[args[0], args[1]]); 710 return js.js('(# & #) >>> 0', args);
711 case BuiltinOperator.NumOr: 711 case BuiltinOperator.NumOr:
712 return js.js('(# | #) >>> 0', <js.Expression>[args[0], args[1]]); 712 return js.js('(# | #) >>> 0', args);
713 case BuiltinOperator.NumXor: 713 case BuiltinOperator.NumXor:
714 return js.js('(# ^ #) >>> 0', <js.Expression>[args[0], args[1]]); 714 return js.js('(# ^ #) >>> 0', args);
715 case BuiltinOperator.NumLt: 715 case BuiltinOperator.NumLt:
716 return new js.Binary('<', args[0], args[1]); 716 return new js.Binary('<', args[0], args[1]);
717 case BuiltinOperator.NumLe: 717 case BuiltinOperator.NumLe:
718 return new js.Binary('<=', args[0], args[1]); 718 return new js.Binary('<=', args[0], args[1]);
719 case BuiltinOperator.NumGt: 719 case BuiltinOperator.NumGt:
720 return new js.Binary('>', args[0], args[1]); 720 return new js.Binary('>', args[0], args[1]);
721 case BuiltinOperator.NumGe: 721 case BuiltinOperator.NumGe:
722 return new js.Binary('>=', args[0], args[1]); 722 return new js.Binary('>=', args[0], args[1]);
723 case BuiltinOperator.StrictEq: 723 case BuiltinOperator.StrictEq:
724 return new js.Binary('===', args[0], args[1]); 724 return new js.Binary('===', args[0], args[1]);
725 case BuiltinOperator.StrictNeq: 725 case BuiltinOperator.StrictNeq:
726 return new js.Binary('!==', args[0], args[1]); 726 return new js.Binary('!==', args[0], args[1]);
727 case BuiltinOperator.LooseEq: 727 case BuiltinOperator.LooseEq:
728 return new js.Binary('==', args[0], args[1]); 728 return new js.Binary('==', args[0], args[1]);
729 case BuiltinOperator.LooseNeq: 729 case BuiltinOperator.LooseNeq:
730 return new js.Binary('!=', args[0], args[1]); 730 return new js.Binary('!=', args[0], args[1]);
731 case BuiltinOperator.IsFalsy: 731 case BuiltinOperator.IsFalsy:
732 return new js.Prefix('!', args[0]); 732 return new js.Prefix('!', args[0]);
733 case BuiltinOperator.IsNumber:
734 return js.js("typeof # === 'number'", args);
735 case BuiltinOperator.IsNotNumber:
736 return js.js("typeof # !== 'number'", args);
737 case BuiltinOperator.IsFloor:
738 return js.js("Math.floor(#) === #", args);
739 case BuiltinOperator.IsNumberAndFloor:
740 return js.js("typeof # === 'number' && Math.floor(#) === #", args);
733 } 741 }
734 } 742 }
735 743
736 visitFunctionExpression(tree_ir.FunctionExpression node) { 744 visitFunctionExpression(tree_ir.FunctionExpression node) {
737 // FunctionExpressions are currently unused. 745 // FunctionExpressions are currently unused.
738 // We might need them if we want to emit raw JS nested functions. 746 // We might need them if we want to emit raw JS nested functions.
739 throw 'FunctionExpressions should not be used'; 747 throw 'FunctionExpressions should not be used';
740 } 748 }
741 } 749 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/tree_ir/optimization/logical_rewriter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698