tgensymregression.nim 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. discard """
  2. output: '''[0.0, 0.0, 0.0]
  3. [0.0, 0.0, 0.0, 0.0]
  4. 5050
  5. 123'''
  6. """
  7. template mathPerComponent(op: untyped): untyped =
  8. proc op*[N,T](v,u: array[N,T]): array[N,T] {.inline.} =
  9. for i in 0 ..< len(result):
  10. result[i] = `*`(v[i], u[i])
  11. mathPerComponent(`***`)
  12. # bug #5285
  13. when true:
  14. if true:
  15. var v1: array[3, float64]
  16. var v2: array[3, float64]
  17. echo repr(v1 *** v2)
  18. proc foo(): void =
  19. var v1: array[4, float64]
  20. var v2: array[4, float64]
  21. echo repr(v1 *** v2)
  22. foo()
  23. # bug #5383
  24. import sequtils
  25. proc zipWithIndex[A](ts: seq[A]): seq[(int, A)] =
  26. toSeq(pairs(ts))
  27. proc main =
  28. discard zipWithIndex(@["foo", "bar"])
  29. discard zipWithIndex(@[1, 2])
  30. discard zipWithIndex(@[true, false])
  31. main()
  32. # bug #5405
  33. proc main2() =
  34. let s = toSeq(1..100).foldL(a + b)
  35. echo s
  36. main2()
  37. # bug #5467
  38. import macros
  39. converter int2string(x: int): string = $x
  40. template wrap(body: typed): untyped =
  41. body
  42. macro makeProc() =
  43. # Make a template tree
  44. result = quote do:
  45. proc someProc* =
  46. wrap do:
  47. let x = 123
  48. # Implicit conversion here
  49. let s: string = x
  50. echo s
  51. makeProc()
  52. someProc()
  53. # bug #12193
  54. import macros, strutils
  55. macro gen(T: typedesc): untyped =
  56. let typeSym = getTypeImpl(T)[1]
  57. let param = genSym(nskParam, "s")
  58. let value = nnkBracketExpr.newTree(param, newIntLitNode(0))
  59. result = newProc(
  60. name = ident"pack",
  61. params = [typeSym,
  62. newIdentDefs(param, nnkBracketExpr.newTree(ident"seq", ident"string"))],
  63. body = newStmtList(newCall(typeSym, newCall(bindSym"parseInt", value))),
  64. procType = nnkTemplateDef)
  65. echo repr result
  66. gen(int)
  67. let i = pack(@["2"])