Chromium Code Reviews| Index: frog/leg/operations.dart |
| diff --git a/frog/leg/operations.dart b/frog/leg/operations.dart |
| index 0f5ea51f6da5595c823b0b0c52191e0a2d913875..8ad5427d01f1e2d320ded4f8f4d14d8bcd74c2a2 100644 |
| --- a/frog/leg/operations.dart |
| +++ b/frog/leg/operations.dart |
| @@ -105,6 +105,31 @@ class ShiftRightOperation extends BinaryIntOperation { |
| } |
| } |
| +class BinaryBoolOperation implements BinaryOperation { |
| + const BinaryBoolOperation(); |
| + Constant fold(Constant left, Constant right) { |
|
Lasse Reichstein Nielsen
2012/03/27 07:48:53
This seems like a pretty weak folding, if it requi
|
| + if (left.isBool() && right.isBool()) { |
| + BoolConstant leftBool = left; |
| + BoolConstant rightBool = right; |
| + bool resultValue = foldBools(leftBool.value, rightBool.value); |
| + return new BoolConstant(resultValue); |
| + } |
| + return null; |
|
Lasse Reichstein Nielsen
2012/03/27 07:48:53
If left or right are not boolean, you can still fo
|
| + } |
| + |
| + abstract bool foldBools(bool left, bool right); |
| +} |
| + |
| +class BooleanAnd extends BinaryBoolOperation { |
| + const BooleanAnd(); |
| + bool foldBools(bool left, bool right) => left && right; |
| +} |
| + |
| +class BooleanOr extends BinaryBoolOperation { |
| + const BooleanOr(); |
| + bool foldBools(bool left, bool right) => left || right; |
| +} |
| + |
| class ArithmeticNumOperation implements BinaryOperation { |
| const ArithmeticNumOperation(); |
| Constant fold(Constant left, Constant right) { |