OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "dart:math"; | 5 import "dart:math"; |
6 import "dart:typed_data"; | 6 import "dart:typed_data"; |
7 | 7 |
8 // We need to pass the exception and stack trace objects as second and third | 8 // We need to pass the exception and stack trace objects as second and third |
9 // parameter to the continuation. See vm/ast_transformer.cc for usage. | 9 // parameter to the continuation. See vm/ast_transformer.cc for usage. |
10 void _asyncCatchHelper(catchFunction, continuation) { | 10 void _asyncCatchHelper(catchFunction, continuation) { |
11 catchFunction((e, s) => continuation(null, e, s)); | 11 catchFunction((e, s) => continuation(null, e, s)); |
12 } | 12 } |
13 | 13 |
14 // The members of this class are cloned and added to each class that | 14 // The members of this class are cloned and added to each class that |
15 // represents an enum type. | 15 // represents an enum type. |
16 class _EnumHelper { | 16 class _EnumHelper { |
17 // Declare the list of enum value names private. When this field is | 17 // Declare the list of enum value names private. When this field is |
18 // cloned into a user-defined enum class, the field will be inaccessible | 18 // cloned into a user-defined enum class, the field will be inaccessible |
19 // because of the library-specific name suffix. The toString() function | 19 // because of the library-specific name suffix. The toString() function |
20 // below can access it because it uses the same name suffix. | 20 // below can access it because it uses the same name suffix. |
21 static const List<String> _enum_names = null; | 21 static const List<String> _enum_names = null; |
22 String toString() => _enum_names[index]; | 22 String toString() => _enum_names[index]; |
23 } | 23 } |
| 24 |
| 25 typedef bool SyncGeneratorCallback(Iterator iterator); |
| 26 |
| 27 // _SyncIterable and _syncIterator are used by the compiler to |
| 28 // implement sync* generator functions. A sync* generator allocates |
| 29 // and returns a new _SyncIterable object. |
| 30 class _SyncIterable extends IterableBase { |
| 31 // moveNextFn is the closurized body of the generator function. |
| 32 final SyncGeneratorCallback moveNextFn; |
| 33 |
| 34 const _SyncIterable(this.moveNextFn); |
| 35 |
| 36 get iterator { |
| 37 return new _SyncIterator(moveNextFn._clone()); |
| 38 } |
| 39 } |
| 40 |
| 41 class _SyncIterator implements Iterator { |
| 42 bool isYieldEach; // Set by generated code for the yield* statement. |
| 43 Iterator yieldEachIterator; |
| 44 var current; // Set by generated code for the yield and yield* statement. |
| 45 SyncGeneratorCallback moveNextFn; |
| 46 |
| 47 _SyncIterator(this.moveNextFn); |
| 48 |
| 49 bool moveNext() { |
| 50 if (moveNextFn == null) { |
| 51 return false; |
| 52 } |
| 53 while(true) { |
| 54 if (yieldEachIterator != null) { |
| 55 if (yieldEachIterator.moveNext()) { |
| 56 current = yieldEachIterator.current; |
| 57 return true; |
| 58 } |
| 59 yieldEachIterator = null; |
| 60 } |
| 61 isYieldEach = false; |
| 62 if (!moveNextFn(this)) { |
| 63 moveNextFn = null; |
| 64 current = null; |
| 65 return false; |
| 66 } |
| 67 if (isYieldEach && (current is Iterable)) { |
| 68 yieldEachIterator = current.iterator; |
| 69 continue; |
| 70 } |
| 71 return true; |
| 72 } |
| 73 } |
| 74 } |
OLD | NEW |