experimental_continuation4.carbon 503 B

123456789101112131415161718192021
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. package ExecutableSemanticsTest api;
  5. // Assignment for continuations is shallow, so `k2` refers to the same
  6. // continuation as `k1`.
  7. fn main() -> i32 {
  8. var x: i32 = 0;
  9. __continuation k1 {
  10. x = x + 1;
  11. __await;
  12. x = x + 2;
  13. }
  14. var k2: __Continuation = k1;
  15. __run k1;
  16. __run k2;
  17. return x;
  18. }