tdup.nim 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 = RefCustom()
  35. result.id = x.id
  36. proc inc(x: sink Ref) =
  37. inc x.id
  38. proc inc(x: sink RefCustom) =
  39. inc x.id[]
  40. proc foo =
  41. var x = Ref(id: 8)
  42. inc(x)
  43. inc(x)
  44. var id = 777
  45. var s = RefCustom(id: addr id)
  46. inc s
  47. inc s
  48. foo()
  49. proc foo2 =
  50. var x = Ref(id: 8)
  51. inc(x)
  52. doAssert x.id == 9
  53. inc(x)
  54. doAssert x.id == 10
  55. var id = 777
  56. var s = RefCustom(id: addr id)
  57. inc s
  58. doAssert s.id[] == 778
  59. inc s
  60. doAssert s.id[] == 779
  61. foo2()