tcomputedgoto.nim 637 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. cmd: '''nim c --gc:arc $file'''
  3. output: '''2
  4. 2'''
  5. """
  6. type
  7. ObjWithDestructor = object
  8. a: int
  9. proc `=destroy`(self: var ObjWithDestructor) =
  10. echo "destroyed"
  11. proc `=`(self: var ObjWithDestructor, other: ObjWithDestructor) =
  12. echo "copied"
  13. proc test(a: range[0..1], arg: ObjWithDestructor) =
  14. var iteration = 0
  15. while true:
  16. {.computedGoto.}
  17. let
  18. b = int(a) * 2
  19. c = a
  20. d = arg
  21. e = arg
  22. discard c
  23. discard d
  24. discard e
  25. inc iteration
  26. case a
  27. of 0:
  28. assert false
  29. of 1:
  30. echo b
  31. if iteration == 2:
  32. break
  33. test(1, ObjWithDestructor())