experimental_continuation7.carbon 620 B

12345678910111213141516171819202122232425
  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 after the variable `x` is created.
  8. var y: i32 = 0;
  9. fn main() -> i32 {
  10. __continuation k1 {
  11. var x: i32 = 0;
  12. x = x + 1;
  13. __await;
  14. x = x + 2;
  15. y = x;
  16. }
  17. __run k1;
  18. var k2: __Continuation = k1;
  19. __run k2;
  20. return y;
  21. }