tcomplexecho.nim 664 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. discard """
  2. output: '''3
  3. OK
  4. 56
  5. 123
  6. 56
  7. 61'''
  8. """
  9. import macros
  10. # Bug from the forum
  11. macro addEcho1(s: untyped): untyped =
  12. s.body.add(newCall("echo", newStrLitNode("OK")))
  13. result = s
  14. proc f1() {.addEcho1.} =
  15. let i = 1+2
  16. echo i
  17. f1()
  18. # bug #537
  19. proc test(): seq[NimNode] {.compiletime.} =
  20. result = @[]
  21. result.add parseExpr("echo 56")
  22. result.add parseExpr("echo 123")
  23. result.add parseExpr("echo 56")
  24. proc foo(): seq[NimNode] {.compiletime.} =
  25. result = @[]
  26. result.add test()
  27. result.add parseExpr("echo(5+56)")
  28. macro bar() =
  29. result = newNimNode(nnkStmtList)
  30. let x = foo()
  31. for xx in x:
  32. result.add xx
  33. echo treeRepr(result)
  34. bar()