tstaticprintseq.nim 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. discard """
  2. nimout: '''1
  3. 2
  4. 3
  5. 1
  6. 2
  7. 3
  8. 1
  9. 2
  10. 3
  11. 1
  12. 2
  13. 3
  14. aa
  15. bb
  16. 11
  17. 22
  18. aa
  19. bb
  20. 24
  21. 2147483647 2147483647
  22. 5'''
  23. """
  24. const s = @[1,2,3]
  25. macro foo() =
  26. for e in s:
  27. echo e
  28. foo()
  29. static:
  30. for e in s:
  31. echo e
  32. macro bar(x: static[seq[int]]): untyped =
  33. for e in x:
  34. echo e
  35. bar s
  36. bar(@[1, 2, 3])
  37. type
  38. TData = tuple
  39. letters: seq[string]
  40. numbers: seq[int]
  41. const data: TData = (@["aa", "bb"], @[11, 22])
  42. static:
  43. var m1 = data
  44. for x in m1.letters: echo x
  45. var m2: TData = data
  46. for x in m2.numbers: echo x
  47. macro ff(d: static[TData]) =
  48. for x in d.letters:
  49. echo x
  50. ff(data)
  51. # bug #1010
  52. proc `*==`(x: var int, y: int) {.inline, noSideEffect.} =
  53. ## Binary `*=` operator for ordinals
  54. x = x * y
  55. proc fac: int =
  56. var x = 1;
  57. for i in 1..4:
  58. x *== i;
  59. return x
  60. const y = fac()
  61. static:
  62. echo y
  63. static:
  64. var foo2 = int32.high
  65. echo foo2, " ", int32.high
  66. # bug #1329
  67. static:
  68. var a: ref int
  69. new(a)
  70. a[] = 5
  71. echo a[]