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

Unified Diff: runtime/lib/core_patch.dart

Issue 888463004: Add support for sync* and yield (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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 | « no previous file | runtime/lib/function.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/core_patch.dart
===================================================================
--- runtime/lib/core_patch.dart (revision 43515)
+++ runtime/lib/core_patch.dart (working copy)
@@ -21,3 +21,54 @@
static const List<String> _enum_names = null;
String toString() => _enum_names[index];
}
+
+typedef bool SyncGeneratorCallback(Iterator iterator);
+
+// _SyncIterable and _syncIterator are used by the compiler to
+// implement sync* generator functions. A sync* generator allocates
+// and returns a new _SyncIterable object.
+class _SyncIterable extends IterableBase {
+ // moveNextFn is the closurized body of the generator function.
+ final SyncGeneratorCallback moveNextFn;
+
+ const _SyncIterable(this.moveNextFn);
+
+ get iterator {
+ return new _SyncIterator(moveNextFn._clone());
+ }
+}
+
+class _SyncIterator implements Iterator {
+ bool isYieldEach; // Set by generated code for the yield* statement.
+ Iterator yieldEachIterator;
+ var current; // Set by generated code for the yield and yield* statement.
+ SyncGeneratorCallback moveNextFn;
+
+ _SyncIterator(this.moveNextFn);
+
+ bool moveNext() {
+ if (moveNextFn == null) {
+ return false;
+ }
+ while(true) {
+ if (yieldEachIterator != null) {
+ if (yieldEachIterator.moveNext()) {
+ current = yieldEachIterator.current;
+ return true;
+ }
+ yieldEachIterator = null;
+ }
+ isYieldEach = false;
+ if (!moveNextFn(this)) {
+ moveNextFn = null;
+ current = null;
+ return false;
+ }
+ if (isYieldEach && (current is Iterable)) {
+ yieldEachIterator = current.iterator;
+ continue;
+ }
+ return true;
+ }
+ }
+}
« no previous file with comments | « no previous file | runtime/lib/function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698