tdup.nim 949 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. discard """
  2. cmd: "nim c --mm:arc --expandArc:foo --hints:off $file"
  3. nimout: '''
  4. --expandArc: foo
  5. var
  6. x
  7. :tmpD
  8. s
  9. :tmpD_1
  10. x = Ref(id: 8)
  11. inc:
  12. :tmpD = `=dup`(x)
  13. :tmpD
  14. inc:
  15. let blitTmp = x
  16. blitTmp
  17. var id_1 = 777
  18. s = RefCustom(id_2: addr(id_1))
  19. inc_1 :
  20. :tmpD_1 = `=dup_1`(s)
  21. :tmpD_1
  22. inc_1 :
  23. let blitTmp_1 = s
  24. blitTmp_1
  25. -- end of expandArc ------------------------
  26. '''
  27. """
  28. type
  29. Ref = ref object
  30. id: int
  31. RefCustom = object
  32. id: ptr int
  33. proc `=dup`(x: RefCustom): RefCustom =
  34. result.id = x.id
  35. proc inc(x: sink Ref) =
  36. inc x.id
  37. proc inc(x: sink RefCustom) =
  38. inc x.id[]
  39. proc foo =
  40. var x = Ref(id: 8)
  41. inc(x)
  42. inc(x)
  43. var id = 777
  44. var s = RefCustom(id: addr id)
  45. inc s
  46. inc s
  47. foo()
  48. proc foo2 =
  49. var x = Ref(id: 8)
  50. inc(x)
  51. doAssert x.id == 9
  52. inc(x)
  53. doAssert x.id == 10
  54. var id = 777
  55. var s = RefCustom(id: addr id)
  56. inc s
  57. doAssert s.id[] == 778
  58. inc s
  59. doAssert s.id[] == 779
  60. foo2()