experimental_continuation7.carbon 579 B

1234567891011121314151617181920212223
  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. // Test the way in which copying of continuations interacts with data
  5. // on the stack such as the variable `x`. In this example the copy
  6. // happens after the variable `x` is created.
  7. var Int y = 0;
  8. fn main() -> Int {
  9. __continuation k1 {
  10. var Int x = 0;
  11. x = x + 1;
  12. __await;
  13. x = x + 2;
  14. y = x;
  15. }
  16. __run k1;
  17. var __Continuation k2 = k1;
  18. __run k2;
  19. return y;
  20. }