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

Unified Diff: tool/input_sdk/private/ddc_runtime/types.dart

Issue 1926283002: implement generic method runtime behavior, fixes #301 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 8 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 | « tool/input_sdk/private/ddc_runtime/rtti.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/private/ddc_runtime/types.dart
diff --git a/tool/input_sdk/private/ddc_runtime/types.dart b/tool/input_sdk/private/ddc_runtime/types.dart
index 0246c6750e3decf45beb8f9fa4d30548d32e498e..c4045a4bff657f9cda99c7e85e72a2aa7aff36d2 100644
--- a/tool/input_sdk/private/ddc_runtime/types.dart
+++ b/tool/input_sdk/private/ddc_runtime/types.dart
@@ -241,7 +241,26 @@ final Typedef = JS('', '''
}
''');
+final _typeFormalCount = JS('', 'Symbol("_typeFormalCount")');
+
_functionType(definite, returnType, args, extra) => JS('', '''(() => {
+ // TODO(jmesserly): this is a bit of a retrofit, to easily fit
+ // generic functions into all of the existing ways we generate function
+ // signatures. Given `(T) => [T, [T]]` we'll return a function that does
+ // `(T) => _functionType(definite, T, [T])` ... we could do this in the
+ // compiler instead, at a slight cost to code size.
+ if ($args === void 0 && $extra === void 0) {
+ const fnTypeParts = $returnType;
+ // A closure that computes the remaining arguments.
+ // Return a function that makes the type.
+ function makeGenericFnType(...types) {
+ let parts = fnTypeParts(...types);
+ return $_functionType($definite, parts[0], parts[1], parts[2]);
+ }
+ makeGenericFnType[$_typeFormalCount] = fnTypeParts.length;
+ return makeGenericFnType;
+ }
+
// TODO(vsm): Cache / memomize?
let optionals;
let named;
@@ -274,9 +293,7 @@ definiteFunctionType(returnType, args, extra) =>
typedef(name, closure) => JS('', 'new #(#, #)', Typedef, name, closure);
-bool isDartType(type) {
- return JS('bool', '#(#) === #', read, type, Type);
-}
+bool isDartType(type) => JS('bool', '#(#) === #', read, type, Type);
typeName(type) => JS('', '''(() => {
// Non-instance types
« no previous file with comments | « tool/input_sdk/private/ddc_runtime/rtti.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698