3abf78212c
Add dart2bytecode tool which takes Dart sources and produces Dart bytecode. The tool uses common front-end (CFE) to parse Dart source code and contains bytecode generator which translates kernel AST to bytecode. Change-Id: I90bd6e72c619cf0edc556da0640760b30e81091d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378560 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Slava Egorov <vegorov@google.com>
69 lines
1.2 KiB
Dart
69 lines
1.2 KiB
Dart
// Copyright (c) 2024, 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.
|
|
|
|
import 'dart:async';
|
|
|
|
Future<int> foo() async => 42;
|
|
|
|
Future<int> simpleAsyncAwait(Future<int> a, Future<int> b) async {
|
|
return (await a) + (await b);
|
|
}
|
|
|
|
Future<int> loops(List<int> list) async {
|
|
int sum = 0;
|
|
for (int i = 0; i < 10; ++i) {
|
|
for (var j in list) {
|
|
sum += i + j + await foo();
|
|
}
|
|
}
|
|
for (int k = 0; k < 10; ++k) {
|
|
sum += k;
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
Future<int> tryCatchRethrow(Future<int> a, Future<int> b, Future<int> c) async {
|
|
int x = 1;
|
|
try {
|
|
x = x + await a;
|
|
} catch (e) {
|
|
if (e is Error) {
|
|
return 42;
|
|
}
|
|
x = x + await b;
|
|
rethrow;
|
|
} finally {
|
|
print('fin');
|
|
x = x + await c;
|
|
return x;
|
|
}
|
|
}
|
|
|
|
closure(Future<int> a) {
|
|
int x = 3;
|
|
Future<int> nested() async {
|
|
int y = 4;
|
|
try {
|
|
x = 5;
|
|
y = await a;
|
|
return x + y;
|
|
} finally {
|
|
print('fin');
|
|
}
|
|
}
|
|
|
|
return nested;
|
|
}
|
|
|
|
Future<int> testAssert(Future<int> a) async {
|
|
assert((await a) == 42);
|
|
return 7;
|
|
}
|
|
|
|
var asyncInFieldInitializer = (Future<int> x) async {
|
|
await x;
|
|
};
|
|
|
|
main() {}
|