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

Unified Diff: frog/type.dart

Issue 8457007: Better runtime type checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleaner output Created 9 years, 1 month 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
Index: frog/type.dart
diff --git a/frog/type.dart b/frog/type.dart
index 259e3669d5c34601030bdadcbed3a99f0a5d0d1f..ad059ae3e655ff91b53cdc710a404c06e0af602f 100644
--- a/frog/type.dart
+++ b/frog/type.dart
@@ -6,6 +6,13 @@ class Type implements Named, Hashable {
final String name;
bool isTested;
+ /**
+ * For core types (int, String, etc) this is the generated type assertion
+ * type check function. It uses JS typeof, and does extra work for "int".
+ * This field is null for all other types.
+ */
+ String typeCheckCode;
+
String _jsname;
Member _typeMember;
@@ -49,6 +56,8 @@ class Type implements Named, Hashable {
bool get isFunction() => false;
bool get isList() => false;
bool get isNum() => false;
+ bool get isInt() => false;
+ bool get isIsDouble() => false;
bool get isVoid() => false;
// Strangely Dart treats calls on Function much like calls on var.
@@ -177,7 +186,7 @@ class Type implements Named, Hashable {
* and: Ti << Si, 1 <= i <= n
* - T << U and U << S.
*
- * << is a partial order on types. T is a subtype of S, written T <: S, i
+ * << is a partial order on types. T is a subtype of S, written T <: S, iff
* [Bottom/Dynamic]T << S.
*/
// TODO(jmesserly): this function could be expensive. Memoize results?
@@ -223,7 +232,7 @@ class Type implements Named, Hashable {
return true;
}
- // And now for some fun: T << U and U << S => T << S
+ // And now for some fun: T << U and U << S -> T << S
// To implement this, we need to enumerate a set of types C such that
// U will be an element of C. We can do this by either enumerating less
// specific types of T, or more specific types of S.
@@ -595,6 +604,9 @@ class DefinedType extends Type {
(name == 'num' || name == 'int' || name == 'double');
}
+ bool get isInt() => this == world.intType;
+ bool get isDouble() => this == world.doubleType;
+
MethodMember getCallMethod() => members['\$call'];
Map<String, Member> getAllMembers() => new Map.from(members);
@@ -772,7 +784,7 @@ class DefinedType extends Type {
}
}
} else if (definition is FunctionTypeDefinition) {
- // Functions should implement Function. See "Function Types" in the spec.
+ // Function types implement the Function interface.
this.interfaces = [world.functionType];
}
« frog/presubmit.py ('K') | « frog/tokenizer.g.dart ('k') | frog/value.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698