treorder.nim 939 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. discard """
  2. output:'''0
  3. 1
  4. 2
  5. 3'''
  6. """
  7. import macros
  8. # {.reorder: on .}
  9. {.experimental: "codeReordering".}
  10. echo foo(-1)
  11. echo callWithFoo(0)
  12. echo(CA+CD)
  13. echo useTypes(TA(x:TB(x:1)), 2)
  14. second(0)
  15. template callWithFoo(arg: untyped): untyped =
  16. foo(arg)
  17. proc first(i: int): void
  18. proc second(i: int): void =
  19. make(first)
  20. first(i)
  21. proc useTypes(a: TA, d: TD): int =
  22. result = a.x.x+d
  23. type
  24. TDoubleCyclic = ref object
  25. x: TCyclicA
  26. y: TCyclicB
  27. type
  28. TCyclicA = ref object
  29. x: TDoubleCyclic
  30. type
  31. TCyclicB = ref object
  32. x: TDoubleCyclic
  33. const
  34. CA = 1
  35. CB = CC
  36. type
  37. TA = object
  38. x: TB
  39. TC = type(CC)
  40. TD = type(CA)
  41. const
  42. CC = 1
  43. CD = CB
  44. type
  45. TB = object
  46. x: TC
  47. proc foo(x: int): int =
  48. result = bar(x)
  49. proc bar(x: int): int =
  50. result = x+1
  51. macro make(arg: untyped): untyped =
  52. ss &= arg.repr
  53. ss &= " "
  54. discard
  55. proc first(i: int): void =
  56. make(second)
  57. var ss {.compileTime.}: string = ""