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

Unified Diff: lib/compiler/implementation/constant_system.dart

Issue 10825386: Use JavaScript runtime semantics when constant folding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/constant_system_dart.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/constant_system.dart
diff --git a/lib/compiler/implementation/constant_system.dart b/lib/compiler/implementation/constant_system.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1f8862d55cd477b8f4cb8b56bb32ef6b9862d749
--- /dev/null
+++ b/lib/compiler/implementation/constant_system.dart
@@ -0,0 +1,64 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+interface Operation {
+ final SourceString name;
+ bool isUserDefinable();
+}
+
+interface UnaryOperation extends Operation {
+ /** Returns [:null:] if it was unable to fold the operation. */
+ Constant fold(Constant constant);
+}
+
+interface BinaryOperation extends Operation {
+ /** Returns [:null:] if it was unable to fold the operation. */
+ Constant fold(Constant left, Constant right);
+}
+
+/**
+ * A [ConstantSystem] is responsible for creating constants and folding them.
+ */
+interface ConstantSystem {
+ BinaryOperation get add();
+ BinaryOperation get bitAnd();
+ UnaryOperation get bitNot();
+ BinaryOperation get bitOr();
+ BinaryOperation get bitXor();
+ BinaryOperation get booleanAnd();
+ BinaryOperation get booleanOr();
+ BinaryOperation get divide();
+ BinaryOperation get equal();
+ BinaryOperation get greaterEqual();
+ BinaryOperation get greater();
+ BinaryOperation get identity();
+ BinaryOperation get lessEqual();
+ BinaryOperation get less();
+ BinaryOperation get modulo();
+ BinaryOperation get multiply();
+ UnaryOperation get negate();
+ UnaryOperation get not();
+ BinaryOperation get shiftLeft();
+ BinaryOperation get shiftRight();
+ BinaryOperation get subtract();
+ BinaryOperation get truncatingDivide();
+
+ Constant createInt(int i);
+ Constant createDouble(double d);
+ // We need a diagnostic node to report errors in case the string is malformed.
+ Constant createString(DartString string, Node diagnosticNode);
+ Constant createBool(bool value);
+ Constant createNull();
+
+ /** Returns true if the [constant] is an integer at runtime. */
+ bool isInt(Constant constant);
+ /** Returns true if the [constant] is a double at runtime. */
+ bool isDouble(Constant constant);
+ /** Returns true if the [constant] is a string at runtime. */
+ bool isString(Constant constant);
+ /** Returns true if the [constant] is a boolean at runtime. */
+ bool isBool(Constant constant);
+ /** Returns true if the [constant] is null at runtime. */
+ bool isNull(Constant constant);
+}
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/constant_system_dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698