tcomputedgotocopy.nim 650 B

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