experimental_continuation8.carbon 679 B

123456789101112131415161718192021222324252627
  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. // Test the way in which copying of continuations interacts with data
  6. // on the stack such as the variable `x`. In this example the copy
  7. // happens before the variable `x` is created, so each continuation
  8. // creates a different `x`.
  9. var y: i32 = 0;
  10. fn main() -> i32 {
  11. __continuation k1 {
  12. var x: i32 = 0;
  13. x = x + 1;
  14. __await;
  15. y = x;
  16. }
  17. var k2: __Continuation = k1;
  18. __run k1;
  19. __run k2;
  20. __run k1;
  21. __run k2;
  22. return y;
  23. }